19 #include <boost/algorithm/string.hpp>
60 return "week_saturday";
102 return "week_sunday";
104 return "week_saturday";
116 if (boost::iequals(field,
"year")) {
118 }
else if (boost::iequals(field,
"quarter")) {
120 }
else if (boost::iequals(field,
"month")) {
122 }
else if (boost::iequals(field,
"day")) {
124 }
else if (boost::iequals(field,
"quarterday")) {
126 }
else if (boost::iequals(field,
"hour")) {
128 }
else if (boost::iequals(field,
"minute")) {
130 }
else if (boost::iequals(field,
"second")) {
132 }
else if (boost::iequals(field,
"millisecond")) {
134 }
else if (boost::iequals(field,
"microsecond")) {
136 }
else if (boost::iequals(field,
"nanosecond")) {
138 }
else if (boost::iequals(field,
"dow")) {
140 }
else if (boost::iequals(field,
"isodow")) {
142 }
else if (boost::iequals(field,
"doy")) {
144 }
else if (boost::iequals(field,
"epoch")) {
146 }
else if (boost::iequals(field,
"week")) {
148 }
else if (boost::iequals(field,
"week_sunday")) {
150 }
else if (boost::iequals(field,
"week_saturday")) {
152 }
else if (boost::iequals(field,
"dateepoch")) {
155 throw std::runtime_error(
"Unsupported field in EXTRACT function " + field);
161 const std::shared_ptr<Analyzer::Expr> from_expr,
162 const std::string& field_name) {
168 const std::shared_ptr<Analyzer::Expr> from_expr,
170 const auto expr_ti = from_expr->get_type_info();
171 if (!expr_ti.is_time()) {
172 throw std::runtime_error(
173 "Only TIME, TIMESTAMP and DATE types can be in EXTRACT function.");
182 if (constant !=
nullptr) {
185 ?
floor_div(constant->get_constval().bigintval,
188 constant->get_constval().bigintval,
field, expr_ti);
189 constant->set_constval(d);
190 constant->set_type_info(ti);
193 return makeExpr<Analyzer::ExtractExpr>(
194 ti, from_expr->get_contains_agg(),
field, from_expr->decompress());
199 if (boost::iequals(field,
"year")) {
201 }
else if (boost::iequals(field,
"quarter")) {
203 }
else if (boost::iequals(field,
"month")) {
205 }
else if (boost::iequals(field,
"quarterday")) {
207 }
else if (boost::iequals(field,
"day")) {
209 }
else if (boost::iequals(field,
"hour")) {
211 }
else if (boost::iequals(field,
"minute")) {
213 }
else if (boost::iequals(field,
"second")) {
215 }
else if (boost::iequals(field,
"millennium")) {
217 }
else if (boost::iequals(field,
"century")) {
219 }
else if (boost::iequals(field,
"decade")) {
221 }
else if (boost::iequals(field,
"millisecond")) {
223 }
else if (boost::iequals(field,
"microsecond")) {
225 }
else if (boost::iequals(field,
"nanosecond")) {
227 }
else if (boost::iequals(field,
"week")) {
229 }
else if (boost::iequals(field,
"week_sunday")) {
231 }
else if (boost::iequals(field,
"week_saturday")) {
234 throw std::runtime_error(
"Invalid field in DATE_TRUNC function " + field);
240 const std::shared_ptr<Analyzer::Expr> from_expr,
241 const std::string& field_name) {
247 const std::shared_ptr<Analyzer::Expr> from_expr,
249 const auto& expr_ti = from_expr->get_type_info();
250 if (!expr_ti.is_time()) {
251 throw std::runtime_error(
252 "Only TIME, TIMESTAMP and DATE types can be in DATE_TRUNC function.");
254 if (from_expr->get_type_info().get_type() ==
kTIME && field !=
dtHOUR &&
265 constant->set_constval(d);
266 constant->set_type_info(ti);
269 return makeExpr<Analyzer::DatetruncExpr>(
270 ti, from_expr->get_contains_agg(),
field, from_expr->decompress());
static int64_t getExtractFromTimeConstantValue(const int64_t &timeval, const ExtractField &field, const SQLTypeInfo &ti)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
std::string from_extract_field(const ExtractField &fieldno)
std::string from_datetrunc_field(const DatetruncField &fieldno)
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
static int64_t getDateTruncConstantValue(const int64_t &timeval, const DatetruncField &field, const SQLTypeInfo &ti)
static DatetruncField to_datetrunc_field(const std::string &field)
const std::shared_ptr< Analyzer::Expr > generate() const