OmniSciDB  c07336695a
CalciteDeserializerUtils.h File Reference
#include "DateAdd.h"
#include "DateTruncate.h"
#include "../Shared/sqldefs.h"
#include "../Shared/sqltypes.h"
#include "Shared/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::Constantmake_fp_constant (const int64_t val, const SQLTypeInfo &ti)
 

Function Documentation

◆ get_agg_type()

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(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_integer(), kAPPROX_COUNT_DISTINCT, kAVG, kBIGINT, kCOUNT, kDOUBLE, kINT, kMAX, kMIN, kSAMPLE, and kSUM.

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation(), to_sql_type(), anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateAggregate(), 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 kSAMPLE:
41  return arg_expr->get_type_info();
42  default:
43  CHECK(false);
44  }
45  CHECK(false);
46  return SQLTypeInfo();
47 }
Definition: sqldefs.h:71
bool is_integer() const
Definition: sqltypes.h:448
bool g_bigint_count
Definition: sqldefs.h:71
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:819
Definition: sqldefs.h:71
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
Definition: sqldefs.h:71
Definition: sqldefs.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_fp_constant()

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

Definition at line 172 of file CalciteDeserializerUtils.cpp.

References CHECK, anonymous_namespace{ImportTest.cpp}::d(), Datum::doubleval, Datum::floatval, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), kDOUBLE, and kFLOAT.

Referenced by to_sql_type(), RelAlgTranslator::translateLiteral(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateTypedLiteral().

173  {
174  Datum d;
175  switch (ti.get_type()) {
176  case kFLOAT:
177  d.floatval = val;
178  break;
179  case kDOUBLE:
180  d.doubleval = val;
181  break;
182  default:
183  CHECK(false);
184  }
185  return makeExpr<Analyzer::Constant>(ti, false, d);
186 }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
float floatval
Definition: sqltypes.h:127
#define CHECK(condition)
Definition: Logger.h:187
double doubleval
Definition: sqltypes.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_agg_kind()

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

Definition at line 94 of file CalciteDeserializerUtils.h.

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

Referenced by anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_aggregate_expr(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateAggregate().

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 == std::string("SAMPLE") || agg_name == std::string("LAST_SAMPLE")) {
114  return kSAMPLE;
115  }
116  throw std::runtime_error("Aggregate function " + agg_name + " not supported");
117 }
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
+ Here is the caller graph for this function:

◆ to_dateadd_field()

DateaddField to_dateadd_field ( const std::string &  )

Definition at line 90 of file CalciteDeserializerUtils.cpp.

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

Referenced by to_sql_type(), RelAlgTranslator::translateDateadd(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateDateadd().

90  {
91  DateaddField fieldno;
92  if (boost::iequals(field, "year") || boost::iequals(field, "yy") ||
93  boost::iequals(field, "yyyy") || boost::iequals(field, "sql_tsi_year")) {
94  fieldno = daYEAR;
95  } else if (boost::iequals(field, "quarter") || boost::iequals(field, "qq") ||
96  boost::iequals(field, "q") || boost::iequals(field, "sql_tsi_quarter")) {
97  fieldno = daQUARTER;
98  } else if (boost::iequals(field, "month") || boost::iequals(field, "mm") ||
99  boost::iequals(field, "m") || boost::iequals(field, "sql_tsi_month")) {
100  fieldno = daMONTH;
101  } else if (boost::iequals(field, "day") || boost::iequals(field, "dd") ||
102  boost::iequals(field, "d") || boost::iequals(field, "sql_tsi_day")) {
103  fieldno = daDAY;
104  } else if (boost::iequals(field, "week") || boost::iequals(field, "ww") ||
105  boost::iequals(field, "w") || boost::iequals(field, "sql_tsi_week")) {
106  fieldno = daWEEK;
107  } else if (boost::iequals(field, "hour") || boost::iequals(field, "hh") ||
108  boost::iequals(field, "sql_tsi_hour")) {
109  fieldno = daHOUR;
110  } else if (boost::iequals(field, "minute") || boost::iequals(field, "mi") ||
111  boost::iequals(field, "n") || boost::iequals(field, "sql_tsi_minute")) {
112  fieldno = daMINUTE;
113  } else if (boost::iequals(field, "second") || boost::iequals(field, "ss") ||
114  boost::iequals(field, "s") || boost::iequals(field, "sql_tsi_second")) {
115  fieldno = daSECOND;
116  } else if (boost::iequals(field, "millisecond") || boost::iequals(field, "ms")) {
117  fieldno = daMILLISECOND;
118  } else if (boost::iequals(field, "microsecond") || boost::iequals(field, "us") ||
119  boost::iequals(field, "sql_tsi_microsecond") ||
120  boost::iequals(field, "frac_second")) {
121  fieldno = daMICROSECOND;
122  } else if (boost::iequals(field, "nanosecond") || boost::iequals(field, "ns") ||
123  boost::iequals(field, "sql_tsi_frac_second")) {
124  fieldno = daNANOSECOND;
125  } else if (boost::iequals(field, "weekday") || boost::iequals(field, "dw")) {
126  fieldno = daWEEKDAY;
127  } else if (boost::iequals(field, "decade") || boost::iequals(field, "dc")) {
128  fieldno = daDECADE;
129  } else {
130  throw std::runtime_error("Unsupported field in DATEADD function: " + field);
131  }
132  return fieldno;
133 }
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:

◆ to_datediff_field()

DatetruncField to_datediff_field ( const std::string &  )

Definition at line 135 of file CalciteDeserializerUtils.cpp.

References dtDAY, dtHOUR, dtMICROSECOND, dtMILLISECOND, dtMINUTE, dtMONTH, dtNANOSECOND, dtQUARTER, dtSECOND, dtWEEK, and dtYEAR.

Referenced by to_sql_type(), RelAlgTranslator::translateDatediff(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateDatediff().

135  {
136  DatetruncField fieldno;
137  if (boost::iequals(field, "year") || boost::iequals(field, "yy") ||
138  boost::iequals(field, "yyyy")) {
139  fieldno = dtYEAR;
140  } else if (boost::iequals(field, "quarter") || boost::iequals(field, "qq") ||
141  boost::iequals(field, "q")) {
142  fieldno = dtQUARTER;
143  } else if (boost::iequals(field, "month") || boost::iequals(field, "mm") ||
144  boost::iequals(field, "m")) {
145  fieldno = dtMONTH;
146  } else if (boost::iequals(field, "week") || boost::iequals(field, "ww") ||
147  boost::iequals(field, "w")) {
148  fieldno = dtWEEK;
149  } else if (boost::iequals(field, "day") || boost::iequals(field, "dd") ||
150  boost::iequals(field, "d")) {
151  fieldno = dtDAY;
152  } else if (boost::iequals(field, "hour") || boost::iequals(field, "hh")) {
153  fieldno = dtHOUR;
154  } else if (boost::iequals(field, "minute") || boost::iequals(field, "mi") ||
155  boost::iequals(field, "n")) {
156  fieldno = dtMINUTE;
157  } else if (boost::iequals(field, "second") || boost::iequals(field, "ss") ||
158  boost::iequals(field, "s")) {
159  fieldno = dtSECOND;
160  } else if (boost::iequals(field, "millisecond") || boost::iequals(field, "ms")) {
161  fieldno = dtMILLISECOND;
162  } else if (boost::iequals(field, "microsecond") || boost::iequals(field, "us")) {
163  fieldno = dtMICROSECOND;
164  } else if (boost::iequals(field, "nanosecond") || boost::iequals(field, "ns")) {
165  fieldno = dtNANOSECOND;
166  } else {
167  throw std::runtime_error("Unsupported field in DATEDIFF function: " + field);
168  }
169  return fieldno;
170 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
DatetruncField
Definition: DateTruncate.h:42
+ Here is the caller graph for this function:

◆ to_datepart_field()

ExtractField to_datepart_field ( const std::string &  )

Definition at line 49 of file CalciteDeserializerUtils.cpp.

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

Referenced by to_sql_type(), RelAlgTranslator::translateDatepart(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateDatepart().

49  {
50  ExtractField fieldno;
51  if (boost::iequals(field, "year") || boost::iequals(field, "yy") ||
52  boost::iequals(field, "yyyy")) {
53  fieldno = kYEAR;
54  } else if (boost::iequals(field, "quarter") || boost::iequals(field, "qq") ||
55  boost::iequals(field, "q")) {
56  fieldno = kQUARTER;
57  } else if (boost::iequals(field, "month") || boost::iequals(field, "mm") ||
58  boost::iequals(field, "m")) {
59  fieldno = kMONTH;
60  } else if (boost::iequals(field, "dayofyear") || boost::iequals(field, "dy") ||
61  boost::iequals(field, "y")) {
62  fieldno = kDOY;
63  } else if (boost::iequals(field, "day") || boost::iequals(field, "dd") ||
64  boost::iequals(field, "d")) {
65  fieldno = kDAY;
66  } else if (boost::iequals(field, "hour") || boost::iequals(field, "hh")) {
67  fieldno = kHOUR;
68  } else if (boost::iequals(field, "minute") || boost::iequals(field, "mi") ||
69  boost::iequals(field, "n")) {
70  fieldno = kMINUTE;
71  } else if (boost::iequals(field, "second") || boost::iequals(field, "ss") ||
72  boost::iequals(field, "s")) {
73  fieldno = kSECOND;
74  } else if (boost::iequals(field, "millisecond") || boost::iequals(field, "ms")) {
75  fieldno = kMILLISECOND;
76  } else if (boost::iequals(field, "microsecond") || boost::iequals(field, "us")) {
77  fieldno = kMICROSECOND;
78  } else if (boost::iequals(field, "nanosecond") || boost::iequals(field, "ns")) {
79  fieldno = kNANOSECOND;
80  } else if (boost::iequals(field, "weekday") || boost::iequals(field, "dw")) {
81  fieldno = kISODOW;
82  } else if (boost::iequals(field, "quarterday") || boost::iequals(field, "dq")) {
83  fieldno = kQUARTERDAY;
84  } else {
85  throw std::runtime_error("Unsupported field in DATEPART function: " + field);
86  }
87  return fieldno;
88 }
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:

◆ to_sql_op()

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{RelAlgAbstractInterpreter.cpp}::parse_operator(), anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateOp(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateUnaryOp().

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:

◆ to_sql_type()

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

Definition at line 119 of file CalciteDeserializerUtils.h.

References get_agg_type(), kARRAY, kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kEVAL_CONTEXT_TYPE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNULLT, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, make_fp_constant(), to_dateadd_field(), to_datediff_field(), and to_datepart_field().

Referenced by anonymous_namespace{CalciteAdapter.cpp}::parse_literal(), anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_literal(), anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_type(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateUnaryOp().

119  {
120  if (type_name == std::string("BIGINT")) {
121  return kBIGINT;
122  }
123  if (type_name == std::string("INTEGER")) {
124  return kINT;
125  }
126  if (type_name == std::string("TINYINT")) {
127  return kTINYINT;
128  }
129  if (type_name == std::string("SMALLINT")) {
130  return kSMALLINT;
131  }
132  if (type_name == std::string("FLOAT")) {
133  return kFLOAT;
134  }
135  if (type_name == std::string("DOUBLE")) {
136  return kDOUBLE;
137  }
138  if (type_name == std::string("DECIMAL")) {
139  return kDECIMAL;
140  }
141  if (type_name == std::string("CHAR") || type_name == std::string("VARCHAR")) {
142  return kTEXT;
143  }
144  if (type_name == std::string("BOOLEAN")) {
145  return kBOOLEAN;
146  }
147  if (type_name == std::string("TIMESTAMP")) {
148  return kTIMESTAMP;
149  }
150  if (type_name == std::string("DATE")) {
151  return kDATE;
152  }
153  if (type_name == std::string("TIME")) {
154  return kTIME;
155  }
156  if (type_name == std::string("NULL")) {
157  return kNULLT;
158  }
159  if (type_name == std::string("ARRAY")) {
160  return kARRAY;
161  }
162  if (type_name == std::string("INTERVAL_DAY") ||
163  type_name == std::string("INTERVAL_HOUR") ||
164  type_name == std::string("INTERVAL_MINUTE") ||
165  type_name == std::string("INTERVAL_SECOND")) {
166  return kINTERVAL_DAY_TIME;
167  }
168  if (type_name == std::string("INTERVAL_MONTH") ||
169  type_name == std::string("INTERVAL_YEAR")) {
170  return kINTERVAL_YEAR_MONTH;
171  }
172  if (type_name == std::string("ANY")) {
173  return kEVAL_CONTEXT_TYPE;
174  }
175 
176  throw std::runtime_error("Unsupported type: " + type_name);
177 }
Definition: sqltypes.h:51
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function: