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;
154 const Table& tempTable);
156 const std::vector<const Table*>& tempTables);
163 const std::vector<const Table*>& tempTables,
166 const std::vector<const Table*>& tempTables,
524 void handleSort (
const std::vector<TableParseSort>& sortList,
544 const vector<const Table*> tempTables,
545 const vector<TableParseSelect*>& stack);
554 const vector<const Table*> tempTables,
555 const vector<TableParseSelect*>& stack,
706 (
bool showTimings,
const std::vector<TableExprNodeRep*> aggrNodes,
718 (
const std::vector<TableExprNodeRep*>& aggrNodes);
735 template<
typename TCOL,
typename TNODE>
741 template<
typename TCOL,
typename TNODE>
745 template<
typename TCOL,
typename TNODE>
750 template<
typename TCOL,
typename TNODE>
756 template<
typename TCOL,
typename TNODE>
806 const Record& attributes);
817 const vector<TableParseSelect*>& stack);
834 (
const vector<TableExprNodeRep*>& aggrNodes)
841 vector<CountedPtr<TableExprGroupFuncSet> > funcSets;
842 std::map<T, int> keyFuncMap;
852 if (key != lastKey) {
853 typename std::map<T, int>::iterator iter = keyFuncMap.find (key);
854 if (iter == keyFuncMap.end()) {
855 groupnr = funcSets.size();
856 keyFuncMap[key] = groupnr;
859 groupnr = iter->second;
863 funcSets[groupnr]->apply (rowid);
871 (
const vector<TableExprNodeRep*>& aggrNodes);
925 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.
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::vector< TableParseSort > sort_p
TableRecord & findKeyword(const String &name, String &keyName)
Split the given name into optional shorthand, column and fields.
void handleAddCol(const Record &dmInfo)
Add columns to the table of ALTER TABLE.
void execute(Bool showTimings, Bool setInGiving, Bool mustSelect, rownr_t maxRow, Bool doTracing=False)
Execute the select command (select/sort/projection/groupby/having/giving).
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 handleGroupby(const vector< TableExprNode > &, Bool rollup)
Keep the groupby expressions.
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.
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.
vector< TableExprNode > applySelNodes_p
void handleColSpec(const String &columnName, const String &dataType, const Record &spec, Bool isCOrder=False)
Keep the column specification in a create table command.
String getTableInfo(const Vector< String > &parts, const TaQLStyle &style)
Show the structure of fromTables_p[0] using the options given in parts[2:].
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.
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.
vector< TableParse > withTables_p
const Block< String > & getColumnNames() const
Get the projected column names.
vector< TableExprNode > groupbyNodes_p
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.
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 ...
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
void addTable(Int tabnr, const String &name, const Table &table, const String &shorthand, Bool addToFromList, const vector< const Table * > tempTables, const vector< TableParseSelect * > &stack)
Add a table nr, name, or object to the container.
TableExprNode handleKeyCol(const String &name, Bool tryProj)
Find the keyword or column name and create a TableExprNode from it.
void handleCreTab(const Record &dmInfo)
Keep the create table command.
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.
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.
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)
vector< TableParse > fromTables_p
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
Table doFinish(Bool showTimings, Table &table)
Finish the table (rename, copy, and/or flush).
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 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(*)'.
std::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.
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.
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
TableExprNode havingNode_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 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.
std::vector< CountedPtr< TableExprGroupFuncSet > > doGroupByAggrMultipleKeys(const vector< TableExprNodeRep * > &aggrNodes)
Create the set of aggregate functions and groupby keys in case multiple keys are given.
Table doProject(Bool showTimings, const Table &, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >())
Do the projection step returning a table containing the projection.
Table makeTable(Int tabnr, const String &name, const Table &ftab, const String &shorthand, const vector< const Table * > tempTables, const vector< TableParseSelect * > &stack, Bool alwaysOpen=True)
Make a Table object for given name, seqnr or so.
CountedPtr< TableExprGroupResult > doGroupByAggr(const std::vector< TableExprNodeRep * > &aggrNodes)
Do a full groupby/aggregate step.
TableParseSelect * insSel_p
Table createTable(const TableDesc &td, Int64 nrow, const Record &dmInfo)
Create a table using the given parameters.
void copyMaskedValue(rownr_t row, ArrayColumn< TCOL > &acol, const Slicer *slicerPtr, const TNODE *val, size_t incr, const Array< Bool > &mask)
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.
vector< TableExprNodeRep * > getAggrNodes() const
Get the aggregate functions used in SELECT and HAVING.
TableParseSelect(CommandType type)
Construct.
static void checkAggrFuncs(const TableExprNode &node)
An exception is thrown if the node uses an aggregate function.
static String getTypeString(const String &typeStr, DataType type)
Get the type string.
std::vector< CountedPtr< TableParseUpdate > > update_p
void makeTableNoFrom(const vector< TableParseSelect * > &stack)
Create a temporary table in no tables are given in FROM.
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.
TableParse & operator=(const TableParse &)
Assignment (copy semantics).
TableParse(const Table &table, const String &shorthand)
Associate the table and the shorthand.
Bool test(const String &shortHand) const
Test if shorthand matches.
TableParse(const TableParse &)
Copy constructor (copy semantics).
const Table & table() const
Get table object.
const String & shorthand() const
Get the shorthand.
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.