public abstract class Table extends Object implements TableDataSource
It is an abstract class, because it does not implement the methods to add, remove or access row data in the table.
Modifier and Type | Field and Description |
---|---|
protected static boolean |
DEBUG_QUERY |
Modifier | Constructor and Description |
---|---|
protected |
Table()
The Constructor.
|
Modifier and Type | Method and Description |
---|---|
Table |
all(QueryContext context,
Expression lhs,
Operator op,
Table table)
Evaluates a non-correlated ALL type operator given the LHS expression,
the RHS subquery and the ALL operator to use.
|
boolean |
allColumnMatchesValue(int column,
Operator op,
TObject ob)
Returns true if the given column contains all values that the given
operator returns true for with the given value.
|
Table |
any(QueryContext context,
Expression lhs,
Operator op,
Table right_table)
Evaluates a non-correlated ANY type operator given the LHS expression,
the RHS subquery and the ANY operator to use.
|
boolean |
columnContainsCell(int column,
TObject cell)
Returns true if the given cell is found in the table.
|
boolean |
columnContainsValue(int column,
TObject ob)
Returns true if the given column number contains the value given.
|
boolean |
columnMatchesValue(int column,
Operator op,
TObject ob)
Returns true if the given column contains a value that the given
operator returns true for with the given value.
|
Table |
columnMerge(Table table)
Returns a Table that is a merge of this table and the destination table.
|
static boolean |
compareCells(TObject ob1,
TObject ob2,
Operator op)
Compares cell1 with cell2 and if the given operator evalutes to true then
returns true, otherwise false.
|
DebugLogger |
Debug()
Returns a DebugLogger object that we can use to log debug messages to.
|
VirtualTable |
distinct()
Deprecated.
- not a proper SQL distinct.
|
Table |
distinct(int[] col_map)
Returns a new table that has only distinct rows in it.
|
void |
dumpTo(PrintStream out)
Dumps the contents of the table in a human readable form to the given
output stream.
|
Table |
emptySelect()
Returns a new Table based on this table with no rows in it.
|
Table |
exhaustiveSelect(QueryContext context,
Expression exp)
Exhaustively searches through this table for rows that match the
expression given.
|
int |
fastFindFieldName(Variable col)
A faster way to find a column index given a string column name.
|
abstract int |
findFieldName(Variable v)
Given a fully qualified variable field name, ie.
|
abstract TObject |
getCellContents(int column,
int row)
Returns an object that represents the information in the given cell
in the table.
|
abstract int |
getColumnCount()
Returns the number of columns in the table.
|
DataTableColumnDef |
getColumnDefAt(int col_index)
Returns the DataTableColumnDef object for the given column index.
|
SelectableScheme |
getColumnScheme(int column)
Returns the SelectableScheme that indexes the given column in this table.
|
abstract Database |
getDatabase()
Returns the Database object that this table is derived from.
|
abstract DataTableDef |
getDataTableDef()
Returns a DataTableDef object that defines the name of the table and the
layout of the columns of the table.
|
TObject |
getFirstCellContent(int column)
Returns the TObject value that represents the first item in the set or
null if there are no items in the column set.
|
TObject[] |
getFirstCellContent(int[] col_map)
Returns the TObject value that represents the first item in the set or
null if there are no items in the column set.
|
TObject |
getLastCellContent(int column)
Returns the TObject value that represents the last item in the set or
null if there are no items in the column set.
|
TObject[] |
getLastCellContent(int[] col_map)
Returns the TObject value that represents the last item in the set or
null if there are no items in the column set.
|
abstract Variable |
getResolvedVariable(int column)
Returns a fully qualified Variable object that represents the name of
the column at the given index.
|
abstract int |
getRowCount()
Returns the number of rows stored in the table.
|
TObject |
getSingleCellContent(int column)
If the given column contains all items of the same value, this method
returns the value.
|
TObject[] |
getSingleCellContent(int[] col_map)
If the given column contains all items of the same value, this method
returns the value.
|
TransactionSystem |
getSystem()
Returns the TransactionSystem object that this table is part of.
|
TableAccessState |
getTableAccessState()
This returns an object that can only access the cells that are in this
table, and has no other access to the 'Table' class's functionality.
|
TType |
getTTypeForColumn(int column)
Returns a TType object that would represent values at the given
column index.
|
TType |
getTTypeForColumn(Variable v)
Returns a TType object that would represent values in the given
column.
|
abstract boolean |
hasRootsLocked()
Returns true if the table has its row roots locked (via the lockRoot(int)
method.
|
Table |
join(Table table)
Performs a natural join of this table with the given table.
|
abstract void |
lockRoot(int lock_key)
Locks the root table(s) of this table so that it is impossible to
overwrite the underlying rows that may appear in this table.
|
VirtualTable |
orderByColumn(int col_index,
boolean ascending)
Returns a Table which is identical to this table, except it is sorted by
the given column name.
|
VirtualTable |
orderByColumn(Variable column) |
VirtualTable |
orderByColumn(Variable column,
boolean ascending) |
Table |
orderByColumns(int[] col_map)
Returns a table that is ordered by the given column numbers.
|
IntegerVector |
orderedRowList(int[] col_map)
Returns an IntegerVector that represents the list of rows in this
table in sorted order by the given column map.
|
VirtualTable |
outside(Table rtable)
Finds all rows in this table that are 'outside' the result in the
given table.
|
void |
printGraph(PrintStream out,
int indent)
Prints a graph of the table hierarchy to the stream.
|
Table |
rangeSelect(Variable col_var,
SelectableRange[] ranges)
A single column range select on this table.
|
abstract RowEnumeration |
rowEnumeration()
Returns an Enumeration of the rows in this table.
|
IntegerVector |
selectAll()
Returns a list of rows that represents the enumerator order of this
table.
|
IntegerVector |
selectAll(int column)
Returns an array that represents the sorted order of this table by
the given column number.
|
IntegerVector |
selectFirst(int column)
Returns an array that represents the first sorted element(s) of the given
column number.
|
IntegerVector |
selectLast(int column)
Returns an array that represents the last sorted element(s) of the given
column number.
|
IntegerVector |
selectRange(int column,
SelectableRange[] ranges)
Returns an array that represents the sorted order of this table of all
values in the given SelectableRange objects of the given column index.
|
IntegerVector |
selectRest(int column)
Returns an array that represents the rest of the sorted element(s) of the
given column number.
|
Table |
simpleJoin(QueryContext context,
Table table,
Variable lhs_var,
Operator op,
Expression rhs)
A simple join operation.
|
Table |
simpleSelect(QueryContext context,
Variable lhs_var,
Operator op,
Expression rhs)
A simple select on this table.
|
Table |
singleRowSelect(int row_index)
Selects a single row at the given index from this table.
|
Map |
toMap()
Assuming this table is a 2 column key/value table, and the first column
is a string, this will convert it into a map.
|
String |
toString()
Returns a string that represents this table.
|
Table |
union(Table table)
Returns a new Table that is the union of the this table and the given
table.
|
abstract void |
unlockRoot(int lock_key)
Unlocks the root tables so that the underlying rows may
once again be used if they are not locked and have been removed.
|
protected Table()
public abstract Database getDatabase()
public final TransactionSystem getSystem()
getSystem
in interface TableDataSource
public DebugLogger Debug()
public abstract int getColumnCount()
public abstract int getRowCount()
getRowCount
in interface TableDataSource
public TType getTTypeForColumn(int column)
public TType getTTypeForColumn(Variable v)
public abstract int findFieldName(Variable v)
public abstract Variable getResolvedVariable(int column)
public abstract TObject getCellContents(int column, int row)
getCellContents
in interface TableDataSource
public abstract RowEnumeration rowEnumeration()
If you want the rows to be returned by a specific column order then use the 'selectxxx' methods.
rowEnumeration
in interface TableDataSource
public abstract DataTableDef getDataTableDef()
getDataTableDef
in interface TableDataSource
public abstract void lockRoot(int lock_key)
public abstract void unlockRoot(int lock_key)
public abstract boolean hasRootsLocked()
public SelectableScheme getColumnScheme(int column)
getColumnScheme
in interface TableDataSource
public DataTableColumnDef getColumnDefAt(int col_index)
public final void dumpTo(PrintStream out) throws IOException
IOException
public final Table emptySelect()
public final Table singleRowSelect(int row_index)
public final Table columnMerge(Table table)
public final Table rangeSelect(Variable col_var, SelectableRange[] ranges)
col_var
- the column variable in this table (eg. Part.id)ranges
- the normalized (no overlapping) set of ranges to find.public final Table simpleSelect(QueryContext context, Variable lhs_var, Operator op, Expression rhs)
context
- the context of the query.lhs_var
- the left has side column reference.op
- the operator.rhs
- the expression to select against (the expression must
be a constant).public final Table simpleJoin(QueryContext context, Table table, Variable lhs_var, Operator op, Expression rhs)
It is important to understand how this algorithm works because all optimization of the expression must happen before the method starts.
The simple join algorithm works as follows: Every row of the right hand side table 'table' is iterated through. The select opreation is applied to this table given the result evaluation. Each row that matches is included in the result table.
For optimal performance, the expression should be arranged so that the rhs table is the smallest of the two tables (because we must iterate through all rows of this table). This table should be the largest.
public final Table exhaustiveSelect(QueryContext context, Expression exp)
A QueryContext object is used for resolving sub-query plans. If there are no sub-query plans in the expression, this can safely be 'null'.
public Table any(QueryContext context, Expression lhs, Operator op, Table right_table)
Table.col > ANY ( SELECT .... )
ANY creates a new table that contains only the rows in this table that the expression and operator evaluate to true for any values in the given table.
The IN operator can be represented by using '= ANY'.
Note that unlike the other join and select methods in this object this will take a complex expression as the lhs provided all the Variable objects resolve to this table.
lhs
- the left has side expression. The Variable objects in this
expression must all reference columns in this table.op
- the operator to use.right_table
- the subquery table should only contain on column.context
- the context of the query.public Table all(QueryContext context, Expression lhs, Operator op, Table table)
Table.col > ALL ( SELECT .... )
ALL creates a new table that contains only the rows in this table that the expression and operator evaluate to true for all values in the giventable.
The NOT IN operator can be represented by using '<> ALL'.
Note that unlike the other join and select methods in this object this will take a complex expression as the lhs provided all the Variable objects resolve to this table.
lhs
- the left has side expression. The Variable objects in this
expression must all reference columns in this table.op
- the operator to use.table
- The subquery table should only contain on column.context
- The context of the query.public final Table join(Table table)
public final VirtualTable outside(Table rtable)
'rtable' must be a decendent of this table.
public final Table union(Table table)
public final VirtualTable distinct()
public final Table distinct(int[] col_map)
The int array contains the columns to make distinct over.
NOTE: This will change the order of this table in the result.
public final boolean columnContainsValue(int column, TObject ob)
public final boolean columnMatchesValue(int column, Operator op, TObject ob)
public final boolean allColumnMatchesValue(int column, Operator op, TObject ob)
public final Table orderByColumns(int[] col_map)
public final IntegerVector orderedRowList(int[] col_map)
public final VirtualTable orderByColumn(int col_index, boolean ascending)
public final VirtualTable orderByColumn(Variable column, boolean ascending)
public final VirtualTable orderByColumn(Variable column)
public final TableAccessState getTableAccessState()
public final IntegerVector selectAll(int column)
public final IntegerVector selectAll()
public final IntegerVector selectRange(int column, SelectableRange[] ranges)
public final IntegerVector selectLast(int column)
public final IntegerVector selectFirst(int column)
public final IntegerVector selectRest(int column)
public final TObject getFirstCellContent(int column)
public final TObject[] getFirstCellContent(int[] col_map)
public final TObject getLastCellContent(int column)
public final TObject[] getLastCellContent(int[] col_map)
public final TObject getSingleCellContent(int column)
public final TObject[] getSingleCellContent(int[] col_map)
public final boolean columnContainsCell(int column, TObject cell)
public static boolean compareCells(TObject ob1, TObject ob2, Operator op)
public Map toMap()
public final int fastFindFieldName(Variable col)
public String toString()
public void printGraph(PrintStream out, int indent)
Copyright © 2015. All rights reserved.