casacore
|
Select-class for flex/bison scanner/parser for TableParse. More...
#include <TableParse.h>
Public Types | |
enum | CommandType { PSELECT, PUPDATE, PINSERT, PDELETE, PCOUNT, PCALC, PCRETAB } |
enum | GroupAggrType { GROUPBY, AGGR_FUNCS, ONLY_COUNTALL } |
Public Member Functions | |
TableParseSelect (CommandType type) | |
Construct. More... | |
~TableParseSelect () | |
Destructor. More... | |
CommandType | commandType () const |
Return the command type. More... | |
TableExprNode | getNode () const |
Return the expression node. More... | |
void | execute (Bool showTimings, Bool setInGiving, Bool mustSelect, uInt maxRow, Bool doTracing=False) |
Execute the select command (select/sort/projection/groupby/having/giving). More... | |
Table | doFromQuery (Bool showTimings) |
Execute a query in a from clause resulting in a Table. More... | |
TableExprNode | doSubQuery (Bool showTimings) |
Execute a subquery and create an appropriate node for the result. More... | |
TableExprNode | doExists (Bool noexists, Bool showTimings) |
Test if a subquery has sufficient elements. More... | |
void | show (ostream &os) const |
Show the expression tree. More... | |
void | handleWhere (const TableExprNode &) |
Keep the selection expression. More... | |
void | handleGroupby (const vector< TableExprNode > &, Bool rollup) |
Keep the groupby expressions. More... | |
void | handleHaving (const TableExprNode &) |
Keep the having expression. More... | |
void | handleCalcComm (const TableExprNode &) |
Keep the expression of a calculate command. More... | |
void | handleCreTab (const String &tableName, const Record &dmInfo) |
Keep the create table command. More... | |
void | handleColSpec (const String &columnName, const String &dataType, const Record &spec, Bool isCOrder=False) |
Keep the column specification in a create table command. More... | |
void | addUpdate (TableParseUpdate *upd) |
Add an update object. More... | |
void | handleUpdate () |
Keep the update expressions. More... | |
void | handleInsert () |
Make ready for the insert expression. More... | |
void | handleInsert (TableParseSelect *sel) |
void | handleCount () |
Make ready for a COUNT command. More... | |
void | handleSort (const std::vector< TableParseSort > &sortList, Bool noDuplicates, Sort::Order defaultSortOrder) |
Keep the sort expressions. More... | |
void | handleLimit (const TableExprNodeSetElem &expr) |
Evaluate and keep limit/offset/stride given as start:end:incr. More... | |
void | handleLimit (const TableExprNode &expr) |
Evaluate and keep the limit value. More... | |
void | handleOffset (const TableExprNode &expr) |
Evaluate and keep the offset value. More... | |
void | addTable (Int tabnr, const String &name, const Table &table, const String &shorthand, const vector< const Table * > tempTables, const vector< TableParseSelect * > &stack) |
Add a table nr, name, or object to the container. More... | |
void | replaceTable (const Table &table) |
Replace the first table (used by CALC command). More... | |
TableExprNode | handleKeyCol (const String &name, Bool tryProj) |
Find the keyword or column name and create a TableExprNode from it. More... | |
TableExprNode | handleFunc (const String &name, const TableExprNodeSet &arguments, const TaQLStyle &) |
Handle a function. More... | |
void | handleColumn (Int type, const String &name, const TableExprNode &expr, const String &newName, const String &newDtype) |
Add a column to the list of column names. More... | |
void | handleColumnFinish (Bool distinct) |
Finish the addition of columns to the list of column names. More... | |
void | handleGiving (const String &name, Int type) |
Handle the name and type given in a GIVING clause. More... | |
void | handleGiving (const TableExprNodeSet &) |
Handle the set given in a GIVING clause. More... | |
const Block< String > & | getColumnNames () const |
Get the projected column names. More... | |
const Table & | getTable () const |
Get the resulting table. More... | |
Static Public Member Functions | |
static TableExprNode | handleSlice (const TableExprNode &array, const TableExprNodeSet &indices, const TaQLStyle &) |
Handle a slice operator. More... | |
static TableExprNode | makeFuncNode (TableParseSelect *, const String &name, const TableExprNodeSet &arguments, const Vector< int > &ignoreFuncs, const Table &table, const TaQLStyle &) |
Make a function object node for the given function name and arguments. More... | |
static void | checkAggrFuncs (const TableExprNode &node) |
An exception is thrown if the node uses an aggregate function. More... | |
Private Member Functions | |
Int | testGroupAggr (vector< TableExprNodeRep * > &aggr) const |
Test if groupby or aggregate functions are given. More... | |
vector< TableExprNodeRep * > | getAggrNodes () const |
Get the aggregate functions used in SELECT and HAVING. More... | |
void | doUpdate (Bool showTimings, const Table &origTable, Table &updTable, const Vector< uInt > &rownrs, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >()) |
Do the update step. More... | |
Table | doInsert (Bool showTimings, Table &table) |
Do the insert step and return a selection containing the new rows. More... | |
void | doDelete (Bool showTimings, Table &table) |
Do the delete step. More... | |
Table | doCount (Bool showTimings, const Table &) |
Do the count step returning a memory table containing the unique column values and the counts of the column values. More... | |
Table | doProject (Bool showTimings, const Table &, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >()) |
Do the projection step returning a table containing the projection. More... | |
Table | doProjectExpr (Bool useSel, const CountedPtr< TableExprGroupResult > &groups) |
Do the projection containing column expressions. More... | |
void | makeProjectExprTable () |
Make the (empty) table for the epxression in the SELECT clause. More... | |
void | makeProjectExprSel () |
Fill projectExprSelColumn_p telling the columns to be projected at the first stage. More... | |
void | addApplySelNode (const TableExprNode &node) |
Add a column node to applySelNodes_p. More... | |
Table | adjustApplySelNodes (const Table &) |
Set the selected rows for the column objects in applySelNodes_p. More... | |
CountedPtr< TableExprGroupResult > | doGroupby (bool showTimings, vector< TableExprNodeRep * > aggrNodes, Int groupAggrUsed) |
Do the groupby/aggregate step and return its result. More... | |
void | doHaving (Bool showTimings, const CountedPtr< TableExprGroupResult > &groups) |
Do the HAVING step. More... | |
CountedPtr< TableExprGroupResult > | doOnlyCountAll (TableExprNodeRep *aggrNode) |
Do a groupby/aggregate step that only does a 'select count(*)'. More... | |
CountedPtr< TableExprGroupResult > | doGroupByAggr (const vector< TableExprNodeRep * > &aggrNodes) |
Do a full groupby/aggregate step. More... | |
void | doSort (Bool showTimings) |
Do the sort step. More... | |
void | doLimOff (Bool showTimings) |
Do the limit/offset step. More... | |
Table | doLimOff (Bool showTimings, const Table &table) |
Table | doDistinct (Bool showTimings, const Table &table) |
Do the 'select distinct' step. More... | |
Table | doFinish (Bool showTimings, Table &table) |
Finish the table (rename, copy, and/or flush). More... | |
template<typename TCOL , typename TNODE > | |
void | updateValue2 (uInt row, const TableExprId &rowid, Bool isScalarCol, const TableExprNode &node, TableColumn &col, const Slicer *slicerPtr, IPosition &blc, IPosition &trc, IPosition &inc) |
Update the values in the columns (helpers of doUpdate). More... | |
template<typename T > | |
void | updateValue1 (uInt row, const TableExprId &rowid, Bool isScalarCol, const TableExprNode &node, TableColumn &col, const Slicer *slicerPtr, IPosition &blc, IPosition &trc, IPosition &inc) |
DataType | makeDataType (DataType dtype, const String &dtstr, const String &colName) |
Make a data type from the string. More... | |
Sort::Order | getOrder (const TableParseSort &key) const |
Get the order for this key. More... | |
TableExprNode | getColSet () |
Make an array from the contents of a column in a subquery. More... | |
TableExprNode | makeSubSet () const |
Make a set from the results of the subquery. More... | |
Int64 | evalIntScaExpr (const TableExprNode &expr) const |
Evaluate an int scalar expression. More... | |
Bool | splitName (String &shorthand, String &columnName, Vector< String > &fieldNames, const String &name, Bool checkError) const |
Split a name into its parts (shorthand, column and field names). More... | |
Table | findTable (const String &shorthand) const |
Find a table for the given shorthand. More... | |
void | handleWildColumn (Int stringType, const String &name) |
Handle the selection of a wildcarded column name. More... | |
void | addColumnDesc (TableDesc &td, DataType dtype, const String &colName, Int options, Int ndim, const IPosition &shape, const String &dmType, const String &dmGroup, const String &comment, const TableRecord &keywordSet, const String &unitName) |
Add the description of a column to the table description. More... | |
Block< String > | getStoredColumns (const Table &tab) const |
Find the names of all stored columns in a table. More... | |
template<typename T > | |
vector< CountedPtr< TableExprGroupFuncSet > > | doGroupByAggrSingleKey (const vector< TableExprNodeRep * > &aggrNodes) |
Create the set of aggregate functions and groupby keys in case a single groupby key is given. More... | |
vector< CountedPtr< TableExprGroupFuncSet > > | doGroupByAggrMultipleKeys (const vector< TableExprNodeRep * > &aggrNodes) |
Create the set of aggregate functions and groupby keys in case multiple keys are given. More... | |
Static Private Member Functions | |
static TableExprNode | makeUDFNode (TableParseSelect *, const String &name, const TableExprNodeSet &arguments, const Table &table, const TaQLStyle &) |
Try to make a UDF function node for the given function name and arguments. More... | |
static TableExprFuncNode::FunctionType | findFunc (const String &name, uInt narguments, const Vector< Int > &ignoreFuncs) |
Find the function code belonging to a function name. More... | |
static Table | tableKey (const String &fullName, const String &shorthand, const String &columnName, const Vector< String > &fieldNames, const vector< TableParseSelect * > &stack) |
Try to find the keyword representing a table in one of the tables in any select block (from inner to outer). More... | |
static Table | findTableKey (const Table &table, const String &columnName, const Vector< String > &keyNames) |
Try to find the keyword representing a table in the given table. More... | |
Private Attributes | |
CommandType | commandType_p |
TableDesc | tableDesc_p |
vector< TableParse > | fromTables_p |
Block< String > | columnNames_p |
Block< TableExprNode > | columnExpr_p |
Block< String > | columnOldNames_p |
Block< String > | columnDtypes_p |
Block< TableRecord > | columnKeywords_p |
uInt | nrSelExprUsed_p |
Bool | distinct_p |
String | resultName_p |
Int | resultType_p |
TableExprNodeSet * | resultSet_p |
TableExprNode | node_p |
vector< TableExprNode > | groupbyNodes_p |
Bool | groupbyRollup_p |
TableExprNode | havingNode_p |
Int64 | limit_p |
Int64 | endrow_p |
Int64 | offset_p |
Int64 | stride_p |
std::vector< TableParseUpdate * > | update_p |
TableParseSelect * | insSel_p |
std::vector< TableParseSort > | sort_p |
Bool | noDupl_p |
Sort::Order | order_p |
vector< TableExprNode > | applySelNodes_p |
Table | table_p |
Table | firstColTable_p |
String | firstColName_p |
Table | projectExprTable_p |
Block< uInt > | projectExprSubset_p |
Block< Bool > | projectExprSelColumn_p |
Vector< uInt > | rownrs_p |
Select-class for flex/bison scanner/parser for TableParse.
Internal
This class is needed for the the actions in the flex scanner and bison parser. This stores the information by constructing TableParse objects as needed and storing them in a vector.
It is necessary to be able to give a table select command in ASCII. This can be used in a CLI or in the table browser to get a subset of a table or to sort a table.
Definition at line 346 of file TableParse.h.
Enumerator | |
---|---|
PSELECT | |
PUPDATE | |
PINSERT | |
PDELETE | |
PCOUNT | |
PCALC | |
PCRETAB |
Definition at line 349 of file TableParse.h.
Enumerator | |
---|---|
GROUPBY | |
AGGR_FUNCS | |
ONLY_COUNTALL |
Definition at line 359 of file TableParse.h.
casacore::TableParseSelect::TableParseSelect | ( | CommandType | type | ) |
Construct.
casacore::TableParseSelect::~TableParseSelect | ( | ) |
Destructor.
|
inlineprivate |
Add a column node to applySelNodes_p.
Definition at line 571 of file TableParse.h.
References casacore::ndim(), and casacore::shape().
|
private |
Add the description of a column to the table description.
ndim < 0 means a scalar column.
void casacore::TableParseSelect::addTable | ( | Int | tabnr, |
const String & | name, | ||
const Table & | table, | ||
const String & | shorthand, | ||
const vector< const Table * > | tempTables, | ||
const vector< TableParseSelect * > & | stack | ||
) |
Add a table nr, name, or object to the container.
|
inline |
Add an update object.
Definition at line 848 of file TableParse.h.
|
static |
An exception is thrown if the node uses an aggregate function.
|
inline |
Return the command type.
Definition at line 372 of file TableParse.h.
Do the count step returning a memory table containing the unique column values and the counts of the column values.
Do the delete step.
Do the 'select distinct' step.
TableExprNode casacore::TableParseSelect::doExists | ( | Bool | noexists, |
Bool | showTimings | ||
) |
Test if a subquery has sufficient elements.
It uses default LIMIT=1, but that can be overidden in the subquery. The flag tells if NOT EXISTS or EXISTS was given.
Finish the table (rename, copy, and/or flush).
Execute a query in a from clause resulting in a Table.
|
private |
Do the groupby/aggregate step and return its result.
|
private |
Do a full groupby/aggregate step.
|
private |
Create the set of aggregate functions and groupby keys in case multiple keys are given.
|
inlineprivate |
Create the set of aggregate functions and groupby keys in case a single groupby key is given.
This offers much faster map access then doGroupByAggrMultiple.
We have to group the data according to the (possibly empty) groupby. We step through the table in the normal order which may not be the groupby order. A map<key,int> is used to keep track of the results where the int is the index in a vector of a set of aggregate function objects.
Loop through all rows. For each row generate the key to get the right entry.
Definition at line 695 of file TableParse.h.
References casacore::max(), and casacore::TableExprId::setRownr().
|
private |
Do the HAVING step.
Do the insert step and return a selection containing the new rows.
|
private |
Do the limit/offset step.
|
private |
Do a groupby/aggregate step that only does a 'select count(*)'.
|
private |
Do the projection step returning a table containing the projection.
|
private |
Do the projection containing column expressions.
Use the selected or unselected columns depending on useSel
.
|
private |
Do the sort step.
TableExprNode casacore::TableParseSelect::doSubQuery | ( | Bool | showTimings | ) |
Execute a subquery and create an appropriate node for the result.
|
private |
Do the update step.
Rows 0,1,2,.. in UpdTable are updated from the expression result for the rows in the given rownrs vector.
|
private |
Evaluate an int scalar expression.
void casacore::TableParseSelect::execute | ( | Bool | showTimings, |
Bool | setInGiving, | ||
Bool | mustSelect, | ||
uInt | maxRow, | ||
Bool | doTracing = False |
||
) |
Execute the select command (select/sort/projection/groupby/having/giving).
The setInGiving flag tells if a set in the GIVING part is allowed. The mustSelect flag tells if a SELECT command must do something. Usually that is required, but not for a SELECT in an INSERT command. Optionally the maximum nr of rows to be selected can be given. It will be used as the default value for the LIMIT clause. 0 = no maximum.
|
staticprivate |
Find the function code belonging to a function name.
Functions to be ignored can be given (as function type values). If the function name is unknown, NRFUNC is returned.
Find a table for the given shorthand.
If no shorthand is given, the first table is returned (if there). If not found, a null Table object is returned.
|
staticprivate |
Try to find the keyword representing a table in the given table.
If the columnName is empty, the keyword is a table keyword. If not found, a null Table object is returned.
|
private |
Get the aggregate functions used in SELECT and HAVING.
|
private |
Make an array from the contents of a column in a subquery.
Get the projected column names.
Definition at line 842 of file TableParse.h.
|
inline |
Return the expression node.
Definition at line 376 of file TableParse.h.
References casacore::array(), casacore::False, casacore::TableParse::shorthand(), and casacore::TableParse::table().
|
inlineprivate |
Get the order for this key.
Use the default order_p if not explicitly given with the key.
Definition at line 851 of file TableParse.h.
References casacore::TableParseSort::order(), and casacore::TableParseSort::orderGiven().
Find the names of all stored columns in a table.
|
inline |
Get the resulting table.
Definition at line 845 of file TableParse.h.
References casacore::TableParse::table_p.
void casacore::TableParseSelect::handleCalcComm | ( | const TableExprNode & | ) |
Keep the expression of a calculate command.
void casacore::TableParseSelect::handleColSpec | ( | const String & | columnName, |
const String & | dataType, | ||
const Record & | spec, | ||
Bool | isCOrder = False |
||
) |
Keep the column specification in a create table command.
void casacore::TableParseSelect::handleColumn | ( | Int | type, |
const String & | name, | ||
const TableExprNode & | expr, | ||
const String & | newName, | ||
const String & | newDtype | ||
) |
Add a column to the list of column names.
void casacore::TableParseSelect::handleColumnFinish | ( | Bool | distinct | ) |
Finish the addition of columns to the list of column names.
void casacore::TableParseSelect::handleCount | ( | ) |
Make ready for a COUNT command.
It checks if all column expressions are scalar.
Keep the create table command.
TableExprNode casacore::TableParseSelect::handleFunc | ( | const String & | name, |
const TableExprNodeSet & | arguments, | ||
const TaQLStyle & | |||
) |
Handle a function.
Handle the name and type given in a GIVING clause.
void casacore::TableParseSelect::handleGiving | ( | const TableExprNodeSet & | ) |
Handle the set given in a GIVING clause.
void casacore::TableParseSelect::handleGroupby | ( | const vector< TableExprNode > & | , |
Bool | rollup | ||
) |
Keep the groupby expressions.
It checks if they are all scalar expressions.
void casacore::TableParseSelect::handleHaving | ( | const TableExprNode & | ) |
Keep the having expression.
void casacore::TableParseSelect::handleInsert | ( | ) |
Make ready for the insert expression.
The first one uses values (added via addUpdate), the second one a subquery.
void casacore::TableParseSelect::handleInsert | ( | TableParseSelect * | sel | ) |
TableExprNode casacore::TableParseSelect::handleKeyCol | ( | const String & | name, |
Bool | tryProj | ||
) |
Find the keyword or column name and create a TableExprNode from it.
If tryProj=True
it is first tried if the column is a coluymn in the projected table (i.e., result from the SELECT part).
void casacore::TableParseSelect::handleLimit | ( | const TableExprNodeSetElem & | expr | ) |
Evaluate and keep limit/offset/stride given as start:end:incr.
void casacore::TableParseSelect::handleLimit | ( | const TableExprNode & | expr | ) |
Evaluate and keep the limit value.
void casacore::TableParseSelect::handleOffset | ( | const TableExprNode & | expr | ) |
Evaluate and keep the offset value.
|
static |
Handle a slice operator.
void casacore::TableParseSelect::handleSort | ( | const std::vector< TableParseSort > & | sortList, |
Bool | noDuplicates, | ||
Sort::Order | defaultSortOrder | ||
) |
Keep the sort expressions.
void casacore::TableParseSelect::handleUpdate | ( | ) |
Keep the update expressions.
void casacore::TableParseSelect::handleWhere | ( | const TableExprNode & | ) |
Keep the selection expression.
Handle the selection of a wildcarded column name.
|
private |
Make a data type from the string.
It checks if it is compatible with the given (expression) data type.
|
static |
Make a function object node for the given function name and arguments.
The ignoreFuncs vector contains invalid function codes.
|
private |
Fill projectExprSelColumn_p telling the columns to be projected at the first stage.
|
private |
Make the (empty) table for the epxression in the SELECT clause.
|
private |
Make a set from the results of the subquery.
|
staticprivate |
Try to make a UDF function node for the given function name and arguments.
void casacore::TableParseSelect::replaceTable | ( | const Table & | table | ) |
Replace the first table (used by CALC command).
void casacore::TableParseSelect::show | ( | ostream & | os | ) | const |
Show the expression tree.
|
private |
Split a name into its parts (shorthand, column and field names).
True is returned when the name contained a keyword part. In that case fieldNames contains the keyword name and the possible subfields. The possible shorthand and the column name are filled in if it is a column keyword. If the name represents a column, fieldNames contains the subfields of the column (for the case where the column contains records). If the name is invalid, an exception is thrown if checkError=True. Otherwise the name is treated as a normal name without keyword.
|
staticprivate |
Try to find the keyword representing a table in one of the tables in any select block (from inner to outer).
If not found, an exception is thrown.
|
private |
Test if groupby or aggregate functions are given.
bit 0: on = groupby is given
bit 1: on = aggregate functions are given
bit 2: on = only select count(*) aggregate function is given
|
private |
|
private |
Update the values in the columns (helpers of doUpdate).
|
private |
Definition at line 790 of file TableParse.h.
Definition at line 749 of file TableParse.h.
|
private |
Definition at line 745 of file TableParse.h.
|
private |
Definition at line 751 of file TableParse.h.
Definition at line 743 of file TableParse.h.
Definition at line 747 of file TableParse.h.
|
private |
Definition at line 735 of file TableParse.h.
|
private |
Definition at line 755 of file TableParse.h.
|
private |
Definition at line 772 of file TableParse.h.
|
private |
Definition at line 796 of file TableParse.h.
|
private |
Definition at line 795 of file TableParse.h.
|
private |
Definition at line 741 of file TableParse.h.
|
private |
Definition at line 764 of file TableParse.h.
|
private |
Definition at line 765 of file TableParse.h.
|
private |
Definition at line 767 of file TableParse.h.
|
private |
Definition at line 780 of file TableParse.h.
|
private |
Definition at line 769 of file TableParse.h.
|
private |
Definition at line 762 of file TableParse.h.
|
private |
Definition at line 784 of file TableParse.h.
|
private |
Definition at line 753 of file TableParse.h.
|
private |
Definition at line 774 of file TableParse.h.
|
private |
Definition at line 786 of file TableParse.h.
Definition at line 801 of file TableParse.h.
Definition at line 800 of file TableParse.h.
|
private |
Definition at line 798 of file TableParse.h.
|
private |
Definition at line 757 of file TableParse.h.
|
private |
Definition at line 760 of file TableParse.h.
|
private |
Definition at line 758 of file TableParse.h.
Definition at line 803 of file TableParse.h.
|
private |
Definition at line 782 of file TableParse.h.
|
private |
Definition at line 776 of file TableParse.h.
|
private |
Definition at line 792 of file TableParse.h.
|
private |
Definition at line 737 of file TableParse.h.
|
private |
Definition at line 778 of file TableParse.h.