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