casacore
Loading...
Searching...
No Matches
TableParseUpdate.h
Go to the documentation of this file.
1//# TableParseUpdate.h: Class to manage TaQL UPDATE command handling
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_TABLEPARSEUPDATE_H
27#define TABLES_TABLEPARSEUPDATE_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/ExprNode.h>
32#include <casacore/casa/BasicSL/String.h>
33
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37 //# Forward Declarations
38 class TableExprNodeSet;
39 class TableExprNodeIndex;
40 class TaQLStyle;
41 class TableExprId;
42 class TableColumn;
43 template<class T> class ArrayColumn;
44
45
46 // <summary>
47 // Manage TaQL UPDATE command handling
48 // </summary>
49
50 // <use visibility=local>
51
52 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
53 // </reviewed>
54
55 // <synopsis>
56 // TableParseUpdate holds the column name, optional indices, optional mask,
57 // and new value expression of a column to be updated.
58 // Furthermore, it has functions to perform updates in the column and possibly
59 // mask column using the expression and possible slice.
60 // </synopsis>
61
63 {
64 public:
68
69 // Construct from a column name and expression.
70 // By default it checks if no aggregate functions are used.
73 const TableExprNode&,
74 Bool checkAggr=True);
75
76 // Construct from a column name, subscripts or mask, and expression.
77 // It checks if no aggregate functions are used.
80 const TableExprNodeSet& indices,
81 const TableExprNode&,
82 const TaQLStyle&);
83
84 // Construct from a column name, subscripts and mask, and expression.
85 // It checks if no aggregate functions are used.
86 // It checks if one of the indices represents subscripts, the other a mask.
89 const TableExprNodeSet& indices1,
90 const TableExprNodeSet& indices2,
91 const TableExprNode&,
92 const TaQLStyle&);
93
94 // Handle the subscripts or mask.
95 // It checks if subscripts or mask is not already used.
96 void handleIndices (const TableExprNodeSet& indices,
97 const TaQLStyle& style);
98
99 // Set the node expression (used by TableParseQuery::doInsert).
100 void setNode (const TableExprNode& node)
101 { node_p = node; }
102
103 // Set the column name.
104 void setColumnName (const String& name)
105 { columnName_p = name; }
106
107 // Set the column name for the mask.
108 void setColumnNameMask (const String& name)
109 { columnNameMask_p = name; }
110
111 // Get the column name.
112 const String& columnName() const
113 { return columnName_p; }
114
115 // Get the possible column name for the mask.
116 const String& columnNameMask() const
117 { return columnNameMask_p; }
118
119 // Adapt the possible unit of the expression to the possible unit
120 // of the column.
121 void adaptUnit (const Unit& columnUnit)
122 { node_p.adaptUnit (columnUnit); }
123
124 // Check if the update column and expression specifications match.
125 // Also check if the number of rows is correct.
126 void check (const Table& origTable, const Table& updTable) const;
127
128 // Update the values in the column with the values of the node_p expression.
129 // The column can contain scalars of arrays. Possible only array slices
130 // are updated.
131 // The mask column values are also updated if a mask is used.
133 rownr_t row, const TableExprId& rowid);
134
135 private:
136 // Update the values in the columns (helpers of updateColumn).
137 // It converts the data type of the expression to that opf the column.
138 // <group>
139 template<typename TCOL, typename TNODE>
140 void updateValue (rownr_t row, const TableExprId& rowid,
141 Bool isScalarCol, const TableExprNode& node,
142 const Array<Bool>& mask,
143 TableColumn& col, const Slicer* slicerPtr,
144 ArrayColumn<Bool>& maskCol);
145 template<typename TCOL, typename TNODE>
146 void updateScalar (rownr_t row, const TableExprId& rowid,
147 const TableExprNode& node,
148 TableColumn& col);
149 template<typename TCOL, typename TNODE>
150 void updateArray (rownr_t row, const TableExprId& rowid,
151 const TableExprNode& node,
152 const Array<TNODE>& res,
153 ArrayColumn<TCOL>& col);
154 template<typename TCOL, typename TNODE>
155 void updateSlice (rownr_t row, const TableExprId& rowid,
156 const TableExprNode& node,
157 const Array<TNODE>& res,
158 const Slicer& slice,
159 ArrayColumn<TCOL>& col);
160 template<typename TCOL, typename TNODE>
162 const Slicer* slicerPtr,
163 const TNODE* val,
164 size_t incr, const Array<Bool>& mask);
166 const IPosition& shapeCol,
167 const Slicer* slicerPtr);
168 void checkMaskColumn (Bool hasMask,
169 const ArrayColumn<Bool>& maskCol,
170 const TableColumn& col);
171 // </group>
172
173 //# Data members
176 Bool maskFirst_p; //# True = mask is given before slice
177 TableExprNodeIndex* indexPtr_p; //# copy of pointer in indexNode_p; no need to delete
181 };
182
183
184} //# NAMESPACE CASACORE - END
185
186#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
The index of an array element in a table select expression.
void adaptUnit(const Unit &)
Adapt the unit of the expression to the given unit (if not empty).
void checkMaskColumn(Bool hasMask, const ArrayColumn< Bool > &maskCol, const TableColumn &col)
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.
void setNode(const TableExprNode &node)
Set the node expression (used by TableParseQuery::doInsert).
void adaptUnit(const Unit &columnUnit)
Adapt the possible unit of the expression to the possible unit of the column.
void updateArray(rownr_t row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, ArrayColumn< TCOL > &col)
void check(const Table &origTable, const Table &updTable) const
Check if the update column and expression specifications match.
void updateColumn(TableColumn &col, ArrayColumn< Bool > &maskCol, rownr_t row, const TableExprId &rowid)
Update the values in the column with the values of the node_p expression.
TableParseUpdate(const String &columnName, const String &columnNameMask, const TableExprNode &, Bool checkAggr=True)
Construct from a column name and expression.
void updateSlice(rownr_t row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, const Slicer &slice, ArrayColumn< TCOL > &col)
void setColumnName(const String &name)
Set the column name.
Array< Bool > makeMaskSlice(const Array< Bool > &mask, const IPosition &shapeCol, const Slicer *slicerPtr)
void updateValue(rownr_t row, const TableExprId &rowid, Bool isScalarCol, const TableExprNode &node, const Array< Bool > &mask, TableColumn &col, const Slicer *slicerPtr, ArrayColumn< Bool > &maskCol)
Update the values in the columns (helpers of updateColumn).
TableExprNodeIndex * indexPtr_p
const String & columnName() const
Get the column name.
void updateScalar(rownr_t row, const TableExprId &rowid, const TableExprNode &node, TableColumn &col)
void handleIndices(const TableExprNodeSet &indices, const TaQLStyle &style)
Handle the subscripts or mask.
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 for the mask.
void copyMaskedValue(rownr_t row, ArrayColumn< TCOL > &acol, const Slicer *slicerPtr, const TNODE *val, size_t incr, const Array< Bool > &mask)
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44