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.
38 class TableParse;
39 class TableParseQuery;
40 class TableExprNode;
41 class 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 {
72 public:
74
75 // Add a join table nr, name, or object to the container.
76 void addTable (Int tabnr, const String& name,
77 const Table& table,
78 const String& shorthand,
79 const std::vector<const Table*>& tempTables,
80 const std::vector<TableParseQuery*>& stack);
81
82 // Handle the ON condition of a join.
83 void handleCondition (const TableExprNode& expr);
84
85 // Find the row in the join table for the given main table row.
86 //# In the initialization phase of TaQLJoin, the itsJoin pointer
87 //# is not set. In that case the given row id is already the original
88 //# rownr in the join table and should be returned as such.
89 Int64 findRow (const TableExprId& id) const;
90
91 private:
92 // Split the ON condition recursively into its AND parts.
93 void splitAnd (const TENShPtr& node, std::vector<TENShPtr>& parts);
94
95 // Handle all AND parts of the join condition.
96 void handleConditionParts (std::vector<TENShPtr>& parts);
97
98 // Tell how many tables in the exprTables vector are the same as those
99 // in the tables vector.
100 uInt findMatchingTables (const std::vector<Table>& exprTables,
101 const std::vector<Table>& tables) const;
102
103 // Check if all join tables in the vector have the same number of rows.
104 rownr_t checkNrow (const std::vector<Table>&) const;
105
106 // Add the tables in the other vector to the tables vector.
107 // Only do that for tables not occurring in the tables vector yet.
108 void addUniqueTables (std::vector<Table>& tables,
109 const std::vector<Table>& other);
110
111 //# Data members.
113 std::vector<Table> itsFromTables;
114 std::vector<Table> itsJoinTables;
115 //# Index in TableParseQuery's vector of joins; <0 is no parent join.
117 std::shared_ptr<TaQLJoinBase> itsJoin;
118 mutable Int64 itsLastMainRow; // Last main table row looked for
119 mutable Int64 itsLastJoinRow; // Join table row matching itsLastMainRow
120 };
121
122} //# NAMESPACE CASACORE - END
123
124#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
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
this file contains all the compiler specific defines
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
std::shared_ptr< TableExprNodeRep > TENShPtr
Definition ExprNodeRep.h:55
int Int
Definition aipstype.h:48
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44