|
casacore
|
#include <TableParseQuery.h>
Public Types | |
| enum | CommandType { PSELECT , PUPDATE , PINSERT , PDELETE , PCOUNT , PCALC , PCRETAB , PALTTAB , PDROPTAB , PSHOW } |
Public Member Functions | |
| TableParseQuery (CommandType type) | |
| Construct. | |
| ~TableParseQuery () | |
| Destructor. | |
| CommandType | commandType () const |
| Return the command type. | |
| TableExprNode | getNode () const |
| Return the expression node. | |
| TableParseTableList & | tableList () |
| Return the table name list. | |
| Table & | projectExprTable () |
| void | execute (Bool showTimings, Bool setInGiving, Bool mustSelect, rownr_t maxRow, Bool doTracing=False, const std::vector< const Table * > &tempTables=std::vector< const Table * >(), const std::vector< TableParseQuery * > &stack=std::vector< TableParseQuery * >()) |
| Execute the select command (select/sort/projection/groupby/having/giving). | |
| Table | doFromQuery (Bool showTimings) |
| Execute a query in a FROM clause resulting in a Table. | |
| TableExprNode | doSubQuery (Bool showTimings) |
| Execute a subquery and create an appropriate node for the result. | |
| TableExprNode | doExists (Bool noexists, Bool showTimings) |
| Test if a subquery has sufficient elements. | |
| void | show (ostream &os) const |
| Show the expression tree. | |
| void | handleTableNoFrom () |
| Create a temporary table if no tables are given in FROM. | |
| void | handleWhere (const TableExprNode &) |
| Keep the selection expression. | |
| void | handleGroupby (const std::vector< TableExprNode > &, Bool rollup) |
| Keep the groupby expressions. | |
| void | handleHaving (const TableExprNode &) |
| Keep the having expression. | |
| void | handleCalcComm (const TableExprNode &) |
| Keep the expression of a calculate command. | |
| void | handleDropTab (const std::vector< const Table * > &tempTables, const std::vector< TableParseQuery * > &stack) |
| Handle the DROP TABLE command. | |
| void | handleCreTab (const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseQuery * > &stack) |
| Keep the create table command. | |
| void | handleColSpec (const String &columnName, const String &likeColName, const String &dataType, const Record &spec, Bool isCOrder=False) |
| Keep the column specification in a create table command. | |
| void | handleAltTab () |
| Reopen the table (for update) used in the ALTER TABLE command. | |
| void | handleAddCol (const Record &dmInfo) |
| Add columns to the table of ALTER TABLE. | |
| void | handleCopyCol (Bool showTimings) |
| Handle copying of columns. | |
| void | handleSetKey (const String &name, const String &dtype, const ValueHolder &value) |
| Add a keyword or replace a keyword with a value. | |
| void | handleRenameKey (const String &oldName, const String &newName) |
| Rename a table or column keyword. | |
| void | handleRemoveKey (const String &name) |
| Remove a table or column keyword. | |
| void | handleUpdate () |
| Keep the update expressions. | |
| void | handleInsert () |
| Make ready for the insert expression. | |
| void | handleInsert (TableParseQuery *sel) |
| void | handleCount () |
| Make ready for a COUNT command. | |
| void | handleSort (const std::vector< TableParseSortKey > &sortList, Bool noDuplicates, Sort::Order defaultSortOrder) |
| Keep the sort expressions. | |
| void | handleLimit (const TableExprNodeSetElem &expr) |
| Evaluate and keep limit/offset/stride given as start:end:incr. | |
| void | handleLimit (const TableExprNode &expr) |
| Evaluate and keep the limit value. | |
| void | handleOffset (const TableExprNode &expr) |
| Evaluate and keep the offset value. | |
| void | handleAddRow (const TableExprNode &expr) |
| Evaluate and add the rows. | |
| TableParseJoin & | addJoin () |
| Add a join object. | |
| TableExprNode | handleKeyCol (const String &name, Bool tryProj) |
| Find the keyword or column name and create a TableExprNode from it. | |
| TableExprNode | handleFunc (const String &name, const TableExprNodeSet &arguments, const TaQLStyle &) |
| Handle a function. | |
| void | handleColumn (Int type, const String &name, const TableExprNode &expr, const String &newName, const String &nameMask, const String &newDtype) |
| Add a column to the list of column names. | |
| void | handleColumnFinish (Bool distinct) |
| Finish the addition of columns to the list of column names. | |
| void | handleGiving (const String &name, const Record &type) |
| Handle the name and type given in a GIVING clause. | |
| void | handleGiving (const TableExprNodeSet &) |
| Handle the set given in a GIVING clause. | |
| const std::vector< TableParseJoin > & | joins () const |
| Get the TableParseJoin objects. | |
| void | initDescriptions (const TableDesc &, const Record &dminfo) |
| Initialize the table and data manager descriptions. | |
| ValueHolder | getRecFld (const String &name) |
| Add a keyword or replace a keyword with the value of another keyword. | |
| TableRecord & | findKeyword (const String &name, String &keyName, Bool update=True) |
| Split the given name into optional shorthand, column and fields. | |
| void | addUpdate (const std::shared_ptr< TableParseUpdate > &upd) |
| Add an update object. | |
| void | setInsertExprs (const std::vector< TableExprNode > exprs) |
| Set the insert expressions for all rows. | |
| void | replaceTable (const Table &table) |
| Replace the first table (used by CALC command). | |
| void | setDMInfo (const Record &dminfo) |
| Set the DataManager info for a new table. | |
| const Block< String > & | getColumnNames () const |
| Get the projected column names. | |
| const Table & | getTable () const |
| Get the resulting table. | |
| String | getTableStructure (const Vector< String > &parts, const TaQLStyle &style) |
| Show the structure of fromTables_p[0] using the options given in parts[2:]. | |
| void | addApplySelNode (const TableExprNode &node) |
| Add a column node to applySelNodes_p. | |
| Table | createTable (const TableDesc &td, Int64 nrow, const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseQuery * > &stack) |
| Create a table using the given parameters. | |
Static Public Member Functions | |
| static TableExprNode | handleSlice (const TableExprNode &array, const TableExprNodeSet &indices, const TaQLStyle &) |
| Handle a slice operator. | |
Private Member Functions | |
| void | doUpdate (Bool showTimings, const Table &origTable, Table &updTable, const Vector< rownr_t > &rownrs, const std::shared_ptr< TableExprGroupResult > &groups=std::shared_ptr< TableExprGroupResult >()) |
| Do the update step. | |
| Table | doInsert (Bool showTimings, Table &table) |
| Do the insert step and return a selection containing the new rows. | |
| void | doDelete (Bool showTimings, Table &table) |
| Do the delete step. | |
| 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. | |
| Table | doProject (Bool showTimings, const Table &, const std::shared_ptr< TableExprGroupResult > &groups=std::shared_ptr< TableExprGroupResult >()) |
| Do the projection step returning a table containing the projection. | |
| Table | doProjectExpr (Bool useSel, const std::shared_ptr< TableExprGroupResult > &groups) |
| Do the projection containing column expressions. | |
| Table | createSubTable (const String &subtableName, const TableDesc &td, Int64 nrow, const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseQuery * > &stack) |
| Create a subtable (used by createTable). | |
| Table | adjustApplySelNodes (const Table &) |
| Set the selected rows for the column objects in applySelNodes_p. | |
| std::shared_ptr< TableExprGroupResult > | doGroupby (bool showTimings) |
| Do the groupby/aggregate step and return its result. | |
| Bool | doHaving (Bool showTimings, const std::shared_ptr< TableExprGroupResult > &groups) |
| Do the HAVING step. | |
| void | doSort (Bool showTimings) |
| Do the sort step. | |
| void | doLimOff (Bool showTimings) |
| Do the limit/offset step. | |
| Table | doLimOff (Bool showTimings, const Table &table) |
| Table | doDistinct (Bool showTimings, const Table &table) |
| Do the 'select distinct' step. | |
| Table | doFinish (Bool showTimings, Table &table, const std::vector< const Table * > &tempTables, const std::vector< TableParseQuery * > &stack) |
| Finish the table (rename, copy, and/or flush). | |
| TableExprNode | getColSet () |
| Make an array from the contents of a column in a subquery. | |
| TableExprNode | makeSubSet () const |
| Make a set from the results of the subquery. | |
| Int64 | evalIntScaExpr (const TableExprNode &expr) const |
| Evaluate an int scalar expression. | |
Private Attributes | |
| CommandType | commandType_p |
| TableParseTableList | tableList_p |
| std::vector< TableParseJoin > | joins_p |
| TableParseProject | tableProject_p |
| String | resultName_p |
| uInt | resultType_p |
| Bool | resultCreated_p |
| StorageOption | storageOption_p |
| Table::EndianFormat | endianFormat_p |
| Bool | overwrite_p |
| TableExprNodeSet * | resultSet_p |
| TableExprNode | node_p |
| TableParseGroupby | groupby_p |
| Bool | distinct_p |
| Int64 | limit_p |
| Int64 | endrow_p |
| Int64 | offset_p |
| Int64 | stride_p |
| std::vector< std::shared_ptr< TableParseUpdate > > | update_p |
| std::vector< TableExprNode > | insertExprs_p |
| TableParseQuery * | insSel_p |
| std::vector< TableParseSortKey > | sort_p |
| Bool | noDupl_p |
| Sort::Order | order_p |
| std::vector< TableExprNode > | applySelNodes_p |
| Table | table_p |
| Table | projectExprTable_p |
| Vector< rownr_t > | rownrs_p |
Class getting the parser results and executing a query
Internal
The results of the bison parser TableGram.yy and flex scanner TableGram.ll are stored in a tree of TaQLNode objects. When the parsing of a TaQL command is fully done, the tree is traversed by TaQLNodeHandler which creates and fills a stack of TableParseQuery objects, one object per (nested) query. A nested query is executed once it is fully handled.
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 93 of file TableParseQuery.h.
| Enumerator | |
|---|---|
| PSELECT | |
| PUPDATE | |
| PINSERT | |
| PDELETE | |
| PCOUNT | |
| PCALC | |
| PCRETAB | |
| PALTTAB | |
| PDROPTAB | |
| PSHOW | |
Definition at line 96 of file TableParseQuery.h.
| casacore::TableParseQuery::TableParseQuery | ( | CommandType | type | ) |
Construct.
| casacore::TableParseQuery::~TableParseQuery | ( | ) |
Destructor.
|
inline |
Add a column node to applySelNodes_p.
Definition at line 317 of file TableParseQuery.h.
References applySelNodes_p.
| TableParseJoin & casacore::TableParseQuery::addJoin | ( | ) |
Add a join object.
|
inline |
|
inline |
Return the command type.
Definition at line 116 of file TableParseQuery.h.
References commandType_p.
|
private |
Create a subtable (used by createTable).
| Table casacore::TableParseQuery::createTable | ( | const TableDesc & | td, |
| Int64 | nrow, | ||
| const Record & | dmInfo, | ||
| const std::vector< const Table * > & | tempTables, | ||
| const std::vector< TableParseQuery * > & | stack | ||
| ) |
Create a table using the given parameters.
The variables set by handleGiven are used for name and type.
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::TableParseQuery::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.
|
private |
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 the HAVING step.
It returns False if no HAVING step was given.
Do the insert step and return a selection containing the new rows.
|
private |
Do the limit/offset step.
|
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::TableParseQuery::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::TableParseQuery::execute | ( | Bool | showTimings, |
| Bool | setInGiving, | ||
| Bool | mustSelect, | ||
| rownr_t | maxRow, | ||
| Bool | doTracing = False, |
||
| const std::vector< const Table * > & | tempTables = std::vector< const Table * >(), |
||
| const std::vector< TableParseQuery * > & | stack = std::vector< TableParseQuery * >() |
||
| ) |
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.
| TableRecord & casacore::TableParseQuery::findKeyword | ( | const String & | name, |
| String & | keyName, | ||
| Bool | update = True |
||
| ) |
Split the given name into optional shorthand, column and fields.
Find the keywordset for it and fill in the final keyword name. It is a helper function for handleSetKey, etc. If update=True, rwKeywordSet() is used to ensure the table is updated.
|
private |
Make an array from the contents of a column in a subquery.
Get the projected column names.
Definition at line 306 of file TableParseQuery.h.
References casacore::TableParseProject::getColumnNames(), and tableProject_p.
|
inline |
| ValueHolder casacore::TableParseQuery::getRecFld | ( | const String & | name | ) |
Add a keyword or replace a keyword with the value of another keyword.
The keywords can be table or column keywords (col::key).
|
inline |
| String casacore::TableParseQuery::getTableStructure | ( | const Vector< String > & | parts, |
| const TaQLStyle & | style | ||
| ) |
Show the structure of fromTables_p[0] using the options given in parts[2:].
| void casacore::TableParseQuery::handleAddCol | ( | const Record & | dmInfo | ) |
Add columns to the table of ALTER TABLE.
The column descriptions have already been added to tableDesc_p.
| void casacore::TableParseQuery::handleAddRow | ( | const TableExprNode & | expr | ) |
Evaluate and add the rows.
| void casacore::TableParseQuery::handleAltTab | ( | ) |
Reopen the table (for update) used in the ALTER TABLE command.
| void casacore::TableParseQuery::handleCalcComm | ( | const TableExprNode & | ) |
Keep the expression of a calculate command.
| void casacore::TableParseQuery::handleColSpec | ( | const String & | columnName, |
| const String & | likeColName, | ||
| const String & | dataType, | ||
| const Record & | spec, | ||
| Bool | isCOrder = False |
||
| ) |
Keep the column specification in a create table command.
| void casacore::TableParseQuery::handleColumn | ( | Int | type, |
| const String & | name, | ||
| const TableExprNode & | expr, | ||
| const String & | newName, | ||
| const String & | nameMask, | ||
| const String & | newDtype | ||
| ) |
Add a column to the list of column names.
| void casacore::TableParseQuery::handleColumnFinish | ( | Bool | distinct | ) |
Finish the addition of columns to the list of column names.
| void casacore::TableParseQuery::handleCopyCol | ( | Bool | showTimings | ) |
Handle copying of columns.
| void casacore::TableParseQuery::handleCount | ( | ) |
Make ready for a COUNT command.
It checks if all column expressions are scalar.
| void casacore::TableParseQuery::handleCreTab | ( | const Record & | dmInfo, |
| const std::vector< const Table * > & | tempTables, | ||
| const std::vector< TableParseQuery * > & | stack | ||
| ) |
Keep the create table command.
| void casacore::TableParseQuery::handleDropTab | ( | const std::vector< const Table * > & | tempTables, |
| const std::vector< TableParseQuery * > & | stack | ||
| ) |
Handle the DROP TABLE command.
| TableExprNode casacore::TableParseQuery::handleFunc | ( | const String & | name, |
| const TableExprNodeSet & | arguments, | ||
| const TaQLStyle & | |||
| ) |
Handle a function.
Handle the name and type given in a GIVING clause.
| void casacore::TableParseQuery::handleGiving | ( | const TableExprNodeSet & | ) |
Handle the set given in a GIVING clause.
| void casacore::TableParseQuery::handleGroupby | ( | const std::vector< TableExprNode > & | , |
| Bool | rollup | ||
| ) |
Keep the groupby expressions.
It checks if they are all scalar expressions.
| void casacore::TableParseQuery::handleHaving | ( | const TableExprNode & | ) |
Keep the having expression.
| void casacore::TableParseQuery::handleInsert | ( | ) |
Make ready for the insert expression.
The first one uses values (added via addUpdate), the second one a subquery.
| void casacore::TableParseQuery::handleInsert | ( | TableParseQuery * | sel | ) |
| TableExprNode casacore::TableParseQuery::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 column in the projected table (i.e., result from the SELECT part).
| void casacore::TableParseQuery::handleLimit | ( | const TableExprNode & | expr | ) |
Evaluate and keep the limit value.
| void casacore::TableParseQuery::handleLimit | ( | const TableExprNodeSetElem & | expr | ) |
Evaluate and keep limit/offset/stride given as start:end:incr.
| void casacore::TableParseQuery::handleOffset | ( | const TableExprNode & | expr | ) |
Evaluate and keep the offset value.
| void casacore::TableParseQuery::handleRemoveKey | ( | const String & | name | ) |
Remove a table or column keyword.
Rename a table or column keyword.
| void casacore::TableParseQuery::handleSetKey | ( | const String & | name, |
| const String & | dtype, | ||
| const ValueHolder & | value | ||
| ) |
Add a keyword or replace a keyword with a value.
The keyword can be a table or column keyword (col::key). The data type string can be empty leaving the data type unchanged.
|
static |
Handle a slice operator.
| void casacore::TableParseQuery::handleSort | ( | const std::vector< TableParseSortKey > & | sortList, |
| Bool | noDuplicates, | ||
| Sort::Order | defaultSortOrder | ||
| ) |
Keep the sort expressions.
| void casacore::TableParseQuery::handleTableNoFrom | ( | ) |
Create a temporary table if no tables are given in FROM.
| void casacore::TableParseQuery::handleUpdate | ( | ) |
Keep the update expressions.
| void casacore::TableParseQuery::handleWhere | ( | const TableExprNode & | ) |
Keep the selection expression.
Initialize the table and data manager descriptions.
|
inline |
Get the TableParseJoin objects.
Definition at line 273 of file TableParseQuery.h.
References joins_p.
|
private |
Make a set from the results of the subquery.
|
inline |
Definition at line 127 of file TableParseQuery.h.
References projectExprTable_p.
| void casacore::TableParseQuery::replaceTable | ( | const Table & | table | ) |
Replace the first table (used by CALC command).
|
inline |
Set the DataManager info for a new table.
Definition at line 302 of file TableParseQuery.h.
References casacore::TableParseProject::setDMInfo(), and tableProject_p.
|
inline |
Set the insert expressions for all rows.
Definition at line 295 of file TableParseQuery.h.
References insertExprs_p.
| void casacore::TableParseQuery::show | ( | ostream & | os | ) | const |
Show the expression tree.
|
inline |
Return the table name list.
Definition at line 124 of file TableParseQuery.h.
References tableList_p.
|
private |
Definition at line 449 of file TableParseQuery.h.
Referenced by addApplySelNode().
|
private |
Definition at line 403 of file TableParseQuery.h.
Referenced by commandType().
|
private |
Definition at line 424 of file TableParseQuery.h.
|
private |
Definition at line 415 of file TableParseQuery.h.
|
private |
Definition at line 429 of file TableParseQuery.h.
|
private |
Definition at line 422 of file TableParseQuery.h.
|
private |
Definition at line 437 of file TableParseQuery.h.
Referenced by setInsertExprs().
|
private |
Definition at line 439 of file TableParseQuery.h.
|
private |
Definition at line 407 of file TableParseQuery.h.
Referenced by joins().
|
private |
Definition at line 426 of file TableParseQuery.h.
|
private |
Definition at line 420 of file TableParseQuery.h.
Referenced by getNode().
|
private |
Definition at line 443 of file TableParseQuery.h.
|
private |
Definition at line 431 of file TableParseQuery.h.
|
private |
Definition at line 445 of file TableParseQuery.h.
|
private |
Definition at line 416 of file TableParseQuery.h.
|
private |
Definition at line 453 of file TableParseQuery.h.
Referenced by projectExprTable().
|
private |
Definition at line 413 of file TableParseQuery.h.
|
private |
Definition at line 411 of file TableParseQuery.h.
|
private |
Definition at line 418 of file TableParseQuery.h.
|
private |
Definition at line 412 of file TableParseQuery.h.
Definition at line 455 of file TableParseQuery.h.
|
private |
Definition at line 441 of file TableParseQuery.h.
|
private |
Definition at line 414 of file TableParseQuery.h.
|
private |
Definition at line 433 of file TableParseQuery.h.
|
private |
Definition at line 451 of file TableParseQuery.h.
Referenced by getTable().
|
private |
Definition at line 405 of file TableParseQuery.h.
Referenced by tableList().
|
private |
Definition at line 409 of file TableParseQuery.h.
Referenced by getColumnNames(), and setDMInfo().
|
private |
Definition at line 435 of file TableParseQuery.h.
Referenced by addUpdate().