28 #ifndef TABLES_TABLEPARSE_H
29 #define TABLES_TABLEPARSE_H
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/Tables/Table.h>
34 #include <casacore/tables/Tables/TableDesc.h>
35 #include <casacore/tables/TaQL/ExprNode.h>
36 #include <casacore/tables/TaQL/TaQLResult.h>
37 #include <casacore/tables/TaQL/ExprGroup.h>
38 #include <casacore/casa/Arrays/ArrayFwd.h>
39 #include <casacore/casa/BasicSL/String.h>
40 #include <casacore/casa/Utilities/Sort.h>
41 #include <casacore/casa/Containers/Record.h>
42 #include <casacore/casa/Containers/Block.h>
50 class TableExprNodeSet;
51 class TableExprNodeSetElem;
52 class TableExprNodeIndex;
55 template<
class T>
class ArrayColumn;
161 const Table& tempTable);
163 const std::vector<const Table*>& tempTables);
170 const std::vector<const Table*>& tempTables,
173 const std::vector<const Table*>& tempTables,
436 const std::vector<const Table*>& tempTables = std::vector<const Table*>(),
437 const std::vector<TableParseSelect*>& stack = std::vector<TableParseSelect*>());
468 const std::vector<TableParseSelect*>& stack);
472 const std::vector<const Table*>& tempTables,
473 const std::vector<TableParseSelect*>& stack);
549 void handleSort (
const std::vector<TableParseSort>& sortList,
569 const std::vector<const Table*>& tempTables,
570 const std::vector<TableParseSelect*>& stack);
578 const std::vector<const Table*>& tempTables,
579 const std::vector<TableParseSelect*>& stack,
710 const std::vector<const Table*>& tempTables,
711 const std::vector<TableParseSelect*>& stack);
715 const std::vector<const Table*>& tempTables,
716 const std::vector<TableParseSelect*>& stack);
720 const String& subTableName,
721 const std::vector<const Table*>& tempTables,
722 const std::vector<TableParseSelect*>& stack);
744 (
bool showTimings,
const std::vector<TableExprNodeRep*> aggrNodes,
756 (
const std::vector<TableExprNodeRep*>& aggrNodes);
770 const std::vector<const Table*>& tempTables,
771 const std::vector<TableParseSelect*>& stack);
775 template<
typename TCOL,
typename TNODE>
781 template<
typename TCOL,
typename TNODE>
785 template<
typename TCOL,
typename TNODE>
790 template<
typename TCOL,
typename TNODE>
796 template<
typename TCOL,
typename TNODE>
834 const std::vector<TableParseSelect*>& stack)
const;
848 const Record& attributes);
855 const String& newColName)
const;
869 (
const std::vector<TableExprNodeRep*>& aggrNodes)
876 std::vector<CountedPtr<TableExprGroupFuncSet> > funcSets;
877 std::map<T, int> keyFuncMap;
887 if (key != lastKey) {
888 typename std::map<T, int>::iterator iter = keyFuncMap.find (key);
889 if (iter == keyFuncMap.end()) {
890 groupnr = funcSets.size();
891 keyFuncMap[key] = groupnr;
894 groupnr = iter->second;
898 funcSets[groupnr]->apply (rowid);
906 (
const std::vector<TableExprNodeRep*>& aggrNodes);
961 std::vector<CountedPtr<TableParseUpdate>>
update_p;
Referenced counted pointer for constant data.
Order
Enumerate the sort order:
String: the storage and methods of handling collections of characters.
Bool empty() const
Test for empty.
Class containing the results of aggregated values in a group.
void setRownr(rownr_t rownr)
Set the row number.
The index of an array element in a table select expression.
Abstract base class for a node in a table column expression tree.
Class to hold multiple table expression nodes.
void adaptUnit(const Unit &)
Adapt the unit of the expression to the given unit (if not empty).
Select-class for flex/bison scanner/parser for TableParse.
void updateSlice(rownr_t row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, const Slicer &slice, ArrayColumn< TCOL > &col)
void doUpdate(Bool showTimings, const Table &origTable, Table &updTable, const Vector< rownr_t > &rownrs, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >())
Do the update step.
TableExprNode getNode() const
Return the expression node.
Block< String > getStoredColumns(const Table &tab) const
Find the names of all stored columns in a table.
void updateArray(rownr_t row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, ArrayColumn< TCOL > &col)
Array< Bool > makeMaskSlice(const Array< Bool > &mask, Bool maskFirst, const IPosition &shapeCol, const Slicer *slicerPtr)
TableExprNode doExists(Bool noexists, Bool showTimings)
Test if a subquery has sufficient elements.
Table::EndianFormat endianFormat_p
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.
void setDMInfo(const Record &dminfo)
Set the DataManager info for a new table.
const Table & getTable() const
Get the resulting table.
void updateScalar(rownr_t row, const TableExprId &rowid, const TableExprNode &node, TableColumn &col)
CommandType commandType() const
Return the command type.
std::shared_ptr< TableDesc > tableDesc_p
Table getTable(Int tabnr, const String &name, const Table &ftab, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack, Bool alwaysOpen=True)
Make a Table object for given name, seqnr or so.
void initDescriptions(const TableDesc &, const Record &dminfo)
Initialize the table and data manager descriptions.
std::vector< TableParseSort > sort_p
void handleAddCol(const Record &dmInfo)
Add columns to the table of ALTER TABLE.
void setInsertExprs(const std::vector< TableExprNode > exprs)
Set the insert expressions for all rows.
Table findTable(const String &shorthand, Bool doWith) const
Find a table for the given shorthand.
std::vector< TableExprNode > insertExprs_p
void handleGiving(const TableExprNodeSet &)
Handle the set given in a GIVING clause.
void handleHaving(const TableExprNode &)
Keep the having expression.
Block< TableExprNode > columnExpr_p
void handleGiving(const String &name, const Record &type)
Handle the name and type given in a GIVING clause.
void show(ostream &os) const
Show the expression tree.
Sort::Order getOrder(const TableParseSort &key) const
Get the order for this key.
Table openParentTable(const String &fullName, const String &subTableName, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Open the parent table of a subtable.
void addUpdate(const CountedPtr< TableParseUpdate > &upd)
Add an update object.
Block< Bool > projectExprSelColumn_p
DataType makeDataType(DataType dtype, const String &dtstr, const String &colName)
Make a data type from the string.
TableExprNode makeSubSet() const
Make a set from the results of the subquery.
void handleWhere(const TableExprNode &)
Keep the selection expression.
std::vector< TableExprNodeRep * > getAggrNodes() const
Get the aggregate functions used in SELECT and HAVING.
String getTableInfo(const Vector< String > &parts, const TaQLStyle &style)
Show the structure of fromTables_p[0] using the options given in parts[2:].
std::vector< TableParse > withTables_p
std::vector< CountedPtr< TableExprGroupFuncSet > > doGroupByAggrSingleKey(const std::vector< TableExprNodeRep * > &aggrNodes)
Create the set of aggregate functions and groupby keys in case a single groupby key is given.
static Bool splitName(String &shorthand, String &columnName, Vector< String > &fieldNames, const String &name, Bool checkError, Bool isKeyword, Bool allowNoKey)
Split a name into its parts (shorthand, column and field names).
Block< String > columnOldNames_p
void handleWildColumn(Int stringType, const String &name)
Handle the selection of a wildcarded column name.
void doHaving(Bool showTimings, const CountedPtr< TableExprGroupResult > &groups)
Do the HAVING step.
void handleSetKey(const String &name, const String &dtype, const ValueHolder &value)
Add a keyword or replace a keyword with a value.
const Block< String > & getColumnNames() const
Get the projected column names.
TableExprNode doSubQuery(Bool showTimings)
Execute a subquery and create an appropriate node for the result.
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 Vector< String > &unitName, const Record &attributes)
Add the description of a column to the table description.
void handleCreTab(const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Keep the create table command.
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.
~TableParseSelect()
Destructor.
CommandType commandType_p
TableExprNode handleKeyCol(const String &name, Bool tryProj)
Find the keyword or column name and create a TableExprNode from it.
static void setRecFld(RecordInterface &rec, const String &name, const String &dtype, const ValueHolder &vh)
Define a field with the given data type in the Record.
void handleColumnFinish(Bool distinct)
Finish the addition of columns to the list of column names.
Table createSubTable(const String &subtableName, const TableDesc &td, Int64 nrow, const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
ValueHolder getRecFld(const String &name)
Add a keyword or replace a keyword with the value of another keyword.
Int64 evalIntScaExpr(const TableExprNode &expr) const
Evaluate an int scalar expression.
void makeTableNoFrom(const std::vector< TableParseSelect * > &stack)
Create a temporary table if no tables are given in FROM.
static TableExprNode handleSlice(const TableExprNode &array, const TableExprNodeSet &indices, const TaQLStyle &)
Handle a slice operator.
void handleLimit(const TableExprNodeSetElem &expr)
Evaluate and keep limit/offset/stride given as start:end:incr.
Table doLimOff(Bool showTimings, const Table &table)
void checkTableProjSizes() const
Check if the tables used in selection columns have the same size as the first table given in FROM.
Table doCount(Bool showTimings, const Table &)
Do the count step returning a memory table containing the unique column values and the counts of the ...
Int testGroupAggr(std::vector< TableExprNodeRep * > &aggr) const
Test if groupby or aggregate functions are given.
void handleCalcComm(const TableExprNode &)
Keep the expression of a calculate command.
void doLimOff(Bool showTimings)
Do the limit/offset step.
void handleLimit(const TableExprNode &expr)
Evaluate and keep the limit value.
Table doDistinct(Bool showTimings, const Table &table)
Do the 'select distinct' step.
void handleInsert(TableParseSelect *sel)
void makeProjectExprTable()
Make the (empty) table for the epxression in the SELECT clause.
void handleAddRow(const TableExprNode &expr)
Evaluate and add the rows.
StorageOption storageOption_p
void handleUpdate()
Keep the update expressions.
void addApplySelNode(const TableExprNode &node)
Add a column node to applySelNodes_p.
Table doFromQuery(Bool showTimings)
Execute a query in a from clause resulting in a Table.
void handleCount()
Make ready for a COUNT command.
Block< TableRecord > columnKeywords_p
void handleInsert()
Make ready for the insert expression.
void checkMaskColumn(Bool hasMask, const ArrayColumn< Bool > &maskCol, const TableColumn &col)
void handleSort(const std::vector< TableParseSort > &sortList, Bool noDuplicates, Sort::Order defaultSortOrder)
Keep the sort expressions.
Table doProjectExpr(Bool useSel, const CountedPtr< TableExprGroupResult > &groups)
Do the projection containing column expressions.
Block< String > columnNames_p
Block< uInt > projectExprSubset_p
void handleGroupby(const std::vector< TableExprNode > &, Bool rollup)
Keep the groupby expressions.
void handleCopyCol(Bool showTimings)
Handle copying of columns.
void makeProjectExprSel()
Fill projectExprSelColumn_p telling the columns to be projected at the first stage.
CountedPtr< TableExprGroupResult > doOnlyCountAll(TableExprNodeRep *aggrNode)
Do a groupby/aggregate step that only does a 'select count(*)'.
Table createTable(const TableDesc &td, Int64 nrow, const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Create a table using the given parameters.
void handleRemoveKey(const String &name)
Remove a table or column keyword.
CountedPtr< TableExprGroupResult > doGroupby(bool showTimings, const std::vector< TableExprNodeRep * > aggrNodes, Int groupAggrUsed)
Do the groupby/aggregate step and return its result.
TableExprNode handleFunc(const String &name, const TableExprNodeSet &arguments, const TaQLStyle &)
Handle a function.
std::vector< TableParse > fromTables_p
void updateValue(rownr_t row, const TableExprId &rowid, Bool isScalarCol, const TableExprNode &node, const Array< Bool > &mask, Bool maskFirst, TableColumn &col, const Slicer *slicerPtr, ArrayColumn< Bool > &maskCol)
Update the values in the columns (helpers of doUpdate).
Block< String > columnNameMasks_p
std::vector< CountedPtr< TableExprGroupFuncSet > > doGroupByAggrMultipleKeys(const std::vector< TableExprNodeRep * > &aggrNodes)
Create the set of aggregate functions and groupby keys in case multiple keys are given.
TableExprNode havingNode_p
std::vector< TableExprNode > applySelNodes_p
Block< String > columnDtypes_p
Table adjustApplySelNodes(const Table &)
Set the selected rows for the column objects in applySelNodes_p.
void handleOffset(const TableExprNode &expr)
Evaluate and keep the offset value.
Vector< rownr_t > rownrs_p
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 replaceTable(const Table &table)
Replace the first table (used by CALC command).
TableExprNode getColSet()
Make an array from the contents of a column in a subquery.
Table doProject(Bool showTimings, const Table &, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >())
Do the projection step returning a table containing the projection.
Table doFinish(Bool showTimings, Table &table, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Finish the table (rename, copy, and/or flush).
CountedPtr< TableExprGroupResult > doGroupByAggr(const std::vector< TableExprNodeRep * > &aggrNodes)
Do a full groupby/aggregate step.
TableParseSelect * insSel_p
void copyMaskedValue(rownr_t row, ArrayColumn< TCOL > &acol, const Slicer *slicerPtr, const TNODE *val, size_t incr, const Array< Bool > &mask)
Table findTable(const String &shorthand, Bool doWith, const std::vector< TableParseSelect * > &stack) const
std::pair< ColumnDesc, Record > findColumnInfo(const String &colName, const String &newColName) const
Find the ColumnDesc and data manager info of another column (a LIKE column).
void handleDropTab(const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Handle the DROP TABLE command.
TableRecord & findKeyword(const String &name, String &keyName, Bool update=True)
Split the given name into optional shorthand, column and fields.
Table addTable(Int tabnr, const String &name, const Table &table, const String &shorthand, Bool addToFromList, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Add a table nr, name, or object to the container.
void doDelete(Bool showTimings, Table &table)
Do the delete step.
TableExprNodeSet * resultSet_p
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.
Table doInsert(Bool showTimings, Table &table)
Do the insert step and return a selection containing the new rows.
void handleRenameKey(const String &oldName, const String &newName)
Rename a table or column keyword.
static TableExprFuncNode::FunctionType findFunc(const String &name, uInt narguments, const Vector< Int > &ignoreFuncs)
Find the function code belonging to a function name.
void handleAltTab()
Reopen the table (for update) used in the ALTER TABLE command.
TableParseSelect(CommandType type)
Construct.
static void checkAggrFuncs(const TableExprNode &node)
An exception is thrown if the node uses an aggregate function.
std::vector< TableExprNode > groupbyNodes_p
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< TableParseSelect * > &stack=std::vector< TableParseSelect * >())
Execute the select command (select/sort/projection/groupby/having/giving).
static String getTypeString(const String &typeStr, DataType type)
Get the type string.
std::vector< CountedPtr< TableParseUpdate > > update_p
void doSort(Bool showTimings)
Do the sort step.
Helper class for sort keys in TableParse.
Bool orderGiven() const
Is the order given?
TableParseSort(const TableExprNode &, Sort::Order)
Construct from a given expression and for the given order.
TableParseSort()
Construct from a given expression.
void checkNode() const
Check if the node results in a scalar and does not contain aggregate functions.
TableParseSort(const TableExprNode &)
Construct from a given expression.
Sort::Order order() const
Get the sort order.
const TableExprNode & node() const
Get the expression node.
Helper class for updates in TableParse.
const String & columnNameMask() const
Get the possible column name for the mask.
TableParseUpdate(const String &columnName, const String &columnNameMask, const TableExprNodeSet &indices, const TableExprNode &, const TaQLStyle &)
Construct from a column name, subscripts or mask, and expression.
const TableExprNode & node() const
Get the expression node.
void adaptUnit(const Unit &columnUnit)
Adapt the possible unit of the expression to the possible unit of the column.
TableExprNode indexNode_p
const TableExprNode & indexNode() const
Get the index expression node.
TableParseUpdate(const String &columnName, const String &columnNameMask, const TableExprNode &, Bool checkAggr=True)
Construct from a column name and expression.
Bool maskFirst() const
Tell if the mask is given first (i.e., before slice).
void setColumnName(const String &name)
Set the column name.
const TableExprNode & mask() const
Get the mask.
TableExprNodeIndex * indexPtr_p
const String & columnName() const
Get the column name.
void handleIndices(const TableExprNodeSet &indices, const TaQLStyle &style)
Handle the subscripts or mask.
TableExprNodeIndex * indexPtr() const
Get the pointer to the indices.
TableParseUpdate(const String &columnName, const String &columnNameMask, const TableExprNodeSet &indices1, const TableExprNodeSet &indices2, const TableExprNode &, const TaQLStyle &)
Construct from a column name, subscripts and mask, and expression.
void setColumnNameMask(const String &name)
Set the column name forthe mask.
TableParse()
Default constructor for container class.
Int tabnr() const
Get the given table number (of $i tables in TempTables)
const String & name() const
Get the given table name.
TableParse(const Table &table, Int tabnr, const String &name, const String &shorthand)
Associate the table and the shorthand.
Bool test(const String &shortHand) const
Test if shorthand matches.
const Table & table() const
Get table object.
const String & shorthand() const
Get the shorthand.
void replaceTable(const Table &)
Replace the Table object.
EndianFormat
Define the possible endian formats in which table data can be stored.
this file contains all the compiler specific defines
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
TaQLResult tableCommand(const String &command)
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
bool Bool
Define the standard types used by Casacore.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
uInt64 rownr_t
Define the type of a row number in a table.