casacore
Loading...
Searching...
No Matches
TableParseJoin.h
Go to the documentation of this file.
1// # TableParseJoin.h: Class handling the join clause
2// # Copyright (C) 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_TABLEPARSEJOIN_H
27#define TABLES_TABLEPARSEJOIN_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/ExprNodeRep.h>
32#include <casacore/tables/TaQL/TaQLJoin.h>
33#include <vector>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward declarations.
38class TableParse;
39class TableParseQuery;
40class TableExprNode;
41class Table;
42
43// <summary>
44// Class handling a join clause in a TaQL command
45// </summary>
46
47// <use visibility=local>
48
49// <reviewed reviewer="Tammo Jan Dijkema" date="2022/12/15" tests="tTableGramJoin">
50// </reviewed>
51
52// <synopsis>
53// TableParseQuery holds a vector of TableParseJoin objects, one for each
54// join clause in a TaQL command.
55// <br>TableParseJoin holds the join condition expression and the from and
56// join tables involved in the expression. The from tables are all tables in
57// the TaQL command prior to this join clause. The join tables are the tables
58// mentioned in the join clause.
59// TableParseJoin also tells if the join is nested in another join by keeping
60// the index of the parent TableParseJoin object in the vector in TableParseQuery.
61//
62// The ON condition expression is split in its AND parts; basically each part
63// involves a column comparison. Each part must contain an = for an exact match
64// or IN comparison for matching an interval.
65// A tree, consisting of TaQLJoinBase objects, is built to execute the condition.
66// It finds the matching row in the join table given a row in the main table.
67// Each level in the tree is an AND part in the condition.
68// </synopsis>
69
71 public:
73
74 // Add a join table nr, name, or object to the container.
75 void addTable(Int tabnr, const String& name, const Table& table, const String& shorthand,
76 const std::vector<const Table*>& tempTables,
77 const std::vector<TableParseQuery*>& stack);
78
79 // Handle the ON condition of a join.
80 void handleCondition(const TableExprNode& expr);
81
82 // Find the row in the join table for the given main table row.
83 // # In the initialization phase of TaQLJoin, the itsJoin pointer
84 // # is not set. In that case the given row id is already the original
85 // # rownr in the join table and should be returned as such.
86 Int64 findRow(const TableExprId& id) const;
87
88 private:
89 // Split the ON condition recursively into its AND parts.
90 void splitAnd(const TENShPtr& node, std::vector<TENShPtr>& parts);
91
92 // Handle all AND parts of the join condition.
93 void handleConditionParts(std::vector<TENShPtr>& parts);
94
95 // Tell how many tables in the exprTables vector are the same as those
96 // in the tables vector.
97 uInt findMatchingTables(const std::vector<Table>& exprTables,
98 const std::vector<Table>& tables) const;
99
100 // Check if all join tables in the vector have the same number of rows.
101 rownr_t checkNrow(const std::vector<Table>&) const;
102
103 // Add the tables in the other vector to the tables vector.
104 // Only do that for tables not occurring in the tables vector yet.
105 void addUniqueTables(std::vector<Table>& tables, const std::vector<Table>& other);
106
107 // # Data members.
109 std::vector<Table> itsFromTables;
110 std::vector<Table> itsJoinTables;
111 // # Index in TableParseQuery's vector of joins; <0 is no parent join.
113 std::shared_ptr<TaQLJoinBase> itsJoin;
114 mutable Int64 itsLastMainRow; // Last main table row looked for
115 mutable Int64 itsLastJoinRow; // Join table row matching itsLastMainRow
116};
117
118} // namespace casacore
119
120#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
std::vector< Table > itsJoinTables
Int64 findRow(const TableExprId &id) const
Find the row in the join table for the given main table row.
uInt findMatchingTables(const std::vector< Table > &exprTables, const std::vector< Table > &tables) const
Tell how many tables in the exprTables vector are the same as those in the tables vector.
rownr_t checkNrow(const std::vector< Table > &) const
Check if all join tables in the vector have the same number of rows.
void splitAnd(const TENShPtr &node, std::vector< TENShPtr > &parts)
Split the ON condition recursively into its AND parts.
std::vector< Table > itsFromTables
TableParseQuery * itsParent
void handleCondition(const TableExprNode &expr)
Handle the ON condition of a join.
void handleConditionParts(std::vector< TENShPtr > &parts)
Handle all AND parts of the join condition.
void addUniqueTables(std::vector< Table > &tables, const std::vector< Table > &other)
Add the tables in the other vector to the tables vector.
TableParseJoin(TableParseQuery *)
void addTable(Int tabnr, const String &name, const Table &table, const String &shorthand, const std::vector< const Table * > &tempTables, const std::vector< TableParseQuery * > &stack)
Add a join table nr, name, or object to the container.
std::shared_ptr< TaQLJoinBase > itsJoin
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
String name() const
Return the name of the field.
std::shared_ptr< TableExprNodeRep > TENShPtr
Definition ExprNodeRep.h:56
int Int
Definition aipstype.h:48
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44