OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RelAlgTranslator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef QUERYENGINE_RELALGTRANSLATOR_H
18 #define QUERYENGINE_RELALGTRANSLATOR_H
19 
20 #include "Execute.h"
21 #include "RelAlgDagBuilder.h"
22 
23 #include <ctime>
24 #include <memory>
25 #include <unordered_map>
26 #include <vector>
27 
28 namespace Analyzer {
29 
30 class Expr;
31 
32 } // namespace Analyzer
33 
34 namespace Catalog_Namespace {
35 
36 class Catalog;
37 class SessionInfo;
38 
39 } // namespace Catalog_Namespace
40 
41 namespace query_state {
42 
43 class QueryState;
44 
45 } // namespace query_state
46 
48  public:
50  std::shared_ptr<const query_state::QueryState> q_s,
51  const Executor* executor,
52  const std::unordered_map<const RelAlgNode*, int>& input_to_nest_level,
53  const std::vector<JoinType>& join_types,
54  const time_t now,
55  const bool just_explain)
56  : cat_(cat)
57  , query_state_(q_s)
58  , executor_(executor)
59  , input_to_nest_level_(input_to_nest_level)
60  , join_types_(join_types)
61  , now_(now)
63  , just_explain_(just_explain) {}
64 
65  std::shared_ptr<Analyzer::Expr> translateScalarRex(const RexScalar* rex) const;
66 
67  static std::shared_ptr<Analyzer::Expr> translateAggregateRex(
68  const RexAgg* rex,
69  const std::vector<std::shared_ptr<Analyzer::Expr>>& scalar_sources);
70 
71  static std::shared_ptr<Analyzer::Expr> translateLiteral(const RexLiteral*);
72 
74 
75  private:
76  std::shared_ptr<Analyzer::Expr> translateScalarSubquery(const RexSubQuery*) const;
77 
78  std::shared_ptr<Analyzer::Expr> translateInput(const RexInput*) const;
79 
80  std::shared_ptr<Analyzer::Expr> translateUoper(const RexOperator*) const;
81 
82  std::shared_ptr<Analyzer::Expr> translateInOper(const RexOperator*) const;
83 
84  std::shared_ptr<Analyzer::Expr> getInIntegerSetExpr(std::shared_ptr<Analyzer::Expr> arg,
85  const ResultSet& val_set) const;
86 
87  std::shared_ptr<Analyzer::Expr> translateOper(const RexOperator*) const;
88 
89  std::shared_ptr<Analyzer::Expr> translateOverlapsOper(const RexOperator*) const;
90 
91  std::shared_ptr<Analyzer::Expr> translateCase(const RexCase*) const;
92 
93  std::shared_ptr<Analyzer::Expr> translateLike(const RexFunctionOperator*) const;
94 
95  std::shared_ptr<Analyzer::Expr> translateRegexp(const RexFunctionOperator*) const;
96 
97  std::shared_ptr<Analyzer::Expr> translateLikely(const RexFunctionOperator*) const;
98 
99  std::shared_ptr<Analyzer::Expr> translateUnlikely(const RexFunctionOperator*) const;
100 
101  std::shared_ptr<Analyzer::Expr> translateExtract(const RexFunctionOperator*) const;
102 
103  std::shared_ptr<Analyzer::Expr> translateDateadd(const RexFunctionOperator*) const;
104 
105  std::shared_ptr<Analyzer::Expr> translateDatePlusMinus(const RexOperator*) const;
106 
107  std::shared_ptr<Analyzer::Expr> translateDatediff(const RexFunctionOperator*) const;
108 
109  std::shared_ptr<Analyzer::Expr> translateDatepart(const RexFunctionOperator*) const;
110 
111  std::shared_ptr<Analyzer::Expr> translateLength(const RexFunctionOperator*) const;
112 
113  std::shared_ptr<Analyzer::Expr> translateKeyForString(const RexFunctionOperator*) const;
114 
115  std::shared_ptr<Analyzer::Expr> translateSampleRatio(const RexFunctionOperator*) const;
116 
117  std::shared_ptr<Analyzer::Expr> translateCurrentUser(const RexFunctionOperator*) const;
118 
119  std::shared_ptr<Analyzer::Expr> translateLower(const RexFunctionOperator*) const;
120 
121  std::shared_ptr<Analyzer::Expr> translateCardinality(const RexFunctionOperator*) const;
122 
123  std::shared_ptr<Analyzer::Expr> translateItem(const RexFunctionOperator*) const;
124 
125  std::shared_ptr<Analyzer::Expr> translateNow() const;
126 
127  std::shared_ptr<Analyzer::Expr> translateDatetime(const RexFunctionOperator*) const;
128 
129  std::shared_ptr<Analyzer::Expr> translateHPTLiteral(const RexFunctionOperator*) const;
130 
131  std::shared_ptr<Analyzer::Expr> translateAbs(const RexFunctionOperator*) const;
132 
133  std::shared_ptr<Analyzer::Expr> translateSign(const RexFunctionOperator*) const;
134 
135  std::shared_ptr<Analyzer::Expr> translateOffsetInFragment() const;
136 
137  std::shared_ptr<Analyzer::Expr> translateArrayFunction(
138  const RexFunctionOperator*) const;
139 
140  std::shared_ptr<Analyzer::Expr> translateFunction(const RexFunctionOperator*) const;
141 
142  std::shared_ptr<Analyzer::Expr> translateWindowFunction(
143  const RexWindowFunctionOperator*) const;
144 
146 
147  std::shared_ptr<Analyzer::Expr> translateUnaryGeoFunction(
148  const RexFunctionOperator*) const;
149 
150  std::shared_ptr<Analyzer::Expr> translateBinaryGeoFunction(
151  const RexFunctionOperator*) const;
152 
153  std::shared_ptr<Analyzer::Expr> translateTernaryGeoFunction(
154  const RexFunctionOperator*) const;
155 
156  std::shared_ptr<Analyzer::Expr> translateFunctionWithGeoArg(
157  const RexFunctionOperator*) const;
158 
159  std::shared_ptr<Analyzer::Expr> translateGeoComparison(const RexOperator*) const;
160 
161  std::shared_ptr<Analyzer::Expr> translateGeoProjection(const RexFunctionOperator*,
162  SQLTypeInfo&,
163  const bool with_bounds) const;
164 
165  std::shared_ptr<Analyzer::Expr> translateGeoPredicate(const RexFunctionOperator*,
166  SQLTypeInfo&,
167  const bool with_bounds) const;
168 
169  std::shared_ptr<Analyzer::Expr> translateGeoBinaryConstructor(
170  const RexFunctionOperator*,
171  SQLTypeInfo&,
172  const bool with_bounds) const;
173 
174  std::shared_ptr<Analyzer::Expr> translateGeoOverlapsOper(const RexOperator*) const;
175 
176  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoFunctionArg(
177  const RexScalar* rex_scalar,
178  SQLTypeInfo& arg_ti,
179  int32_t& lindex,
180  const bool with_bounds,
181  const bool with_render_group,
182  const bool expand_geo_col,
183  const bool is_projection = false) const;
184 
185  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoColumn(
186  const RexInput*,
187  SQLTypeInfo&,
188  const bool with_bounds,
189  const bool with_render_group,
190  const bool expand_geo_col) const;
191 
192  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoLiteral(const RexLiteral*,
193  SQLTypeInfo&,
194  bool) const;
195 
197  std::shared_ptr<const query_state::QueryState> query_state_;
198  const Executor* executor_;
199  const std::unordered_map<const RelAlgNode*, int> input_to_nest_level_;
200  const std::vector<JoinType> join_types_;
201  time_t now_;
202  mutable bool generated_geos_ops_;
203  const bool just_explain_;
204 };
205 
207  const std::list<std::shared_ptr<Analyzer::Expr>> simple_quals;
208  const std::list<std::shared_ptr<Analyzer::Expr>> quals;
209 };
210 
212  const std::shared_ptr<Analyzer::Expr> qual_expr);
213 
214 std::vector<std::shared_ptr<Analyzer::Expr>> qual_to_disjunctive_form(
215  const std::shared_ptr<Analyzer::Expr>& qual_expr);
216 
217 inline auto func_resolve = [](auto funcname, auto&&... strlist) {
218  return ((funcname == strlist) || ...);
219 };
220 
221 using namespace std::literals;
222 
223 #endif // QUERYENGINE_RELALGTRANSLATOR_H
const std::vector< JoinType > join_types_
auto func_resolve
std::shared_ptr< Analyzer::Expr > translateOffsetInFragment() const
std::string cat(Ts &&...args)
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:97
std::shared_ptr< Analyzer::Expr > translateRegexp(const RexFunctionOperator *) const
const Executor * executor_
std::shared_ptr< Analyzer::Expr > translateUnlikely(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateFunction(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
std::shared_ptr< Analyzer::Expr > translateUoper(const RexOperator *) const
const std::list< std::shared_ptr< Analyzer::Expr > > quals
std::shared_ptr< Analyzer::Expr > translateDateadd(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateNow() const
std::shared_ptr< Analyzer::Expr > translateAbs(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > getInIntegerSetExpr(std::shared_ptr< Analyzer::Expr > arg, const ResultSet &val_set) const
std::shared_ptr< Analyzer::Expr > translateItem(const RexFunctionOperator *) const
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
std::shared_ptr< Analyzer::Expr > translateGeoProjection(const RexFunctionOperator *, SQLTypeInfo &, const bool with_bounds) const
std::shared_ptr< Analyzer::Expr > translateOper(const RexOperator *) const
std::shared_ptr< Analyzer::Expr > translateDatediff(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateInput(const RexInput *) const
std::shared_ptr< Analyzer::Expr > translateSign(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateUnaryGeoFunction(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateGeoOverlapsOper(const RexOperator *) const
std::vector< std::shared_ptr< Analyzer::Expr > > translateGeoLiteral(const RexLiteral *, SQLTypeInfo &, bool) const
std::shared_ptr< Analyzer::Expr > translateLower(const RexFunctionOperator *) const
static std::shared_ptr< Analyzer::Expr > translateLiteral(const RexLiteral *)
std::shared_ptr< Analyzer::Expr > translateDatetime(const RexFunctionOperator *) const
RelAlgTranslator(const Catalog_Namespace::Catalog &cat, std::shared_ptr< const query_state::QueryState > q_s, const Executor *executor, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const std::vector< JoinType > &join_types, const time_t now, const bool just_explain)
const std::unordered_map< const RelAlgNode *, int > input_to_nest_level_
Analyzer::ExpressionPtrVector translateFunctionArgs(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateOverlapsOper(const RexOperator *) const
std::shared_ptr< Analyzer::Expr > translateArrayFunction(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateCurrentUser(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateSampleRatio(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateLike(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateGeoBinaryConstructor(const RexFunctionOperator *, SQLTypeInfo &, const bool with_bounds) const
std::shared_ptr< Analyzer::Expr > translateLikely(const RexFunctionOperator *) const
bool g_enable_watchdog false
Definition: Execute.cpp:74
std::shared_ptr< Analyzer::Expr > translateTernaryGeoFunction(const RexFunctionOperator *) const
std::vector< std::shared_ptr< Analyzer::Expr > > qual_to_disjunctive_form(const std::shared_ptr< Analyzer::Expr > &qual_expr)
const int8_t * literals
std::shared_ptr< Analyzer::Expr > translateBinaryGeoFunction(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateInOper(const RexOperator *) const
std::vector< ExpressionPtr > ExpressionPtrVector
Definition: Analyzer.h:182
std::shared_ptr< Analyzer::Expr > translateCase(const RexCase *) const
std::shared_ptr< Analyzer::Expr > translateFunctionWithGeoArg(const RexFunctionOperator *) const
std::shared_ptr< const query_state::QueryState > query_state_
std::shared_ptr< Analyzer::Expr > translateCardinality(const RexFunctionOperator *) const
const bool just_explain_
std::shared_ptr< Analyzer::Expr > translateGeoComparison(const RexOperator *) const
std::shared_ptr< Analyzer::Expr > translateDatePlusMinus(const RexOperator *) const
const std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
std::shared_ptr< Analyzer::Expr > translateHPTLiteral(const RexFunctionOperator *) const
std::vector< std::shared_ptr< Analyzer::Expr > > translateGeoColumn(const RexInput *, SQLTypeInfo &, const bool with_bounds, const bool with_render_group, const bool expand_geo_col) const
std::shared_ptr< Analyzer::Expr > translateDatepart(const RexFunctionOperator *) const
std::vector< std::shared_ptr< Analyzer::Expr > > translateGeoFunctionArg(const RexScalar *rex_scalar, SQLTypeInfo &arg_ti, int32_t &lindex, const bool with_bounds, const bool with_render_group, const bool expand_geo_col, const bool is_projection=false) const
const Catalog_Namespace::Catalog & cat_
std::shared_ptr< Analyzer::Expr > translateKeyForString(const RexFunctionOperator *) const
static std::shared_ptr< Analyzer::Expr > translateAggregateRex(const RexAgg *rex, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
std::shared_ptr< Analyzer::Expr > translateWindowFunction(const RexWindowFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateScalarSubquery(const RexSubQuery *) const
std::shared_ptr< Analyzer::Expr > translateGeoPredicate(const RexFunctionOperator *, SQLTypeInfo &, const bool with_bounds) const
std::shared_ptr< Analyzer::Expr > translateLength(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateExtract(const RexFunctionOperator *) const