OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalciteDeserializerUtils.cpp File Reference
#include "CalciteDeserializerUtils.h"
#include "../Analyzer/Analyzer.h"
#include "Logger/Logger.h"
#include <boost/algorithm/string.hpp>
+ Include dependency graph for CalciteDeserializerUtils.cpp:

Go to the source code of this file.

Functions

SQLTypeInfo get_agg_type (const SQLAgg agg_kind, const Analyzer::Expr *arg_expr)
 
ExtractField to_datepart_field (const std::string &field)
 
DateaddField to_dateadd_field (const std::string &field)
 
DatetruncField to_datediff_field (const std::string &field)
 
std::shared_ptr
< Analyzer::Constant
make_fp_constant (const int64_t val, const SQLTypeInfo &ti)
 

Variables

bool g_bigint_count
 

Function Documentation

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

Definition at line 26 of file CalciteDeserializerUtils.cpp.

References 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, kCOUNT_IF, kDOUBLE, kINT, kMAX, kMIN, kMODE, kSAMPLE, kSINGLE_VALUE, kSUM, kSUM_IF, and UNREACHABLE.

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

26  {
27  switch (agg_kind) {
28  case kCOUNT:
29  case kCOUNT_IF:
30  return SQLTypeInfo(g_bigint_count ? kBIGINT : kINT, false);
31  case kMIN:
32  case kMAX:
33  return arg_expr->get_type_info();
34  case kSUM:
35  case kSUM_IF:
36  return arg_expr->get_type_info().is_integer() ? SQLTypeInfo(kBIGINT, false)
37  : arg_expr->get_type_info();
38  case kAVG:
39  return SQLTypeInfo(kDOUBLE, false);
41  return SQLTypeInfo(kBIGINT, false);
42  case kAPPROX_QUANTILE:
43  return SQLTypeInfo(kDOUBLE, false);
44  case kSINGLE_VALUE:
45  if (arg_expr->get_type_info().is_varlen()) {
46  throw std::runtime_error("SINGLE_VALUE not supported on '" +
47  arg_expr->get_type_info().get_type_name() + "' input.");
48  } // else fall through
49  case kSAMPLE:
50  case kMODE:
51  return arg_expr->get_type_info();
52  default:
53  UNREACHABLE() << "Unsupported agg_kind: " << agg_kind;
54  return {};
55  }
56 }
bool is_varlen() const
Definition: sqltypes.h:620
#define UNREACHABLE()
Definition: Logger.h:337
Definition: sqldefs.h:75
bool is_integer() const
Definition: sqltypes.h:582
bool g_bigint_count
Definition: sqldefs.h:77
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
Definition: sqldefs.h:78
std::string get_type_name() const
Definition: sqltypes.h:507
Definition: sqltypes.h:62
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:83

+ 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 212 of file CalciteDeserializerUtils.cpp.

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

Referenced by RelAlgTranslator::translateLiteral().

213  {
214  Datum d;
215  switch (ti.get_type()) {
216  case kFLOAT:
217  d.floatval = val;
218  break;
219  case kDOUBLE:
220  d.doubleval = val;
221  break;
222  default:
223  CHECK(false);
224  }
225  return makeExpr<Analyzer::Constant>(ti, false, d);
226 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
float floatval
Definition: Datum.h:73
#define CHECK(condition)
Definition: Logger.h:291
Definition: Datum.h:67
double doubleval
Definition: Datum.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DateaddField to_dateadd_field ( const std::string &  field)

Definition at line 110 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(), and RelAlgTranslator::translateIntervalExprForWindowFraming().

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

Definition at line 159 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().

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

Definition at line 58 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().

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

Variable Documentation