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
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
39class TaQLStyle;
40class TableExprId;
41class TableColumn;
42template <class T>
43class ArrayColumn;
44
45// <summary>
46// Manage TaQL UPDATE command handling
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
52// </reviewed>
53
54// <synopsis>
55// TableParseUpdate holds the column name, optional indices, optional mask,
56// and new value expression of a column to be updated.
57// Furthermore, it has functions to perform updates in the column and possibly
58// mask column using the expression and possible slice.
59// </synopsis>
60
62 public:
64
65 // Construct from a column name and expression.
66 // By default it checks if no aggregate functions are used.
68 Bool checkAggr = True);
69
70 // Construct from a column name, subscripts or mask, and expression.
71 // It checks if no aggregate functions are used.
73 const TableExprNodeSet& indices, const TableExprNode&, const TaQLStyle&);
74
75 // Construct from a column name, subscripts and mask, and expression.
76 // It checks if no aggregate functions are used.
77 // It checks if one of the indices represents subscripts, the other a mask.
79 const TableExprNodeSet& indices1, const TableExprNodeSet& indices2,
80 const TableExprNode&, const TaQLStyle&);
81
82 // Handle the subscripts or mask.
83 // It checks if subscripts or mask is not already used.
84 void handleIndices(const TableExprNodeSet& indices, const TaQLStyle& style);
85
86 // Set the node expression (used by TableParseQuery::doInsert).
87 void setNode(const TableExprNode& node) { node_p = node; }
88
89 // Set the column name.
91
92 // Set the column name for the mask.
94
95 // Get the column name.
96 const String& columnName() const { return columnName_p; }
97
98 // Get the possible column name for the mask.
99 const String& columnNameMask() const { return columnNameMask_p; }
100
101 // Adapt the possible unit of the expression to the possible unit
102 // of the column.
103 void adaptUnit(const Unit& columnUnit) { node_p.adaptUnit(columnUnit); }
104
105 // Check if the update column and expression specifications match.
106 // Also check if the number of rows is correct.
107 void check(const Table& origTable, const Table& updTable) const;
108
109 // Update the values in the column with the values of the node_p expression.
110 // The column can contain scalars of arrays. Possible only array slices
111 // are updated.
112 // The mask column values are also updated if a mask is used.
114 const TableExprId& rowid);
115
116 private:
117 // Update the values in the columns (helpers of updateColumn).
118 // It converts the data type of the expression to that opf the column.
119 // <group>
120 template <typename TCOL, typename TNODE>
121 void updateValue(rownr_t row, const TableExprId& rowid, Bool isScalarCol,
122 const TableExprNode& node, const Array<Bool>& mask, TableColumn& col,
123 const Slicer* slicerPtr, ArrayColumn<Bool>& maskCol);
124 template <typename TCOL, typename TNODE>
125 void updateScalar(rownr_t row, const TableExprId& rowid, const TableExprNode& node,
126 TableColumn& col);
127 template <typename TCOL, typename TNODE>
128 void updateArray(rownr_t row, const TableExprId& rowid, const TableExprNode& node,
129 const Array<TNODE>& res, ArrayColumn<TCOL>& col);
130 template <typename TCOL, typename TNODE>
131 void updateSlice(rownr_t row, const TableExprId& rowid, const TableExprNode& node,
132 const Array<TNODE>& res, const Slicer& slice, ArrayColumn<TCOL>& col);
133 template <typename TCOL, typename TNODE>
134 void copyMaskedValue(rownr_t row, ArrayColumn<TCOL>& acol, const Slicer* slicerPtr,
135 const TNODE* val, size_t incr, const Array<Bool>& mask);
137 const Slicer* slicerPtr);
138 void checkMaskColumn(Bool hasMask, const ArrayColumn<Bool>& maskCol, const TableColumn& col);
139 // </group>
140
141 // # Data members
144 Bool maskFirst_p; // # True = mask is given before slice
145 TableExprNodeIndex* indexPtr_p; // # copy of pointer in indexNode_p; no need to delete
149};
150
151} // namespace casacore
152
153#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
The index of an array element in a table select expression.
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)
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
String name() const
Return the name of the field.
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