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
42 class TableParseUpdate;
43 class TableExprGroupResult;
44
45
46 // <summary>
47 // Class holding the info of a TaQL projection command
48 // </summary>
49
50 // <use visibility=local>
51
52 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
53 // </reviewed>
54
55 // <synopsis>
56 // Table projection is the selection of columns in a TaQL command.
57 // This class gets the results of the parser of all columns in the projection.
58 // Those results are column name, new name, data type and expression.
59 // Furthermore, it holds info which projected columns are used in other
60 // parts of a TaQL command (HAVING and ORDERBY).
61 // Once the TaQL is fully parsed and all parameters are stored, it is executed.
62 // This class creates the table description and data manager info and finally
63 // creates the resulting table. First projected columns used in other parts
64 // are filled. After a possible HAVING clause and ORDERBY clause is executed,
65 // the remaining columns are filled.
66 // </synopsis>
67
69 {
70 public:
71 // Constructor fills a reference to the tableList objkect.
73
74 // Get access to the datamanager info.
76 { return dminfo_p; }
77
78 // Get the table description.
79 const TableDesc& tableDesc() const
80 { return *tableDesc_p; }
81
82 // Get the projected column names.
84 { return columnNames_p; }
85
86 // Get the projected column expressions.
88 { return columnExpr_p; }
89
90 // Are expressions used in the column projection?
92 { return nrSelExprUsed_p > 0; }
93
94 // Return the number of projected columns used in other clauses such as HAVING
95 // which need to be precalculated.
97 { return projectExprSubset_p.size(); }
98
99 // Set the column names to the ones to be updated.
100 void setColumnNames (const std::vector<std::shared_ptr<TableParseUpdate>>&);
101
102 // Put the column name and mask name into the update objects.
103 void setUpdateNames (std::vector<std::shared_ptr<TableParseUpdate>>&);
104
105 // Set the names to the stored columns of the first table.
106 // Resize columnNameMasks_p accordingly.
108
109 // Add a column to the list of column names.
110 void handleColumn (Int stringType,
111 const String& name,
112 const TableExprNode& expr,
113 const String& newName,
114 const String& newNameMask,
115 const String& newDtype,
117
118 // Handle the selection of a wildcarded column name.
119 void handleWildColumn (Int stringType, const String& name);
120
121 // Finish the additions to the block of column names
122 // by removing the deleted empty names and creating Expr objects as needed.
123 // An exception is thrown if there is a resultset and if columns are selected.
125
126 // Keep the column specification in a create table command.
127 void handleColSpec (const String& columnName, const String& likeColName,
128 const String& dataType,
129 const Record& spec, Bool isCOrder);
130
131 // Add columns to the table of ALTER TABLE.
132 // The column descriptions have already been added to tableDesc_p.
133 void handleAddCol (const Record& dmInfo, Table&);
134
135 // Initialize the table and data manager descriptions.
136 void initDescriptions (const TableDesc& desc, const Record& dminfo);
137
138 // Set the DataManager info for a new table.
139 void setDMInfo (const Record& dminfo)
140 { dminfo_p = dminfo;}
141
142 // Find the keyword or column name and create a TableExprNode from it.
143 // If <src>tryProj=True</src> it is first tried if the column is a coluymn
144 // in the projected table (i.e., result from the SELECT part).
145 TableExprNode handleKeyCol (const String& name, Bool tryProj,
147
148 // Make the table projection using the selected columns.
149 // The columns in the resulting table are renamed if a new name was given.
150 Table project (const Table& tab);
151
152 // Create TableParseUpdate objects for the selected column expressions.
153 void makeUpdate (Bool useSel, TableParseQuery& tpq);
154
155 // Fill projectExprSelColumn_p telling the columns to be projected
156 // at the first stage.
158
159 // Check if the tables used in selection columns have the same
160 // size as the first table given in FROM.
162
163 // Add possible aggregation functions used in projection to the vector.
164 void getAggrNodes (std::vector<TableExprNodeRep*>& aggr) const;
165
166 // Check if the COUNT columns are given correctly.
167 void checkCountColumns() const;
168
169 private:
170 // Make the (empty) table for the expression in the SELECT clause.
172
173 // Make a data type from the string.
174 // It checks if it is compatible with the given (expression) data type.
175 DataType makeDataType (DataType dtype, const String& dtstr,
176 const String& colName);
177
178 // Add the description of a column to the table description.
179 // ndim < 0 means a scalar column.
180 void addColumnDesc (TableDesc& td, DataType dtype,
181 const String& colName, Int options,
182 Int ndim, const IPosition& shape,
183 const String& dmType, const String& dmGroup,
184 const String& comment,
185 const TableRecord& keywordSet,
186 const Vector<String>& unitName,
187 const Record& attributes);
188
189 // Find the ColumnDesc and data manager info of another column (a LIKE column).
190 // The LIKE column name can be qualified to use another table.
191 // It sets the new column name in the data manager info.
192 // An exception is thrown if colName is invalid or unknown.
193 std::pair<ColumnDesc,Record> findColumnInfo (const String& colName,
194 const String& newColName) const;
195
196 //# Data members.
198 //# Table and data manager description for a series of column descriptions.
199 //# TableDesc has no copy ctor, so use a shared_ptr.
200 std::shared_ptr<TableDesc> tableDesc_p;
202 //# Block of selected column names (new name in case of select).
204 //# Block of selected mask column names (for masked arrays).
206 //# Block of selected column expressions.
208 //# The old name for a selected column.
210 //# The new data type for a column.
212 //# The keywords used in a column.
214 //# Number of real expressions used in selected columns.
216 //# The projected columns used in the HAVING and ORDERBY clauses.
219 //# The first table used when creating a column object.
220 //# All other tables used for them should have the same size.
223 };
224
225
226} //# NAMESPACE CASACORE - END
227
228#endif
simple 1-D array
Definition Block.h:198
size_t size() const
Definition Block.h:610
String: the storage and methods of handling collections of characters.
Definition String.h:223
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.
this file contains all the compiler specific defines
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
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40