Go to the documentation of this file.
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/BasicSL/String.h>
39 #include <casacore/casa/Utilities/Sort.h>
40 #include <casacore/casa/Containers/Record.h>
41 #include <casacore/casa/Containers/Block.h>
49 class TableExprNodeSet;
50 class TableExprNodeSetElem;
51 class TableExprNodeIndex;
54 template<
class T>
class Vector;
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;
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).
void handleGiving(const String &name, const Record &type)
Handle the name and type given in a GIVING clause.
Define the structure of a Casacore table.
TableParseSort()
Construct from a given expression.
Specify which elements to extract from an n-dimensional array.
void makeProjectExprSel()
Fill projectExprSelColumn_p telling the columns to be projected at the first stage.
Array< Bool > makeMaskSlice(const Array< Bool > &mask, Bool maskFirst, const IPosition &shapeCol, const Slicer *slicerPtr)
The index of an array element in a table select expression.
const TableExprNode & mask() const
Get the mask.
const Block< String > & getColumnNames() const
Get the projected column names.
const Table & table() const
Get table object.
void handleCreTab(const Record &dmInfo)
Keep the create table command.
void handleColSpec(const String &columnName, const String &dataType, const Record &spec, Bool isCOrder=False)
Keep the column specification in a create table command.
void setRownr(uInt rownr)
Set the row number.
void checkNode() const
Check if the node results in a scalar and does not contain aggregate functions.
A Vector of integers, for indexing into Array<T> objects.
CountedPtr< TableExprGroupResult > doGroupby(bool showTimings, const std::vector< TableExprNodeRep * > aggrNodes, Int groupAggrUsed)
Do the groupby/aggregate step and return its result.
TableExprNode getColSet()
Make an array from the contents of a column in a subquery.
void updateValue(uInt 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).
static void checkAggrFuncs(const TableExprNode &node)
An exception is thrown if the node uses an aggregate function.
void copyMaskedValue(uInt row, ArrayColumn< TCOL > &acol, const Slicer *slicerPtr, const TNODE *val, uInt incr, const Array< Bool > &mask)
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.
CommandType commandType() const
Return the command type.
void handleCount()
Make ready for a COUNT command.
Bool maskFirst() const
Tell if the mask is given first (i.e., before slice).
void handleUpdate()
Keep the update expressions.
Block< uInt > projectExprSubset_p
EndianFormat
Define the possible endian formats in which table data can be stored.
Read/write access to a table column.
Block< String > columnDtypes_p
Block< TableRecord > columnKeywords_p
~TableParseSelect()
Destructor.
Bool test(const String &shortHand) const
Test if shorthand matches.
A hierarchical collection of named fields of various types.
Class to hold values from table grammar parser.
void makeProjectExprTable()
Make the (empty) table for the epxression in the SELECT clause.
Int testGroupAggr(std::vector< TableExprNodeRep * > &aggr) const
Test if groupby or aggregate functions are given.
Referenced counted pointer for constant data.
Sort::Order order() const
Get the sort order.
TableExprNode havingNode_p
TableParse(const TableParse &)
Copy constructor (copy semantics).
TableParseSelect * insSel_p
void doUpdate(Bool showTimings, const Table &origTable, Table &updTable, const Vector< uInt > &rownrs, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >())
Do the update step.
Order
Enumerate the sort order:
Block< String > columnNames_p
Block< TableExprNode > columnExpr_p
TableParseUpdate(const String &columnName, const String &columnNameMask, const TableExprNode &, Bool checkAggr=True)
Construct from a column name and expression.
Select-class for flex/bison scanner/parser for TableParse.
TableExprNode doExists(Bool noexists, Bool showTimings)
Test if a subquery has sufficient elements.
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
std::vector< CountedPtr< TableParseUpdate > > update_p
TableExprNode getNode() const
Return the expression node.
void doSort(Bool showTimings)
Do the sort step.
const String & columnNameMask() const
Get the possible column name for the mask.
void handleColumnFinish(Bool distinct)
Finish the addition of columns to the list of column names.
Helper class for sort keys in TableParse.
void handleHaving(const TableExprNode &)
Keep the having expression.
Table doProjectExpr(Bool useSel, const CountedPtr< TableExprGroupResult > &groups)
Do the projection containing column expressions.
TableExprNode handleFunc(const String &name, const TableExprNodeSet &arguments, const TaQLStyle &)
Handle a function.
Block< String > columnOldNames_p
TableParseSelect(CommandType type)
Construct.
Table doDistinct(Bool showTimings, const Table &table)
Do the 'select distinct' step.
TableParseUpdate(const String &columnName, const String &columnNameMask, const TableExprNodeSet &indices, const TableExprNode &, const TaQLStyle &)
Construct from a column name, subscripts or mask, and expression.
void addUpdate(const CountedPtr< TableParseUpdate > &upd)
Add an update object.
const String & columnName() const
Get the column name.
Class to hold the result of a TaQL command.
Block< String > getStoredColumns(const Table &tab) const
Find the names of all stored columns in a table.
void setInsertExprs(const std::vector< TableExprNode > exprs)
Set the insert expressions for all rows.
Table doFromQuery(Bool showTimings)
Execute a query in a from clause resulting in a Table.
void handleAltTab()
Reopen the table (for update) used in the ALTER TABLE command.
TableExprNode doSubQuery(Bool showTimings)
Execute a subquery and create an appropriate node for the result.
void handleAddRow(const TableExprNode &expr)
Evaluate and add the rows.
void addApplySelNode(const TableExprNode &node)
Add a column node to applySelNodes_p.
void handleOffset(const TableExprNode &expr)
Evaluate and keep the offset value.
void adaptUnit(const Unit &)
Adapt the unit of the expression to the given unit (if not empty).
void replaceTable(const Table &table)
Replace the first table (used by CALC command).
TableParse(const Table &table, const String &shorthand)
Associate the table and the shorthand.
const Table & getTable() const
Get the resulting table.
Bool orderGiven() const
Is the order given?
void checkMaskColumn(Bool hasMask, const ArrayColumn< Bool > &maskCol, const TableColumn &col)
Main interface class to a read/write table.
void doLimOff(Bool showTimings)
Do the limit/offset step.
TableExprNode makeSubSet() const
Make a set from the results of the subquery.
void setDMInfo(const Record &dminfo)
Set the DataManager info for a new table.
StorageOption storageOption_p
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
void handleWildColumn(Int stringType, const String &name)
Handle the selection of a wildcarded column name.
Int64 evalIntScaExpr(const TableExprNode &expr) const
Evaluate an int scalar expression.
const TableExprNode & indexNode() const
Get the index expression node.
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
vector< TableExprNode > groupbyNodes_p
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 handleWhere(const TableExprNode &)
Keep the selection expression.
void handleLimit(const TableExprNode &expr)
Evaluate and keep the limit value.
Helper class for updates in TableParse.
CountedPtr< TableExprGroupResult > doGroupByAggr(const std::vector< TableExprNodeRep * > &aggrNodes)
Do a full groupby/aggregate step.
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.
TableExprNode indexNode_p
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Table doCount(Bool showTimings, const Table &)
Do the count step returning a memory table containing the unique column values and the counts of the ...
TableExprNodeSet * resultSet_p
Table findTable(const String &shorthand, Bool doWith) const
Find a table for the given shorthand.
std::vector< TableParseSort > sort_p
CountedPtr< TableExprGroupResult > doOnlyCountAll(TableExprNodeRep *aggrNode)
Do a groupby/aggregate step that only does a 'select count(*)'.
void execute(Bool showTimings, Bool setInGiving, Bool mustSelect, uInt maxRow, Bool doTracing=False)
Execute the select command (select/sort/projection/groupby/having/giving).
CommandType commandType_p
std::vector< TableExprNode > insertExprs_p
Block< Bool > projectExprSelColumn_p
Table doLimOff(Bool showTimings, const Table &table)
void updateScalar(uInt row, const TableExprId &rowid, const TableExprNode &node, TableColumn &col)
void handleSort(const std::vector< TableParseSort > &sortList, Bool noDuplicates, Sort::Order defaultSortOrder)
Keep the sort expressions.
const TableExprNode & node() const
Get the expression node.
vector< TableParse > withTables_p
TableExprNodeIndex * indexPtr() const
Get the pointer to the indices.
this file contains all the compiler specific defines
void handleAddCol(const Record &dmInfo)
Add columns to the table of ALTER TABLE.
ValueHolder getRecFld(const String &name)
Add a keyword or replace a keyword with the value of another keyword.
static String getTypeString(const String &typeStr, DataType type)
Get the type string.
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.
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
TableParseSort(const TableExprNode &, Sort::Order)
Construct from a given expression and for the given order.
The identification of a TaQL selection subject.
Class to hold multiple table expression nodes.
void updateArray(uInt row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, ArrayColumn< TCOL > &col)
const String & shorthand() const
Get the shorthand.
DataType makeDataType(DataType dtype, const String &dtstr, const String &colName)
Make a data type from the string.
Table createTable(const TableDesc &td, Int64 nrow, const Record &dmInfo)
Create a table using the given parameters.
Table doProject(Bool showTimings, const Table &, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >())
Do the projection step returning a table containing the projection.
void setColumnNameMask(const String &name)
Set the column name forthe mask.
TableParse & operator=(const TableParse &)
Assignment (copy semantics).
void setColumnName(const String &name)
Set the column name.
Handle class for a table column expression tree.
void checkTableProjSizes() const
Check if the tables used in selection columns have the same size as the first table given in FROM.
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 handleInsert()
Make ready for the insert expression.
std::vector< CountedPtr< TableExprGroupFuncSet > > doGroupByAggrMultipleKeys(const vector< TableExprNodeRep * > &aggrNodes)
Create the set of aggregate functions and groupby keys in case multiple keys are given.
Class with static members defining the TaQL style.
TableParse()
Default constructor for container class.
static TableExprFuncNode::FunctionType findFunc(const String &name, uInt narguments, const Vector< Int > &ignoreFuncs)
Find the function code belonging to a function name.
TaQLResult tableCommand(const String &command)
TableExprNode handleKeyCol(const String &name, Bool tryProj)
Find the keyword or column name and create a TableExprNode from it.
Abstract base class for Record classes.
void handleRenameKey(const String &oldName, const String &newName)
Rename a table or column keyword.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
TableExprNodeIndex * indexPtr_p
void updateSlice(uInt row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, const Slicer &slice, ArrayColumn< TCOL > &col)
Abstract base class for a node in a table column expression tree.
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.
String: the storage and methods of handling collections of characters.
Class containing the results of aggregated values in a group.
bool Bool
Define the standard types used by Casacore.
A holder for a value of any basic Casacore data type.
static TableExprNode handleSlice(const TableExprNode &array, const TableExprNodeSet &indices, const TaQLStyle &)
Handle a slice operator.
Sort::Order getOrder(const TableParseSort &key) const
Get the order for this key.
A hierarchical collection of named fields of various types.
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.
void handleGroupby(const vector< TableExprNode > &, Bool rollup)
Keep the groupby expressions.
A 1-D Specialization of the Array class.
void handleInsert(TableParseSelect *sel)
void handleSetKey(const String &name, const String &dtype, const ValueHolder &value)
Add a keyword or replace a keyword with a value.
Block< String > columnNameMasks_p
void doHaving(Bool showTimings, const CountedPtr< TableExprGroupResult > &groups)
Do the HAVING step.
Options defining how table files are organized.
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.
TableParseSort(const TableExprNode &)
Construct from a given expression.
void doDelete(Bool showTimings, Table &table)
Do the delete step.
vector< TableExprNodeRep * > getAggrNodes() const
Get the aggregate functions used in SELECT and HAVING.
Table doFinish(Bool showTimings, Table &table)
Finish the table (rename, copy, and/or flush).
void handleGiving(const TableExprNodeSet &)
Handle the set given in a GIVING clause.
void handleCalcComm(const TableExprNode &)
Keep the expression of a calculate command.
Table adjustApplySelNodes(const Table &)
Set the selected rows for the column objects in applySelNodes_p.
Table::EndianFormat endianFormat_p
void handleLimit(const TableExprNodeSetElem &expr)
Evaluate and keep limit/offset/stride given as start:end:incr.
Class to hold the table expression nodes for an element in a set.
const TableExprNode & node() const
Get the expression node.
Table doInsert(Bool showTimings, Table &table)
Do the insert step and return a selection containing the new rows.
String getTableInfo(const Vector< String > &parts, const TaQLStyle &style)
Show the structure of fromTables_p[0] using the options given in parts[2:].
vector< TableExprNode > applySelNodes_p
void adaptUnit(const Unit &columnUnit)
Adapt the possible unit of the expression to the possible unit of the column.
void show(ostream &os) const
Show the expression tree.
void handleRemoveKey(const String &name)
Remove a table or column keyword.
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.
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.
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 ...
void makeTableNoFrom(const vector< TableParseSelect * > &stack)
Create a temporary table in no tables are given in FROM.
TableRecord & findKeyword(const String &name, String &keyName)
Split the given name into optional shorthand, column and fields.
vector< TableParse > fromTables_p
void handleIndices(const TableExprNodeSet &indices, const TaQLStyle &style)
Handle the subscripts or mask.