OmniSciDB  a5dc49c757
 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  return SQLTypeInfo(g_bigint_count ? kBIGINT : kINT, true);
30  case kCOUNT_IF:
31  return SQLTypeInfo(g_bigint_count ? kBIGINT : kINT, false);
32  case kMIN:
33  case kMAX:
34  return arg_expr->get_type_info();
35  case kSUM:
36  case kSUM_IF:
37  return arg_expr->get_type_info().is_integer() ? SQLTypeInfo(kBIGINT, false)
38  : arg_expr->get_type_info();
39  case kAVG:
40  return SQLTypeInfo(kDOUBLE, false);
42  return SQLTypeInfo(kBIGINT, true);
43  case kAPPROX_QUANTILE:
44  return SQLTypeInfo(kDOUBLE, false);
45  case kSINGLE_VALUE:
46  if (arg_expr->get_type_info().is_varlen()) {
47  throw std::runtime_error("SINGLE_VALUE not supported on '" +
48  arg_expr->get_type_info().get_type_name() + "' input.");
49  } // else fall through
50  case kSAMPLE:
51  case kMODE:
52  return arg_expr->get_type_info();
53  default:
54  UNREACHABLE() << "Unsupported agg_kind: " << agg_kind;
55  return {};
56  }
57 }
bool is_varlen() const
Definition: sqltypes.h:631
#define UNREACHABLE()
Definition: Logger.h:338
Definition: sqldefs.h:78
bool is_integer() const
Definition: sqltypes.h:567
bool g_bigint_count
Definition: sqldefs.h:80
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
Definition: sqldefs.h:81
std::string get_type_name() const
Definition: sqltypes.h:484
Definition: sqltypes.h:72
Definition: sqldefs.h:79
Definition: sqldefs.h:77
Definition: sqldefs.h:86

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

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

Referenced by RelAlgTranslator::translateLiteral().

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

+ 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 111 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().

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

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

+ Here is the caller graph for this function:

ExtractField to_datepart_field ( const std::string &  field)

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

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

+ Here is the caller graph for this function:

Variable Documentation