OmniSciDB  04ee39c94c
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> translateCardinality(const RexFunctionOperator*) const;
107 
108  std::shared_ptr<Analyzer::Expr> translateItem(const RexFunctionOperator*) const;
109 
110  std::shared_ptr<Analyzer::Expr> translateNow() const;
111 
112  std::shared_ptr<Analyzer::Expr> translateDatetime(const RexFunctionOperator*) const;
113 
114  std::shared_ptr<Analyzer::Expr> translateHPTLiteral(const RexFunctionOperator*) const;
115 
116  std::shared_ptr<Analyzer::Expr> translateAbs(const RexFunctionOperator*) const;
117 
118  std::shared_ptr<Analyzer::Expr> translateSign(const RexFunctionOperator*) const;
119 
120  std::shared_ptr<Analyzer::Expr> translateOffsetInFragment() const;
121 
122  std::shared_ptr<Analyzer::Expr> translateArrayFunction(
123  const RexFunctionOperator*) const;
124 
125  std::shared_ptr<Analyzer::Expr> translateFunction(const RexFunctionOperator*) const;
126 
127  std::shared_ptr<Analyzer::Expr> translateWindowFunction(
128  const RexWindowFunctionOperator*) const;
129 
130  Analyzer::ExpressionPtrVector translateFunctionArgs(const RexFunctionOperator*) const;
131 
132  std::shared_ptr<Analyzer::Expr> translateUnaryGeoFunction(
133  const RexFunctionOperator*) const;
134 
135  std::shared_ptr<Analyzer::Expr> translateBinaryGeoFunction(
136  const RexFunctionOperator*) const;
137 
138  std::shared_ptr<Analyzer::Expr> translateTernaryGeoFunction(
139  const RexFunctionOperator*) const;
140 
141  std::shared_ptr<Analyzer::Expr> translateFunctionWithGeoArg(
142  const RexFunctionOperator*) const;
143 
144  std::shared_ptr<Analyzer::Expr> translateGeoComparison(const RexOperator*) const;
145 
146  std::shared_ptr<Analyzer::Expr> translateGeoOverlapsOper(const RexOperator*) const;
147 
148  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoFunctionArg(
149  const RexScalar* rex_scalar,
150  SQLTypeInfo& arg_ti,
151  int32_t& lindex,
152  const bool with_bounds,
153  const bool with_render_group,
154  const bool expand_geo_col) const;
155 
156  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoColumn(
157  const RexInput*,
158  SQLTypeInfo&,
159  const bool with_bounds,
160  const bool with_render_group,
161  const bool expand_geo_col) const;
162 
163  std::vector<std::shared_ptr<Analyzer::Expr>> translateGeoLiteral(const RexLiteral*,
164  SQLTypeInfo&,
165  bool) const;
166 
168  const Executor* executor_;
169  const std::unordered_map<const RelAlgNode*, int> input_to_nest_level_;
170  const std::vector<JoinType> join_types_;
171  time_t now_;
172  const bool just_explain_;
174 };
175 
177  const std::list<std::shared_ptr<Analyzer::Expr>> simple_quals;
178  const std::list<std::shared_ptr<Analyzer::Expr>> quals;
179 };
180 
182  const std::shared_ptr<Analyzer::Expr> qual_expr);
183 
184 std::vector<std::shared_ptr<Analyzer::Expr>> qual_to_disjunctive_form(
185  const std::shared_ptr<Analyzer::Expr>& qual_expr);
186 
187 #endif // QUERYENGINE_RELALGTRANSLATOR_H
const std::vector< JoinType > join_types_
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
const Executor * executor_
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
const std::list< std::shared_ptr< Analyzer::Expr > > quals
std::vector< std::shared_ptr< Analyzer::Expr > > qual_to_disjunctive_form(const std::shared_ptr< Analyzer::Expr > &qual_expr)
QueryFeatureDescriptor & feature_stash_
const std::unordered_map< const RelAlgNode *, int > input_to_nest_level_
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::vector< ExpressionPtr > ExpressionPtrVector
Definition: Analyzer.h:181
const bool just_explain_
const std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
const Catalog_Namespace::Catalog & cat_