public class Table
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected TableSchema |
schema
each table points to its tablesSchema "schema"
|
java.util.LinkedList<Table> |
subtables
each table has a list of its subtables; this list is initialized by
Table.getSubTables upon first reference
|
Constructor and Description |
---|
Table(Table table)
create an empty table using the schema of the given table
|
Table(TableSchema schema)
create an empty table for TableSchema schema
|
Table(TableSchema schema,
TupleList tl)
most primitive table constructor
|
Table(Table table,
TupleList tl)
create an empty table using the schema of the given table
|
Modifier and Type | Method and Description |
---|---|
Table |
add(Tuple t)
adds tuple t to 'this' table; throws error the schema of the tuple does
not match the schema of the table to which it is being added Untested
precondition: that the schema of the tuple conforms to the schema of the
table
|
Table |
addTuple(java.lang.String... values)
combination of t=new Tuple(schema);t.setValues(values); table.add(t);
|
Table |
addTuples(Table tab)
add tuples of table tab to 'this' table
tab must have same set of columns (name,quote)
|
Table |
addTuples(Table tab,
ColumnCorrespondence cor) |
boolean |
allMatch(java.util.function.Predicate<Tuple> pred)
all tuples in 'this' table must satisfy pred
|
Table |
antiProject(java.lang.String... colNames)
remove from (this) Table the list of column names and their values.
|
Table |
antiSemiJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a table constructor that takes the antiSemiJoin of 'this' table on
the leftJoinCol with rightTable on the right JoinKey.
|
boolean |
anyMatch(java.util.function.Predicate<Tuple> pred)
at least one tuple in 'this' table must satisfy pred
|
boolean |
contains(Tuple t)
does 'this' table 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 table t for use in self-joins; the original table t
is copied and renamed to copyTableName
|
int |
count()
returns number of tuples in this table
|
boolean |
delete(java.lang.String identifier,
java.lang.String value)
finds first tuple with (identifier,value) pair and deletes the first
|
void |
deleteAll()
make 'this' table empty
|
void |
deleteEH(java.lang.String identifier,
java.lang.String value)
finds first tuple with (identifier,value) pair and deletes the first
throws error if not found.
|
Table |
duplicates()
returns table of duplicate tuples from 'this' table
|
boolean |
equals(Table table)
does 'this' table contain the same set of tuples as the given table?
tables must be of the same schema
|
void |
error(ErrorReport er,
java.lang.String format,
java.util.function.Function<Tuple,java.lang.String>... fun)
table error reporter
|
boolean |
exists(java.util.function.Predicate<Tuple> p)
does 'this' table have a tuple that satisfies the given predicate
|
boolean |
exists(java.lang.String field,
java.lang.String value)
does 'this' table have a tuple with field = value
|
Table |
filter(java.util.function.Predicate<Tuple> p)
return a Table from a given Table that satisfies predicate p
|
void |
forEach(java.util.function.Consumer<Tuple> action)
works like forEach stream, except it takes in a table
|
java.util.List<Column> |
getColumns()
returns list of columns of the table; 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"
|
DBSchema |
getDBSchema()
returns the DBSchema of this table.
|
DBSchema |
getDBSchemaEH()
returns the DBSchema of this table.
|
Tuple |
getFirst(java.util.function.Predicate<Tuple> p)
return first tuple in table that satisfies predicate p
|
Tuple |
getFirstEH(java.util.function.Predicate<Tuple> p)
return first tuple in table that satisfies predicate p
|
java.lang.String |
getIDName()
get identifier name of this table
|
java.lang.String |
getName()
returns SubTableSchema of table, which always equals the SubTableSchema
of its table schema
|
TableSchema |
getSchema()
returns schema of table
|
java.util.List<Table> |
getSubTables()
returns list of table + its subtables to search note: this method is
really executed once.
|
java.util.stream.Stream<Table> |
groupBy(java.lang.String columnName)
group 'this' table into a stream of tables; each "sub"table will have
tuples with the same columnName value
|
Table |
intersect(Table tab)
return intersection of two tables that have the same schema
|
Table |
join(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a table constructor that takes the equijoin of 'this' table on the
leftJoinCol with rightTable on the rightJoinCol.
|
Table |
leftOuterJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
takes the leftOuterJoin of 'this' table on the leftJoinCol with rightTable
on the rightJoinCol.
|
<S> S |
map(java.util.function.Function<Table,S> f)
transform a table to an object of type S
|
void |
print() |
void |
print(java.io.PrintStream out)
print table (and all subtables) to PrintStream out
|
void |
printLocal(java.io.PrintStream out)
print tuples of this table only to PrintStream out 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 table schema.
|
static Table |
readTable(java.lang.String tableFilePath)
reads and parses a prolog table from given string filename.
|
Table |
rightSemiJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a table constructor that takes the rightSemiJoin of 'this' table on
the leftJoinCol with rightTable on the right JoinKey.
|
Table |
semiJoin(java.lang.String leftJoinCol,
Table rightTable,
java.lang.String rightJoinCol)
this is a table constructor that takes the leftSemiJoin of 'this' table on the
leftJoinCol with rightTable on the right JoinKey.
|
Table |
sort(java.lang.String columnName,
boolean updateInputTable)
sort 'this' Table on column with columnName
|
java.util.stream.Stream<Tuple> |
stream()
convert table into a stream of Tuples
|
TupleList |
tuples()
return list of Tuples of this table 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 table, and none of its subtables Generally
not used; tuples() is preferred
|
Table |
unique()
eliminates duplicate tuples from 'this' table producing new table
|
void |
writeTable(java.lang.String tablePathName)
general writeTable file utility -- if filename ends in ".csv" then the
table will be written in CSV format.
|
protected final TableSchema schema
public java.util.LinkedList<Table> subtables
public Table(TableSchema schema)
schema
- -- the schema to which the table should conformpublic Table(Table table)
table
- -- the schema to which the table should conformpublic Table(Table table, TupleList tl)
table
- -- the schema to which the table should conformtl
- -- tuple list of tablepublic Table(TableSchema schema, TupleList tl)
schema
- -- of tabletl
- -- tuplelist of tablepublic Table copyForSelfJoins(java.lang.String copyTableName)
copyTableName
- -- postfix SubTableSchema distinguisherpublic static Table readTable(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 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 filter(java.util.function.Predicate<Tuple> p)
p
- -- predicate to satisfypublic 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 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 inner tablerightTable
- -- outer table of joinrightJoinCol
- -- join key of outer tablepublic Table leftOuterJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- join column of inner tablerightTable
- -- outer table of joinrightJoinCol
- -- join column of outer tablepublic Table semiJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- join key of left tablerightTable
- -- inner table of joinrightJoinCol
- -- join key of inner tablepublic Table rightSemiJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- join key of left tablerightTable
- -- inner table of joinrightJoinCol
- -- join key of inner tablepublic Table antiSemiJoin(java.lang.String leftJoinCol, Table rightTable, java.lang.String rightJoinCol)
leftJoinCol
- -- join key of outer tablerightTable
- -- inner table of joinrightJoinCol
- -- join key of inner tablepublic 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 in formatpublic Table copy(TableSchema tableSchema)
tableSchema
- -- table schema of the listpublic boolean equals(Table table)
table
- -- to comparepublic Table intersect(Table tab)
tab
- -- other table, besides 'this'public Table sort(java.lang.String columnName, boolean updateInputTable)
columnName
- -- SubTableSchema of (string) column to sortupdateInputTable
- -- true if input table = output tablepublic java.util.stream.Stream<Table> groupBy(java.lang.String columnName)
columnName
- -- name of column to group bypublic Table add(Tuple t)
t
- is tuple to addpublic Table addTuple(java.lang.String... values)
values
- -- of a tuple to insertpublic Table addTuples(Table tab)
tab
- -- of tuples to add to 'this' tablepublic Table addTuples(Table tab, ColumnCorrespondence cor)
public boolean delete(java.lang.String identifier, java.lang.String value)
identifier
- -- name of identifier columnvalue
- -- column valuepublic void deleteEH(java.lang.String identifier, java.lang.String value)
identifier
- -- name of identifier columnvalue
- -- value of identifierpublic void deleteAll()
public boolean contains(Tuple t)
t
- -- tuplepublic DBSchema getDBSchema()
public DBSchema getDBSchemaEH()
public java.lang.String getName()
public TableSchema getSchema()
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
- - filter or query, usually over a key fieldpublic Tuple getFirstEH(java.util.function.Predicate<Tuple> p)
p
- - filter or query, usually over a key fieldpublic int count()
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 printLocal(java.io.PrintStream out)
out
- -- PrintStream to output printpublic void print(java.io.PrintStream out)
out
- -- PrintStream to output printpublic void print()
public void writeTable(java.lang.String tablePathName)
tablePathName
- -- file path SubTableSchemapublic java.util.stream.Stream<Tuple> stream()