OmniSciDB  1dac507f6e
 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 "QueryFeatures.h"
23 
24 #include <ctime>
25 #include <memory>
26 #include <unordered_map>
27 #include <vector>
28 
29 namespace Analyzer {
30 
31 class Expr;
32 
33 } // namespace Analyzer
34 
35 namespace Catalog_Namespace {
36 
37 class Catalog;
38 
39 } // namespace Catalog_Namespace
40 
42  public:
44  const Executor* executor,
45  const std::unordered_map<const RelAlgNode*, int>& input_to_nest_level,
46  const std::vector<JoinType>& join_types,
47  const time_t now,
48  const bool just_explain,
49  QueryFeatureDescriptor& feature_stash)
50  : cat_(cat)
51  , executor_(executor)
52  , input_to_nest_level_(input_to_nest_level)
53  , join_types_(join_types)
54  , now_(now)
55  , just_explain_(just_explain)
56  , feature_stash_(feature_stash) {}
57 
58  std::shared_ptr<Analyzer::Expr> translateScalarRex(const RexScalar* rex) const;
59 
60  static std::shared_ptr<Analyzer::Expr> translateAggregateRex(
61  const RexAgg* rex,
62  const std::vector<std::shared_ptr<Analyzer::Expr>>& scalar_sources);
63 
64  private:
65  static std::shared_ptr<Analyzer::Expr> translateLiteral(const RexLiteral*);
66 
67  std::shared_ptr<Analyzer::Expr> translateScalarSubquery(const RexSubQuery*) const;
68 
69  std::shared_ptr<Analyzer::Expr> translateInput(const RexInput*) const;
70 
71  std::shared_ptr<Analyzer::Expr> translateUoper(const RexOperator*) const;
72 
73  std::shared_ptr<Analyzer::Expr> translateInOper(const RexOperator*) const;
74 
75  std::shared_ptr<Analyzer::Expr> getInIntegerSetExpr(std::shared_ptr<Analyzer::Expr> arg,
76  const ResultSet& val_set) const;
77 
78  std::shared_ptr<Analyzer::Expr> translateOper(const RexOperator*) const;
79 
80  std::shared_ptr<Analyzer::Expr> translateOverlapsOper(const RexOperator*) const;
81 
82  std::shared_ptr<Analyzer::Expr> translateCase(const RexCase*) const;
83 
84  std::shared_ptr<Analyzer::Expr> translateLike(const RexFunctionOperator*) const;
85 
86  std::shared_ptr<Analyzer::Expr> translateRegexp(const RexFunctionOperator*) const;
87 
88  std::shared_ptr<Analyzer::Expr> translateLikely(const RexFunctionOperator*) const;
89 
90  std::shared_ptr<Analyzer::Expr> translateUnlikely(const RexFunctionOperator*) const;
91 
92  std::shared_ptr<Analyzer::Expr> translateExtract(const RexFunctionOperator*) const;
93 
94  std::shared_ptr<Analyzer::Expr> translateDateadd(const RexFunctionOperator*) const;
95 
96  std::shared_ptr<Analyzer::Expr> translateDatePlusMinus(const RexOperator*) const;
97 
98  std::shared_ptr<Analyzer::Expr> translateDatediff(const RexFunctionOperator*) const;
99 
100  std::shared_ptr<Analyzer::Expr> translateDatepart(const RexFunctionOperator*) const;
101 
102  std::shared_ptr<Analyzer::Expr> translateLength(const RexFunctionOperator*) const;
103 
104  std::shared_ptr<Analyzer::Expr> translateKeyForString(const RexFunctionOperator*) const;
105 
106  std::shared_ptr<Analyzer::Expr> translateLower(const RexFunctionOperator*) const;
107 
108  std::shared_ptr<Analyzer::Expr> translateCardinality(const RexFunctionOperator*) const;
109 
110  std::shared_ptr<Analyzer::Expr> translateItem(const RexFunctionOperator*) const;
111 
112  std::shared_ptr<Analyzer::Expr> translateNow() const;
113 
114  std::shared_ptr<Analyzer::Expr> translateDatetime(const RexFunctionOperator*) const;
115 
116  std::shared_ptr<Analyzer::Expr> translateHPTLiteral(const RexFunctionOperator*) const;
117 
118  std::shared_ptr<Analyzer::Expr> translateAbs(const RexFunctionOperator*) const;
119 
120  std::shared_ptr<Analyzer::Expr> translateSign(const RexFunctionOperator*) const;
121 
122  std::shared_ptr<Analyzer::Expr> translateOffsetInFragment() const;
123 
124  std::shared_ptr<Analyzer::Expr> translateArrayFunction(
125  const RexFunctionOperator*) const;
126 
127  std::shared_ptr<Analyzer::Expr> translateFunction(const RexFunctionOperator*) const;
128 
129  std::shared_ptr<Analyzer::Expr> translateWindowFunction(
130  const RexWindowFunctionOperator*) const;
131 
133 
134  std::shared_ptr<Analyzer::Expr> translateUnaryGeoFunction(
135  const RexFunctionOperator*) const;
136 
137  std::shared_ptr<Analyzer::Expr> translateBinaryGeoFunction(
138  const RexFunctionOperator*) const;
139 
140  std::shared_ptr<Analyzer::Expr> translateTernaryGeoFunction(
141  const RexFunctionOperator*) const;
142 
143  std::shared_ptr<Analyzer::Expr> translateFunctionWithGeoArg(
144  const RexFunctionOperator*) const;
145 
146  std::shared_ptr<Analyzer::Expr> translateGeoComparison(const RexOperator*) const;
147 
148  std::shared_ptr<Analyzer::Expr> translateGeoConstructor(
149  const RexFunctionOperator*) const;
150 
151  std::shared_ptr<Analyzer::Expr> translateGeoOverlapsOper(const RexOperator*) const;
152 
153  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoFunctionArg(
154  const RexScalar* rex_scalar,
155  SQLTypeInfo& arg_ti,
156  int32_t& lindex,
157  const bool with_bounds,
158  const bool with_render_group,
159  const bool expand_geo_col,
160  const bool is_projection = false) const;
161 
162  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoColumn(
163  const RexInput*,
164  SQLTypeInfo&,
165  const bool with_bounds,
166  const bool with_render_group,
167  const bool expand_geo_col) const;
168 
169  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoLiteral(const RexLiteral*,
170  SQLTypeInfo&,
171  bool) const;
172 
174  const Executor* executor_;
175  const std::unordered_map<const RelAlgNode*, int> input_to_nest_level_;
176  const std::vector<JoinType> join_types_;
177  time_t now_;
178  const bool just_explain_;
180 };
181 
183  const std::list<std::shared_ptr<Analyzer::Expr>> simple_quals;
184  const std::list<std::shared_ptr<Analyzer::Expr>> quals;
185 };
186 
188  const std::shared_ptr<Analyzer::Expr> qual_expr);
189 
190 std::vector<std::shared_ptr<Analyzer::Expr>> qual_to_disjunctive_form(
191  const std::shared_ptr<Analyzer::Expr>& qual_expr);
192 
193 inline auto func_resolve = [](auto funcname, auto&&... strlist) {
194  return ((funcname == strlist) || ...);
195 };
196 
197 using namespace std::literals;
198 
199 #endif // QUERYENGINE_RELALGTRANSLATOR_H
const std::vector< JoinType > join_types_
auto func_resolve
std::shared_ptr< Analyzer::Expr > translateOffsetInFragment() const
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
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 > translateOper(const RexOperator *) const
std::shared_ptr< Analyzer::Expr > translateDatediff(const RexFunctionOperator *) const
QueryFeatureDescriptor & feature_stash_
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
std::shared_ptr< Analyzer::Expr > translateGeoConstructor(const RexFunctionOperator *) const
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 > translateLike(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateLikely(const RexFunctionOperator *) const
RelAlgTranslator(const Catalog_Namespace::Catalog &cat, 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, QueryFeatureDescriptor &feature_stash)
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< 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 > translateLength(const RexFunctionOperator *) const
std::shared_ptr< Analyzer::Expr > translateExtract(const RexFunctionOperator *) const