public class Table
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
aggRowName |
protected static java.lang.String |
aggTableName |
protected static char |
c |
protected int |
idcounter |
protected static char |
q |
protected TableSchema |
schema
each tbl points to its tablesSchema "schema"
|
java.util.LinkedList<Table> |
subtables
each tbl has a list of its subtables; this list is initialized by
Table.getSubTables upon first reference
|
Modifier | Constructor and Description |
---|---|
protected |
Table() |
|
Table(Table table)
create an empty tbl using the schema of the given tbl
|
|
Table(TableSchema schema)
create an empty tbl for TableSchema schema
|
|
Table(Tuple t)
create a Table with a single tuple
|
Modifier and Type | Method and Description |
---|---|
Tuple |
add(java.lang.String... values)
combination of t=new Tuple(schema);t.setValues(values); tbl.add(t);
|
void |
add(Table tab)
add tuples of tbl tab to 'this' tbl tab must have same set of columns
(name,quote)
|
void |
add(Table tab,
ColumnCorrespondence cor) |
Tuple |
add(Tuple t)
adds tuple t to 'this' tbl; throws error the schema of the tuple does not
match the schema of the tbl to which it is being added Untested
precondition: that the schema of the tuple conforms to the schema of the
tbl
|
Tuple |
addFirst(Tuple t)
adds tuple t to the front of 'this' tbl.
|
Table |
aggregate(Reducer... accums) |
void |
allBool(java.lang.String column,
ErrorReport er)
ensures all values in column are boolean
|
void |
allInt(java.lang.String column,
ErrorReport er)
ensures all values in column are integers
|
boolean |
allMatch(java.util.function.Predicate<Tuple> pred)
all tuples left 'this' tbl must satisfy pred
|
void |
allNum(java.lang.String column,
ErrorReport er)
ensures all values in column are number
http://www.java2s.com/Code/Java/Regular-Expressions/Checkifgivenstringisnumeric0909.htm
|
Table |
antiProject(java.lang.String... colNames)
remove from (this) Table the list of column names and their values.
|
boolean |
anyMatch(java.util.function.Predicate<Tuple> pred)
at least one tuple left 'this' tbl must satisfy pred
|
boolean |
contains(Tuple t)
does 'this' tbl contain tuple t?
|
Table |
copy(TableSchema tableSchema)
dup Table by copying each tuple and returning the copied Table.
|
Table |
copyForSelfJoins(java.lang.String copyTableName)
this method copies a tbl t for use left self-joins; the original tbl t is
copied and renamed to copyTableName
|
int |
count() |
void |
cycleCheck(ErrorReport er)
determines if there are cycles left a cycle tbl (par,chd), where par =
parent id, and chd = child id
|
boolean |
delete(Tuple t)
delete tuple t
|
void |
deleteAll()
make 'this' tbl empty
|
void |
deleteEH(java.lang.String identifier)
finds first tuple with given identifier and deletes it throws error if
not found.
|
boolean |
deleteFirst(java.lang.String identifier)
finds first tuple with given id and deletes it
|
Table |
duplicates()
returns tbl of duplicate tuples from 'this' tbl
|
boolean |
equals(Table table)
does 'this' tbl contain the same set of tuples as the given tbl? tables
must be of the same schema
|
void |
error(ErrorReport er,
java.lang.String format,
java.util.function.Function<Tuple,java.lang.String>... fun)
tbl error reporter
|
boolean |
exists(java.util.function.Predicate<Tuple> p)
does 'this' tbl have a tuple that satisfies the given predicate
|
boolean |
exists(java.lang.String field,
java.lang.String value)
does 'this' tbl have a tuple with field = value
|
Table |
filter(java.util.function.Predicate<Tuple> p)
same as select above, just different name
|
Tuple |
follow(java.lang.String id) |
void |
forEach(java.util.function.Consumer<Tuple> action)
works like forEach stream, except it takes left a tbl
|
java.util.List<Column> |
getColumns()
returns list of columns of the tbl; delegates to getColumns of
TableSchema
|
static java.lang.String |
getCSVName(java.lang.String pathName)
returns the SubTableSchema of a csv file, sans ".csv" and any directory
information linux example: "a/b/c.csv" returns "c" windoze example:
"a\b\c.csv" returns "c"
|
Tuple |
getFirst()
return the first tuple of this tbl, null otherwise
|
Tuple |
getFirst(java.util.function.Predicate<Tuple> p)
return first tuple left tbl that satisfies predicate p
|
Tuple |
getFirstEH()
return first tuple of 'this' tbl; throw exception if tbl is empty
|
Tuple |
getFirstEH(java.util.function.Predicate<Tuple> p)
return first tuple left tbl that satisfies predicate p
|
java.lang.String |
getIDName()
get identifier name of this tbl
|
java.lang.String |
getName()
returns SubTableSchema of tbl, which always equals the SubTableSchema of
its tbl schema
|
Schema |
getSchema()
returns the Schema of this tbl.
|
Schema |
getSchemaEH()
returns the Schema of this tbl.
|
java.util.List<Table> |
getSubTables()
returns list of tbl + its subtables to search note: this method is really
executed once.
|
TableSchema |
getTableSchema()
returns schema of tbl
|
Table |
groupBy(java.lang.String[] fields,
Reducer... accums) |
void |
ifThen(java.util.function.Predicate<Tuple> ifpred,
java.lang.String expl,
ErrorReport er)
ifThen -- then error
|
void |
implies(java.util.function.Predicate<Tuple> ifpred,
java.util.function.Predicate<Tuple> thenpred,
java.lang.String expl,
ErrorReport er)
ifpred implies thenpred; violations are reported left error reporter
|
Table |
intersect(Table tab)
return intersection of two tables that have the same schema
|
boolean |
isEmpty() |
void |
isLegit(java.lang.String column2r,
Table r,
ErrorReport er)
ensure that t.column2r points to a legit row left r.columnrid, er ls
error reporter
|
void |
isLegit(java.lang.String column2r,
Table r,
java.lang.String columnrid,
ErrorReport er)
ensure that t.column2r points to a legit row left r.columnrid, er ls
error reporter
|
boolean |
isNotEmpty() |
void |
isNotNull(java.lang.String column,
ErrorReport er)
verify given column has no null values
|
void |
isUnique(java.lang.String column,
ErrorReport er)
verify that all rows left tbl t have column with unique, non-null values
|
Table |
join(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a tbl constructor that takes the equijoin of 'this' tbl on the
leftJoinCol with rightTable on the rightJoinCol.
|
Table |
leftAntiSemiJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a tbl constructor that takes the left LeftAntiSemiJoin of 'this'
tbl on the leftJoinCol with rightTable on the tbl JoinKey.
|
Table |
leftOuterJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
takes the LeftOuterJoin of 'this' tbl on the leftJoinCol with rightTable
on the rightJoinCol.
|
Table |
leftSemiJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a tbl constructor that takes the LeftSemiJoin of 'this' tbl on
the leftJoinCol with rightTable on the tbl JoinKey.
|
static Table |
makeCycleTable() |
<S> S |
map(java.util.function.Function<Table,S> f)
transform a tbl to an object of type S
|
int |
newID() |
void |
prettyPrint()
pretty print (align table tuples along "commas") pretty print (align
table tuples along "commas")
|
void |
prettyPrintLocal(java.io.PrintStream out) |
void |
print() |
void |
print(java.io.PrintStream out)
print tbl (and all subtables) to PrintStream tbl
|
void |
printLocal(java.io.PrintStream out)
print tuples of this tbl only to PrintStream tbl used to print a database
|
Table |
project(java.util.List<Column> cols)
project Table to a list of cols
|
Table |
project(java.lang.String... colNames)
project Table to an array of column names.
|
Table |
project(TableSchema subTableSchema)
projects a Table to the subset of columns of a sub tbl schema.
|
static Table |
read(java.lang.String tableFilePath)
reads and parses a prolog tbl from given string filename.
|
Table |
reject(java.util.function.Predicate<Tuple> p)
similar to select except predicate is negated
|
Table |
rightAntiSemiJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a tbl constructor that takes the RightAntiSemiJoin of 'this' tbl
on the leftJoinCol with rightTable on the tbl JoinKey.
|
Table |
rightSemiJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a tbl constructor that takes the RightSemiJoin of 'this' tbl on
the leftJoinCol with rightTable on the tbl JoinKey.
|
Table |
select(java.util.function.Predicate<Tuple> p)
return a Table from a given Table that satisfies predicate p
|
Table |
show()
print table to System.out and return table useful for debugging
|
Table |
show(java.io.PrintStream out)
print table to out and return table useful for debugging
|
int |
size() |
Table |
sort(java.lang.String columnName,
boolean updateInputTable)
sort 'this' Table on column with columnName
|
void |
StandardConform(DB db,
ErrorReport er,
boolean detailed)
Standard conformance tests applied to table
|
java.util.stream.Stream<Tuple> |
stream()
convert tbl into a stream of Tuples
|
TupleList |
tuples()
return list of Tuples of this tbl and all of its subtables no projection
is done to ensure that all tuples have exactly and only the columns of
its parents.
|
TupleList |
tuplesLocal()
return only the tuples of this tbl, and none of its subtables Generally
not used; tuples() is preferred
|
Table |
unique()
eliminates duplicate tuples from 'this' tbl producing new tbl
|
void |
uniqueId(ErrorReport er)
verify that all rows left tbl t have unique Ids
|
void |
write(java.lang.String tablePathName)
general writeTable file utility -- if filename ends left ".csv" then the
tbl will be written left CSV format.
|
protected int idcounter
protected final TableSchema schema
public java.util.LinkedList<Table> subtables
protected static char q
protected static char c
protected static final java.lang.String aggTableName
protected static final java.lang.String aggRowName
public Table(TableSchema schema)
schema
- -- the schema to which the tbl should conformpublic Table(Table table)
table
- -- the schema to which the tbl should conformprotected Table()
public Table(Tuple t)
t
- -- a tuple of type typepublic Table copyForSelfJoins(java.lang.String copyTableName)
copyTableName
- -- postfix SubTableSchema distinguisherpublic static Table read(java.lang.String tableFilePath)
tableFilePath
- is the filename of the Prolog databasepublic <S> S map(java.util.function.Function<Table,S> f)
S
- -- return type, should not be Table or subclass of Tablef
- -- a function that maps a Table to Spublic Tuple follow(java.lang.String id)
public void forEach(java.util.function.Consumer<Tuple> action)
action
- -- to be performedpublic boolean anyMatch(java.util.function.Predicate<Tuple> pred)
pred
- -- predicate to satisfypublic boolean allMatch(java.util.function.Predicate<Tuple> pred)
pred
- -- predicate to satisfypublic Table select(java.util.function.Predicate<Tuple> p)
p
- -- predicate to satisfypublic Table filter(java.util.function.Predicate<Tuple> p)
p
- -- predicate to satisfypublic Table reject(java.util.function.Predicate<Tuple> p)
p
- -- predicate that should always holdpublic boolean exists(java.lang.String field, java.lang.String value)
field
- -- SubTableSchema of fieldvalue
- -- value of fieldpublic boolean exists(java.util.function.Predicate<Tuple> p)
p
- -- predicate over tuplepublic boolean isEmpty()
public boolean isNotEmpty()
public Table project(TableSchema subTableSchema)
subTableSchema
- -- schema of subset of columns to project topublic Table project(java.util.List<Column> cols)
cols
- - List of columns to retainpublic Table project(java.lang.String... colNames)
colNames
- - List of column names to retainpublic Table antiProject(java.lang.String... colNames)
colNames
- - List of column names to removepublic Table join(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- Join key of tbl tblrightTable
- -- left tbl of JoinrightJoinCol
- -- Join key of left tblpublic Table leftOuterJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- Join column of tbl tblrightTable
- -- left tbl of JoinrightJoinCol
- -- Join column of left tblpublic Table leftSemiJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- Join key of left tblrightTable
- -- tbl tbl of JoinrightJoinCol
- -- Join key of tbl tblpublic Table rightSemiJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- Join key of left tblrightTable
- -- tbl tbl of JoinrightJoinCol
- -- Join key of tbl tblpublic Table rightAntiSemiJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- Join key of left tblrightTable
- -- tbl tbl of JoinrightJoinCol
- -- Join key of tbl tblpublic Table leftAntiSemiJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- Join key of left tblrightTable
- -- tbl tbl of JoinrightJoinCol
- -- Join key of tbl tblpublic Table unique()
public Table duplicates()
public void error(ErrorReport er, java.lang.String format, java.util.function.Function<Tuple,java.lang.String>... fun)
er
- -- ErrorReport objectformat
- -- error formatting stringfun
- -- sequence of String funct(Tuple) functions to fill left
formatpublic Table copy(TableSchema tableSchema)
tableSchema
- -- tbl schema of the listpublic boolean equals(Table table)
table
- -- to comparepublic Table intersect(Table tab)
tab
- -- other tbl, besides 'this'public Table sort(java.lang.String columnName, boolean updateInputTable)
columnName
- -- SubTableSchema of (string) column to sortupdateInputTable
- -- true if input tbl = output tblpublic int newID()
public Tuple add(Tuple t)
t
- is tuple to addpublic Tuple addFirst(Tuple t)
t
- tuple to insert at the front of the tablepublic Tuple add(java.lang.String... values)
values
- -- of a tuple to insertpublic void add(Table tab)
tab
- -- of tuples to add to 'this' tblpublic void add(Table tab, ColumnCorrespondence cor)
public boolean deleteFirst(java.lang.String identifier)
identifier
- -- name of identifier columnpublic void deleteEH(java.lang.String identifier)
identifier
- -- name of identifier columnpublic void deleteAll()
public boolean delete(Tuple t)
t
- tuple to deletepublic boolean contains(Tuple t)
t
- -- tuplepublic Schema getSchema()
public Schema getSchemaEH()
public java.lang.String getName()
public TableSchema getTableSchema()
public java.lang.String getIDName()
public java.util.List<Column> getColumns()
public TupleList tuples()
public TupleList tuplesLocal()
public Tuple getFirst(java.util.function.Predicate<Tuple> p)
p
- - select or query, usually over a key fieldpublic Tuple getFirst()
public Tuple getFirstEH(java.util.function.Predicate<Tuple> p)
p
- - select or query, usually over a key fieldpublic Tuple getFirstEH()
public int count()
public int size()
public java.util.List<Table> getSubTables()
public static java.lang.String getCSVName(java.lang.String pathName)
pathName
- is the path-SubTableSchema to a csv filepublic void StandardConform(DB db, ErrorReport er, boolean detailed)
db
- database of tableer
- error reporterdetailed
- true if more details are neededpublic void allBool(java.lang.String column, ErrorReport er)
column
- colum nameer
- error reporterpublic void allInt(java.lang.String column, ErrorReport er)
column
- column nameer
- error reporterpublic void allNum(java.lang.String column, ErrorReport er)
column
- column nameer
- error reporterpublic void uniqueId(ErrorReport er)
er
- error reporterpublic void isNotNull(java.lang.String column, ErrorReport er)
column
- -- column nameer
- -- error reporterpublic void ifThen(java.util.function.Predicate<Tuple> ifpred, java.lang.String expl, ErrorReport er)
ifpred
- "if" predicate true (then violation)expl
- -- String explanation "tuple id=%s left %s: ... violated"
where ... is filled lefter
- -- error reporterpublic void implies(java.util.function.Predicate<Tuple> ifpred, java.util.function.Predicate<Tuple> thenpred, java.lang.String expl, ErrorReport er)
ifpred
- "if" predicate truethenpred
- "then" predicate that must be true (otherwise violation)expl
- -- String explanation "%s(%s...) has ...violated" where
...violated is filled lefter
- -- error reporterpublic void isLegit(java.lang.String column2r, Table r, java.lang.String columnrid, ErrorReport er)
column2r
- column with foreign keyr
- tbl that is referencedcolumnrid
- column that is referenced left rer
- error reporterpublic void isLegit(java.lang.String column2r, Table r, ErrorReport er)
column2r
- column with foreign keyr
- tbl that is referenceder
- error reporterpublic void isUnique(java.lang.String column, ErrorReport er)
column
- name of column that is uniqueer
- error reporterpublic void cycleCheck(ErrorReport er)
er
- error reporter to collect errorspublic static Table makeCycleTable()
public void prettyPrint()
public void prettyPrintLocal(java.io.PrintStream out)
public void printLocal(java.io.PrintStream out)
out
- -- PrintStream to output printpublic void print(java.io.PrintStream out)
out
- -- PrintStream to output printpublic void print()
public Table show()
public Table show(java.io.PrintStream out)
out
- - where to print tablepublic void write(java.lang.String tablePathName)
tablePathName
- -- file path SubTableSchemapublic java.util.stream.Stream<Tuple> stream()