OmniSciDB  dfae7c3b14
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::Constantmake_fp_constant (const int64_t val, const SQLTypeInfo &ti)
 

Variables

bool g_bigint_count
 

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

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation(), to_sql_type(), 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 kSINGLE_VALUE:
41  if (arg_expr->get_type_info().is_varlen()) {
42  throw std::runtime_error("SINGLE_VALUE not supported on '" +
43  arg_expr->get_type_info().get_type_name() + "' input.");
44  }
45  case kSAMPLE:
46  return arg_expr->get_type_info();
47  default:
48  CHECK(false);
49  }
50  CHECK(false);
51  return SQLTypeInfo();
52 }
bool is_integer() const
Definition: sqltypes.h:419
bool is_varlen() const
Definition: sqltypes.h:432
Definition: sqldefs.h:73
bool g_bigint_count
Definition: sqldefs.h:75
std::string get_type_name() const
Definition: sqltypes.h:362
Definition: sqldefs.h:76
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
#define CHECK(condition)
Definition: Logger.h:197
Definition: sqltypes.h:47
Definition: sqldefs.h:74
Definition: sqldefs.h:72
+ 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 200 of file CalciteDeserializerUtils.cpp.

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

Referenced by to_sql_type(), and RelAlgTranslator::translateLiteral().

201  {
202  Datum d;
203  switch (ti.get_type()) {
204  case kFLOAT:
205  d.floatval = val;
206  break;
207  case kDOUBLE:
208  d.doubleval = val;
209  break;
210  default:
211  CHECK(false);
212  }
213  return makeExpr<Analyzer::Constant>(ti, false, d);
214 }
float floatval
Definition: sqltypes.h:139
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
double doubleval
Definition: sqltypes.h:140
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_dateadd_field()

DateaddField to_dateadd_field ( const std::string &  field)

Definition at line 102 of file CalciteDeserializerUtils.cpp.

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

Referenced by to_sql_type(), and RelAlgTranslator::translateDateadd().

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

Definition at line 151 of file CalciteDeserializerUtils.cpp.

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

Referenced by to_sql_type(), and RelAlgTranslator::translateDatediff().

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

◆ to_datepart_field()

ExtractField to_datepart_field ( const std::string &  field)

Definition at line 54 of file CalciteDeserializerUtils.cpp.

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

Referenced by to_sql_type(), and RelAlgTranslator::translateDatepart().

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

◆ g_bigint_count