casacore
Loading...
Searching...
No Matches
TableParseProject.h
Go to the documentation of this file.
1// # TableParseProject.h: Class holding the info of a TaQL projection command
2// # Copyright (C) 1994-2022
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_TABLEPARSEPROJECT_H
27#define TABLES_TABLEPARSEPROJECT_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/TableParseTableList.h>
32#include <casacore/tables/TaQL/ExprNode.h>
33#include <casacore/tables/Tables/Table.h>
34#include <casacore/tables/Tables/TableDesc.h>
35#include <casacore/casa/Arrays/ArrayFwd.h>
36#include <casacore/casa/BasicSL/String.h>
37#include <casacore/casa/Containers/Record.h>
38
39namespace casacore { // # NAMESPACE CASACORE - BEGIN
40
41// # Forward Declarations
44
45// <summary>
46// Class holding the info of a TaQL projection command
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
52// </reviewed>
53
54// <synopsis>
55// Table projection is the selection of columns in a TaQL command.
56// This class gets the results of the parser of all columns in the projection.
57// Those results are column name, new name, data type and expression.
58// Furthermore, it holds info which projected columns are used in other
59// parts of a TaQL command (HAVING and ORDERBY).
60// Once the TaQL is fully parsed and all parameters are stored, it is executed.
61// This class creates the table description and data manager info and finally
62// creates the resulting table. First projected columns used in other parts
63// are filled. After a possible HAVING clause and ORDERBY clause is executed,
64// the remaining columns are filled.
65// </synopsis>
66
68 public:
69 // Constructor fills a reference to the tableList objkect.
71
72 // Get access to the datamanager info.
73 Record& dminfo() { return dminfo_p; }
74
75 // Get the table description.
76 const TableDesc& tableDesc() const { return *tableDesc_p; }
77
78 // Get the projected column names.
79 const Block<String>& getColumnNames() const { return columnNames_p; }
80
81 // Get the projected column expressions.
83
84 // Are expressions used in the column projection?
85 Bool hasExpressions() const { return nrSelExprUsed_p > 0; }
86
87 // Return the number of projected columns used in other clauses such as HAVING
88 // which need to be precalculated.
89 uInt nColumnsPreCalc() const { return projectExprSubset_p.size(); }
90
91 // Set the column names to the ones to be updated.
92 void setColumnNames(const std::vector<std::shared_ptr<TableParseUpdate>>&);
93
94 // Put the column name and mask name into the update objects.
95 void setUpdateNames(std::vector<std::shared_ptr<TableParseUpdate>>&);
96
97 // Set the names to the stored columns of the first table.
98 // Resize columnNameMasks_p accordingly.
100
101 // Add a column to the list of column names.
102 void handleColumn(Int stringType, const String& name, const TableExprNode& expr,
103 const String& newName, const String& newNameMask, const String& newDtype,
105
106 // Handle the selection of a wildcarded column name.
107 void handleWildColumn(Int stringType, const String& name);
108
109 // Finish the additions to the block of column names
110 // by removing the deleted empty names and creating Expr objects as needed.
111 // An exception is thrown if there is a resultset and if columns are selected.
113
114 // Keep the column specification in a create table command.
115 void handleColSpec(const String& columnName, const String& likeColName, const String& dataType,
116 const Record& spec, Bool isCOrder);
117
118 // Add columns to the table of ALTER TABLE.
119 // The column descriptions have already been added to tableDesc_p.
120 void handleAddCol(const Record& dmInfo, Table&);
121
122 // Initialize the table and data manager descriptions.
123 void initDescriptions(const TableDesc& desc, const Record& dminfo);
124
125 // Set the DataManager info for a new table.
127
128 // Find the keyword or column name and create a TableExprNode from it.
129 // If <src>tryProj=True</src> it is first tried if the column is a coluymn
130 // in the projected table (i.e., result from the SELECT part).
132
133 // Make the table projection using the selected columns.
134 // The columns in the resulting table are renamed if a new name was given.
135 Table project(const Table& tab);
136
137 // Create TableParseUpdate objects for the selected column expressions.
138 void makeUpdate(Bool useSel, TableParseQuery& tpq);
139
140 // Fill projectExprSelColumn_p telling the columns to be projected
141 // at the first stage.
143
144 // Check if the tables used in selection columns have the same
145 // size as the first table given in FROM.
147
148 // Add possible aggregation functions used in projection to the vector.
149 void getAggrNodes(std::vector<TableExprNodeRep*>& aggr) const;
150
151 // Check if the COUNT columns are given correctly.
152 void checkCountColumns() const;
153
154 private:
155 // Make the (empty) table for the expression in the SELECT clause.
157
158 // Make a data type from the string.
159 // It checks if it is compatible with the given (expression) data type.
160 DataType makeDataType(DataType dtype, const String& dtstr, const String& colName);
161
162 // Add the description of a column to the table description.
163 // ndim < 0 means a scalar column.
164 void addColumnDesc(TableDesc& td, DataType dtype, const String& colName, Int options, Int ndim,
165 const IPosition& shape, const String& dmType, const String& dmGroup,
166 const String& comment, const TableRecord& keywordSet,
167 const Vector<String>& unitName, const Record& attributes);
168
169 // Find the ColumnDesc and data manager info of another column (a LIKE column).
170 // The LIKE column name can be qualified to use another table.
171 // It sets the new column name in the data manager info.
172 // An exception is thrown if colName is invalid or unknown.
173 std::pair<ColumnDesc, Record> findColumnInfo(const String& colName,
174 const String& newColName) const;
175
176 // # Data members.
178 // # Table and data manager description for a series of column descriptions.
179 // # TableDesc has no copy ctor, so use a shared_ptr.
180 std::shared_ptr<TableDesc> tableDesc_p;
182 // # Block of selected column names (new name in case of select).
184 // # Block of selected mask column names (for masked arrays).
186 // # Block of selected column expressions.
188 // # The old name for a selected column.
190 // # The new data type for a column.
192 // # The keywords used in a column.
194 // # Number of real expressions used in selected columns.
196 // # The projected columns used in the HAVING and ORDERBY clauses.
199 // # The first table used when creating a column object.
200 // # All other tables used for them should have the same size.
203};
204
205} // namespace casacore
206
207#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
Class holding the results of groupby and aggregation.
Definition ExprGroup.h:129
uInt nColumnsPreCalc() const
Return the number of projected columns used in other clauses such as HAVING which need to be precalcu...
const TableDesc & tableDesc() const
Get the table description.
void setStoredColumns()
Set the names to the stored columns of the first table.
Table handleColumnFinish(Bool distinct, Bool hasResultSet, TableParseQuery &)
Finish the additions to the block of column names by removing the deleted empty names and creating Ex...
Table makeProjectExprTable(TableParseQuery &)
Make the (empty) table for the expression in the SELECT clause.
void setUpdateNames(std::vector< std::shared_ptr< TableParseUpdate > > &)
Put the column name and mask name into the update objects.
void setColumnNames(const std::vector< std::shared_ptr< TableParseUpdate > > &)
Set the column names to the ones to be updated.
void makeProjectExprSel()
Fill projectExprSelColumn_p telling the columns to be projected at the first stage.
TableExprNode handleKeyCol(const String &name, Bool tryProj, TableParseQuery &)
Find the keyword or column name and create a TableExprNode from it.
Record & dminfo()
Get access to the datamanager info.
std::shared_ptr< TableDesc > tableDesc_p
Bool hasExpressions() const
Are expressions used in the column projection?
void handleColSpec(const String &columnName, const String &likeColName, const String &dataType, const Record &spec, Bool isCOrder)
Keep the column specification in a create table command.
DataType makeDataType(DataType dtype, const String &dtstr, const String &colName)
Make a data type from the string.
void checkTableProjSizes() const
Check if the tables used in selection columns have the same size as the first table given in FROM.
void setDMInfo(const Record &dminfo)
Set the DataManager info for a new table.
void checkCountColumns() const
Check if the COUNT columns are given correctly.
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 handleWildColumn(Int stringType, const String &name)
Handle the selection of a wildcarded column name.
Block< TableExprNode > columnExpr_p
const Block< String > & getColumnNames() const
Get the projected column names.
void initDescriptions(const TableDesc &desc, const Record &dminfo)
Initialize the table and data manager descriptions.
TableParseProject(const TableParseTableList &tableList)
Constructor fills a reference to the tableList objkect.
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.
Block< TableRecord > columnKeywords_p
void makeUpdate(Bool useSel, TableParseQuery &tpq)
Create TableParseUpdate objects for the selected column expressions.
const Block< TableExprNode > & getColumnExpr() const
Get the projected column expressions.
void handleAddCol(const Record &dmInfo, Table &)
Add columns to the table of ALTER TABLE.
Table project(const Table &tab)
Make the table projection using the selected columns.
const TableParseTableList & tableList_p
void handleColumn(Int stringType, const String &name, const TableExprNode &expr, const String &newName, const String &newNameMask, const String &newDtype, TableParseQuery &)
Add a column to the list of column names.
void getAggrNodes(std::vector< TableExprNodeRep * > &aggr) const
Add possible aggregation functions used in projection to the vector.
Class containing two lists of TableParsePair objects.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
unsigned int uInt
Definition aipstype.h:49
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
String name() const
Return the name of the field.
const String & comment(const RecordFieldId &) const override
Get the comment for this field.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
DataType dataType(const RecordFieldId &) const