OmniSciDB  21ac014ffc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalciteDeserializerUtils.h File Reference
#include "DateAdd.h"
#include "DateTruncate.h"
#include "../Shared/sqldefs.h"
#include "../Shared/sqltypes.h"
#include "Logger/Logger.h"
+ Include dependency graph for CalciteDeserializerUtils.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 Analyzer
 

Functions

SQLOps to_sql_op (const std::string &op_str)
 
SQLAgg to_agg_kind (const std::string &agg_name)
 
SQLTypes to_sql_type (const std::string &type_name)
 
SQLTypeInfo get_agg_type (const SQLAgg agg_kind, const Analyzer::Expr *arg_expr)
 
ExtractField to_datepart_field (const std::string &)
 
DateaddField to_dateadd_field (const std::string &)
 
DatetruncField to_datediff_field (const std::string &)
 
std::shared_ptr
< Analyzer::Constant
make_fp_constant (const int64_t val, const SQLTypeInfo &ti)
 

Function Documentation

SQLTypeInfo get_agg_type ( const SQLAgg  agg_kind,
const Analyzer::Expr arg_expr 
)

Definition at line 26 of file CalciteDeserializerUtils.cpp.

References CHECK, g_bigint_count, Analyzer::Expr::get_type_info(), SQLTypeInfo::get_type_name(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_varlen(), kAPPROX_COUNT_DISTINCT, kAPPROX_QUANTILE, kAVG, kBIGINT, kCOUNT, kDOUBLE, kINT, kMAX, kMIN, kSAMPLE, kSINGLE_VALUE, and kSUM.

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation(), and RelAlgTranslator::translateAggregateRex().

26  {
27  switch (agg_kind) {
28  case kCOUNT:
29  return SQLTypeInfo(g_bigint_count ? kBIGINT : kINT, false);
30  case kMIN:
31  case kMAX:
32  return arg_expr->get_type_info();
33  case kSUM:
34  return arg_expr->get_type_info().is_integer() ? SQLTypeInfo(kBIGINT, false)
35  : arg_expr->get_type_info();
36  case kAVG:
37  return SQLTypeInfo(kDOUBLE, false);
39  return SQLTypeInfo(kBIGINT, false);
40  case kAPPROX_QUANTILE:
41  return SQLTypeInfo(kDOUBLE, false);
42  case kSINGLE_VALUE:
43  if (arg_expr->get_type_info().is_varlen()) {
44  throw std::runtime_error("SINGLE_VALUE not supported on '" +
45  arg_expr->get_type_info().get_type_name() + "' input.");
46  }
47  case kSAMPLE:
48  return arg_expr->get_type_info();
49  default:
50  CHECK(false);
51  }
52  CHECK(false);
53  return SQLTypeInfo();
54 }
bool is_varlen() const
Definition: sqltypes.h:523
Definition: sqldefs.h:73
bool is_integer() const
Definition: sqltypes.h:500
bool g_bigint_count
Definition: sqldefs.h:75
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
Definition: sqldefs.h:76
std::string get_type_name() const
Definition: sqltypes.h:426
#define CHECK(condition)
Definition: Logger.h:206
Definition: sqltypes.h:44
Definition: sqldefs.h:74
Definition: sqldefs.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::Constant> make_fp_constant ( const int64_t  val,
const SQLTypeInfo ti 
)

Definition at line 210 of file CalciteDeserializerUtils.cpp.

References CHECK, test_fsi::d, Datum::doubleval, Datum::floatval, SQLTypeInfo::get_type(), kDOUBLE, and kFLOAT.

Referenced by RelAlgTranslator::translateLiteral().

211  {
212  Datum d;
213  switch (ti.get_type()) {
214  case kFLOAT:
215  d.floatval = val;
216  break;
217  case kDOUBLE:
218  d.doubleval = val;
219  break;
220  default:
221  CHECK(false);
222  }
223  return makeExpr<Analyzer::Constant>(ti, false, d);
224 }
tuple d
Definition: test_fsi.py:9
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
float floatval
Definition: sqltypes.h:210
#define CHECK(condition)
Definition: Logger.h:206
double doubleval
Definition: sqltypes.h:211

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLAgg to_agg_kind ( const std::string &  agg_name)
inline

Definition at line 94 of file CalciteDeserializerUtils.h.

References kAPPROX_COUNT_DISTINCT, kAPPROX_QUANTILE, kAVG, kCOUNT, kMAX, kMIN, kSAMPLE, kSINGLE_VALUE, and kSUM.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::parse_aggregate_expr().

94  {
95  if (agg_name == std::string("COUNT")) {
96  return kCOUNT;
97  }
98  if (agg_name == std::string("MIN")) {
99  return kMIN;
100  }
101  if (agg_name == std::string("MAX")) {
102  return kMAX;
103  }
104  if (agg_name == std::string("SUM")) {
105  return kSUM;
106  }
107  if (agg_name == std::string("AVG")) {
108  return kAVG;
109  }
110  if (agg_name == std::string("APPROX_COUNT_DISTINCT")) {
111  return kAPPROX_COUNT_DISTINCT;
112  }
113  if (agg_name == "APPROX_MEDIAN" || agg_name == "APPROX_QUANTILE") {
114  return kAPPROX_QUANTILE;
115  }
116  if (agg_name == std::string("SAMPLE") || agg_name == std::string("LAST_SAMPLE")) {
117  return kSAMPLE;
118  }
119  if (agg_name == std::string("SINGLE_VALUE")) {
120  return kSINGLE_VALUE;
121  }
122  throw std::runtime_error("Aggregate function " + agg_name + " not supported");
123 }
Definition: sqldefs.h:73
Definition: sqldefs.h:75
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:72

+ Here is the caller graph for this function:

DateaddField to_dateadd_field ( const std::string &  )

Definition at line 108 of file CalciteDeserializerUtils.cpp.

References daCENTURY, daDAY, daDECADE, daHOUR, daMICROSECOND, daMILLENNIUM, daMILLISECOND, daMINUTE, daMONTH, daNANOSECOND, daQUARTER, daSECOND, daWEEK, daWEEKDAY, and daYEAR.

Referenced by RelAlgTranslator::translateDateadd().

108  {
109  DateaddField fieldno;
110  if (boost::iequals(field, "year") || boost::iequals(field, "yy") ||
111  boost::iequals(field, "yyyy") || boost::iequals(field, "sql_tsi_year")) {
112  fieldno = daYEAR;
113  } else if (boost::iequals(field, "quarter") || boost::iequals(field, "qq") ||
114  boost::iequals(field, "q") || boost::iequals(field, "sql_tsi_quarter")) {
115  fieldno = daQUARTER;
116  } else if (boost::iequals(field, "month") || boost::iequals(field, "mm") ||
117  boost::iequals(field, "m") || boost::iequals(field, "sql_tsi_month")) {
118  fieldno = daMONTH;
119  } else if (boost::iequals(field, "day") || boost::iequals(field, "dd") ||
120  boost::iequals(field, "d") || boost::iequals(field, "sql_tsi_day")) {
121  fieldno = daDAY;
122  } else if (boost::iequals(field, "week") || boost::iequals(field, "ww") ||
123  boost::iequals(field, "w") || boost::iequals(field, "sql_tsi_week")) {
124  fieldno = daWEEK;
125  } else if (boost::iequals(field, "hour") || boost::iequals(field, "hh") ||
126  boost::iequals(field, "sql_tsi_hour")) {
127  fieldno = daHOUR;
128  } else if (boost::iequals(field, "minute") || boost::iequals(field, "mi") ||
129  boost::iequals(field, "n") || boost::iequals(field, "sql_tsi_minute")) {
130  fieldno = daMINUTE;
131  } else if (boost::iequals(field, "second") || boost::iequals(field, "ss") ||
132  boost::iequals(field, "s") || boost::iequals(field, "sql_tsi_second")) {
133  fieldno = daSECOND;
134  } else if (boost::iequals(field, "millisecond") || boost::iequals(field, "ms")) {
135  fieldno = daMILLISECOND;
136  } else if (boost::iequals(field, "microsecond") || boost::iequals(field, "us") ||
137  boost::iequals(field, "sql_tsi_microsecond") ||
138  boost::iequals(field, "frac_second")) {
139  fieldno = daMICROSECOND;
140  } else if (boost::iequals(field, "nanosecond") || boost::iequals(field, "ns") ||
141  boost::iequals(field, "sql_tsi_frac_second")) {
142  fieldno = daNANOSECOND;
143  } else if (boost::iequals(field, "weekday") || boost::iequals(field, "dw")) {
144  fieldno = daWEEKDAY;
145  } else if (boost::iequals(field, "decade") || boost::iequals(field, "dc")) {
146  fieldno = daDECADE;
147  } else if (boost::iequals(field, "century")) {
148  fieldno = daCENTURY;
149  } else if (boost::iequals(field, "millennium")) {
150  fieldno = daMILLENNIUM;
151  } else {
152  throw std::runtime_error("Unsupported field in DATEADD function: " + field);
153  }
154  return fieldno;
155 }
Definition: DateAdd.h:47
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
Definition: DateAdd.h:43
DateaddField
Definition: DateAdd.h:42
Definition: DateAdd.h:56
Definition: DateAdd.h:46

+ Here is the caller graph for this function:

DatetruncField to_datediff_field ( const std::string &  )

Definition at line 157 of file CalciteDeserializerUtils.cpp.

References dtCENTURY, dtDAY, dtDECADE, dtHOUR, dtMICROSECOND, dtMILLENNIUM, dtMILLISECOND, dtMINUTE, dtMONTH, dtNANOSECOND, dtQUARTER, dtQUARTERDAY, dtSECOND, dtWEEK, dtWEEK_SATURDAY, dtWEEK_SUNDAY, and dtYEAR.

Referenced by RelAlgTranslator::translateDatediff().

157  {
158  DatetruncField fieldno;
159  if (boost::iequals(field, "year") || boost::iequals(field, "yy") ||
160  boost::iequals(field, "yyyy") || boost::iequals(field, "sql_tsi_year")) {
161  fieldno = dtYEAR;
162  } else if (boost::iequals(field, "quarter") || boost::iequals(field, "qq") ||
163  boost::iequals(field, "q") || boost::iequals(field, "sql_tsi_quarter")) {
164  fieldno = dtQUARTER;
165  } else if (boost::iequals(field, "month") || boost::iequals(field, "mm") ||
166  boost::iequals(field, "m") || boost::iequals(field, "sql_tsi_month")) {
167  fieldno = dtMONTH;
168  } else if (boost::iequals(field, "week") || boost::iequals(field, "ww") ||
169  boost::iequals(field, "w") || boost::iequals(field, "sql_tsi_week")) {
170  fieldno = dtWEEK;
171  } else if (boost::iequals(field, "week_sunday")) {
172  fieldno = dtWEEK_SUNDAY;
173  } else if (boost::iequals(field, "week_saturday")) {
174  fieldno = dtWEEK_SATURDAY;
175  } else if (boost::iequals(field, "day") || boost::iequals(field, "dd") ||
176  boost::iequals(field, "d") || boost::iequals(field, "sql_tsi_day")) {
177  fieldno = dtDAY;
178  } else if (boost::iequals(field, "quarterday")) {
179  fieldno = dtQUARTERDAY;
180  } else if (boost::iequals(field, "hour") || boost::iequals(field, "hh") ||
181  boost::iequals(field, "sql_tsi_hour")) {
182  fieldno = dtHOUR;
183  } else if (boost::iequals(field, "minute") || boost::iequals(field, "mi") ||
184  boost::iequals(field, "n") || boost::iequals(field, "sql_tsi_minute")) {
185  fieldno = dtMINUTE;
186  } else if (boost::iequals(field, "second") || boost::iequals(field, "ss") ||
187  boost::iequals(field, "s") || boost::iequals(field, "sql_tsi_second")) {
188  fieldno = dtSECOND;
189  } else if (boost::iequals(field, "millisecond") || boost::iequals(field, "ms")) {
190  fieldno = dtMILLISECOND;
191  } else if (boost::iequals(field, "microsecond") || boost::iequals(field, "us") ||
192  boost::iequals(field, "sql_tsi_microsecond") ||
193  boost::iequals(field, "frac_second")) {
194  fieldno = dtMICROSECOND;
195  } else if (boost::iequals(field, "nanosecond") || boost::iequals(field, "ns") ||
196  boost::iequals(field, "sql_tsi_frac_second")) {
197  fieldno = dtNANOSECOND;
198  } else if (boost::iequals(field, "decade") || boost::iequals(field, "dc")) {
199  fieldno = dtDECADE;
200  } else if (boost::iequals(field, "century")) {
201  fieldno = dtCENTURY;
202  } else if (boost::iequals(field, "millennium")) {
203  fieldno = dtMILLENNIUM;
204  } else {
205  throw std::runtime_error("Unsupported field in DATEDIFF function: " + field);
206  }
207  return fieldno;
208 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
DatetruncField
Definition: DateTruncate.h:27

+ Here is the caller graph for this function:

ExtractField to_datepart_field ( const std::string &  )

Definition at line 56 of file CalciteDeserializerUtils.cpp.

References kDAY, kDOY, kHOUR, kISODOW, kMICROSECOND, kMILLISECOND, kMINUTE, kMONTH, kNANOSECOND, kQUARTER, kQUARTERDAY, kSECOND, kWEEK, kWEEK_SATURDAY, kWEEK_SUNDAY, and kYEAR.

Referenced by RelAlgTranslator::translateDatepart().

56  {
57  ExtractField fieldno;
58  if (boost::iequals(field, "year") || boost::iequals(field, "yy") ||
59  boost::iequals(field, "yyyy") || boost::iequals(field, "sql_tsi_year")) {
60  fieldno = kYEAR;
61  } else if (boost::iequals(field, "quarter") || boost::iequals(field, "qq") ||
62  boost::iequals(field, "q") || boost::iequals(field, "sql_tsi_quarter")) {
63  fieldno = kQUARTER;
64  } else if (boost::iequals(field, "month") || boost::iequals(field, "mm") ||
65  boost::iequals(field, "m") || boost::iequals(field, "sql_tsi_month")) {
66  fieldno = kMONTH;
67  } else if (boost::iequals(field, "dayofyear") || boost::iequals(field, "dy") ||
68  boost::iequals(field, "y")) {
69  fieldno = kDOY;
70  } else if (boost::iequals(field, "day") || boost::iequals(field, "dd") ||
71  boost::iequals(field, "d") || boost::iequals(field, "sql_tsi_day")) {
72  fieldno = kDAY;
73  } else if (boost::iequals(field, "week") || boost::iequals(field, "ww") ||
74  boost::iequals(field, "w") || boost::iequals(field, "sql_tsi_week")) {
75  fieldno = kWEEK;
76  } else if (boost::iequals(field, "week_sunday")) {
77  fieldno = kWEEK_SUNDAY;
78  } else if (boost::iequals(field, "week_saturday")) {
79  fieldno = kWEEK_SATURDAY;
80  } else if (boost::iequals(field, "hour") || boost::iequals(field, "hh") ||
81  boost::iequals(field, "sql_tsi_hour")) {
82  fieldno = kHOUR;
83  } else if (boost::iequals(field, "minute") || boost::iequals(field, "mi") ||
84  boost::iequals(field, "n") || boost::iequals(field, "sql_tsi_minute")) {
85  fieldno = kMINUTE;
86  } else if (boost::iequals(field, "second") || boost::iequals(field, "ss") ||
87  boost::iequals(field, "s") || boost::iequals(field, "sql_tsi_second")) {
88  fieldno = kSECOND;
89  } else if (boost::iequals(field, "millisecond") || boost::iequals(field, "ms")) {
90  fieldno = kMILLISECOND;
91  } else if (boost::iequals(field, "microsecond") || boost::iequals(field, "us") ||
92  boost::iequals(field, "sql_tsi_microsecond") ||
93  boost::iequals(field, "frac_second")) {
94  fieldno = kMICROSECOND;
95  } else if (boost::iequals(field, "nanosecond") || boost::iequals(field, "ns") ||
96  boost::iequals(field, "sql_tsi_frac_second")) {
97  fieldno = kNANOSECOND;
98  } else if (boost::iequals(field, "weekday") || boost::iequals(field, "dw")) {
99  fieldno = kISODOW;
100  } else if (boost::iequals(field, "quarterday") || boost::iequals(field, "dq")) {
101  fieldno = kQUARTERDAY;
102  } else {
103  throw std::runtime_error("Unsupported field in DATEPART function: " + field);
104  }
105  return fieldno;
106 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
ExtractField

+ Here is the caller graph for this function:

SQLOps to_sql_op ( const std::string &  op_str)
inline

Definition at line 27 of file CalciteDeserializerUtils.h.

References kAND, kBW_EQ, kCAST, kDIVIDE, kEQ, kFUNCTION, kGE, kGT, kIN, kISNOTNULL, kISNULL, kLE, kLT, kMINUS, kMODULO, kMULTIPLY, kNE, kNOT, kOR, kPLUS, and kUNNEST.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::parse_operator().

27  {
28  if (op_str == std::string(">")) {
29  return kGT;
30  }
31  if (op_str == std::string("IS NOT DISTINCT FROM")) {
32  return kBW_EQ;
33  }
34  if (op_str == std::string(">=")) {
35  return kGE;
36  }
37  if (op_str == std::string("<")) {
38  return kLT;
39  }
40  if (op_str == std::string("<=")) {
41  return kLE;
42  }
43  if (op_str == std::string("=")) {
44  return kEQ;
45  }
46  if (op_str == std::string("<>")) {
47  return kNE;
48  }
49  if (op_str == std::string("+")) {
50  return kPLUS;
51  }
52  if (op_str == std::string("-")) {
53  return kMINUS;
54  }
55  if (op_str == std::string("*")) {
56  return kMULTIPLY;
57  }
58  if (op_str == std::string("/")) {
59  return kDIVIDE;
60  }
61  if (op_str == "MOD") {
62  return kMODULO;
63  }
64  if (op_str == std::string("AND")) {
65  return kAND;
66  }
67  if (op_str == std::string("OR")) {
68  return kOR;
69  }
70  if (op_str == std::string("CAST")) {
71  return kCAST;
72  }
73  if (op_str == std::string("NOT")) {
74  return kNOT;
75  }
76  if (op_str == std::string("IS NULL")) {
77  return kISNULL;
78  }
79  if (op_str == std::string("IS NOT NULL")) {
80  return kISNOTNULL;
81  }
82  if (op_str == std::string("PG_UNNEST")) {
83  return kUNNEST;
84  }
85  if (op_str == std::string("PG_ANY") || op_str == std::string("PG_ALL")) {
86  throw std::runtime_error("Invalid use of " + op_str + " operator");
87  }
88  if (op_str == std::string("IN")) {
89  return kIN;
90  }
91  return kFUNCTION;
92 }
Definition: sqldefs.h:35
Definition: sqldefs.h:36
Definition: sqldefs.h:38
Definition: sqldefs.h:49
Definition: sqldefs.h:30
Definition: sqldefs.h:41
Definition: sqldefs.h:37
Definition: sqldefs.h:34
Definition: sqldefs.h:40
Definition: sqldefs.h:32
Definition: sqldefs.h:53
Definition: sqldefs.h:31
Definition: sqldefs.h:33
Definition: sqldefs.h:39

+ Here is the caller graph for this function:

SQLTypes to_sql_type ( const std::string &  type_name)
inline

Definition at line 125 of file CalciteDeserializerUtils.h.

References kARRAY, kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kEVAL_CONTEXT_TYPE, kFLOAT, kGEOGRAPHY, kGEOMETRY, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kLINESTRING, kMULTIPOLYGON, kNULLT, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, and kTINYINT.

Referenced by Parser::anonymous_namespace{ParserNode.cpp}::column_from_json(), anonymous_namespace{RelAlgDagBuilder.cpp}::parse_literal(), and anonymous_namespace{RelAlgDagBuilder.cpp}::parse_type().

125  {
126  if (type_name == std::string("BIGINT")) {
127  return kBIGINT;
128  }
129  if (type_name == std::string("INTEGER")) {
130  return kINT;
131  }
132  if (type_name == std::string("TINYINT")) {
133  return kTINYINT;
134  }
135  if (type_name == std::string("SMALLINT")) {
136  return kSMALLINT;
137  }
138  if (type_name == std::string("FLOAT")) {
139  return kFLOAT;
140  }
141  if (type_name == std::string("REAL")) {
142  return kFLOAT;
143  }
144  if (type_name == std::string("DOUBLE")) {
145  return kDOUBLE;
146  }
147  if (type_name == std::string("DECIMAL")) {
148  return kDECIMAL;
149  }
150  if (type_name == std::string("CHAR") || type_name == std::string("VARCHAR")) {
151  return kTEXT;
152  }
153  if (type_name == std::string("BOOLEAN")) {
154  return kBOOLEAN;
155  }
156  if (type_name == std::string("TIMESTAMP")) {
157  return kTIMESTAMP;
158  }
159  if (type_name == std::string("DATE")) {
160  return kDATE;
161  }
162  if (type_name == std::string("TIME")) {
163  return kTIME;
164  }
165  if (type_name == std::string("NULL")) {
166  return kNULLT;
167  }
168  if (type_name == std::string("ARRAY")) {
169  return kARRAY;
170  }
171  if (type_name == std::string("INTERVAL_DAY") ||
172  type_name == std::string("INTERVAL_HOUR") ||
173  type_name == std::string("INTERVAL_MINUTE") ||
174  type_name == std::string("INTERVAL_SECOND")) {
175  return kINTERVAL_DAY_TIME;
176  }
177  if (type_name == std::string("INTERVAL_MONTH") ||
178  type_name == std::string("INTERVAL_YEAR")) {
179  return kINTERVAL_YEAR_MONTH;
180  }
181  if (type_name == std::string("ANY")) {
182  return kEVAL_CONTEXT_TYPE;
183  }
184  if (type_name == std::string("TEXT")) {
185  return kTEXT;
186  }
187  if (type_name == std::string("POINT")) {
188  return kPOINT;
189  }
190  if (type_name == std::string("LINESTRING")) {
191  return kLINESTRING;
192  }
193  if (type_name == std::string("POLYGON")) {
194  return kPOLYGON;
195  }
196  if (type_name == std::string("MULTIPOLYGON")) {
197  return kMULTIPOLYGON;
198  }
199  if (type_name == std::string("GEOMETRY")) {
200  return kGEOMETRY;
201  }
202  if (type_name == std::string("GEOGRAPHY")) {
203  return kGEOGRAPHY;
204  }
205 
206  throw std::runtime_error("Unsupported type: " + type_name);
207 }
Definition: sqltypes.h:48
Definition: sqltypes.h:51
Definition: sqltypes.h:52
Definition: sqltypes.h:44
constexpr auto type_name() noexcept

+ Here is the caller graph for this function: