OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExpressionRange.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "ExpressionRange.h"
18 #include "DateTimeTranslator.h"
19 #include "DateTimeUtils.h"
20 #include "DateTruncate.h"
22 #include "Execute.h"
23 #include "ExtractFromTime.h"
24 #include "GroupByAndAggregate.h"
26 
27 #include <algorithm>
28 #include <cfenv>
29 #include <cmath>
30 
31 #define DEF_OPERATOR(fname, op) \
32  ExpressionRange fname(const ExpressionRange& other) const { \
33  if (type_ == ExpressionRangeType::Invalid || \
34  other.type_ == ExpressionRangeType::Invalid) { \
35  return ExpressionRange::makeInvalidRange(); \
36  } \
37  CHECK(type_ == other.type_); \
38  switch (type_) { \
39  case ExpressionRangeType::Integer: \
40  return binOp<int64_t>(other, [](const int64_t x, const int64_t y) { \
41  return int64_t(checked_int64_t(x) op y); \
42  }); \
43  case ExpressionRangeType::Float: \
44  return binOp<float>(other, [](const float x, const float y) { \
45  std::feclearexcept(FE_OVERFLOW); \
46  std::feclearexcept(FE_UNDERFLOW); \
47  auto result = x op y; \
48  if (std::fetestexcept(FE_OVERFLOW) || std::fetestexcept(FE_UNDERFLOW)) { \
49  throw std::runtime_error("overflow / underflow"); \
50  } \
51  return result; \
52  }); \
53  case ExpressionRangeType::Double: \
54  return binOp<double>(other, [](const double x, const double y) { \
55  std::feclearexcept(FE_OVERFLOW); \
56  std::feclearexcept(FE_UNDERFLOW); \
57  auto result = x op y; \
58  if (std::fetestexcept(FE_OVERFLOW) || std::fetestexcept(FE_UNDERFLOW)) { \
59  throw std::runtime_error("overflow / underflow"); \
60  } \
61  return result; \
62  }); \
63  default: \
64  CHECK(false); \
65  } \
66  CHECK(false); \
67  return ExpressionRange::makeInvalidRange(); \
68  }
69 
70 DEF_OPERATOR(ExpressionRange::operator+, +)
71 DEF_OPERATOR(ExpressionRange::operator-, -)
72 DEF_OPERATOR(ExpressionRange::operator*, *)
73 
74 void apply_fp_qual(const Datum const_datum,
75  const SQLTypes const_type,
76  const SQLOps sql_op,
77  ExpressionRange& qual_range) {
78  double const_val = get_value_from_datum<double>(const_datum, const_type);
79  switch (sql_op) {
80  case kGT:
81  case kGE:
82  qual_range.setFpMin(std::max(qual_range.getFpMin(), const_val));
83  break;
84  case kLT:
85  case kLE:
86  qual_range.setFpMax(std::min(qual_range.getFpMax(), const_val));
87  break;
88  case kEQ:
89  qual_range.setFpMin(std::max(qual_range.getFpMin(), const_val));
90  qual_range.setFpMax(std::min(qual_range.getFpMax(), const_val));
91  break;
92  default: // there may be other operators, but don't do anything with them
93  break;
94  }
95 }
96 
97 void apply_int_qual(const Datum const_datum,
98  const SQLTypes const_type,
99  const SQLOps sql_op,
100  ExpressionRange& qual_range) {
101  int64_t const_val = get_value_from_datum<int64_t>(const_datum, const_type);
102  switch (sql_op) {
103  case kGT:
104  qual_range.setIntMin(std::max(qual_range.getIntMin(), const_val + 1));
105  break;
106  case kGE:
107  qual_range.setIntMin(std::max(qual_range.getIntMin(), const_val));
108  break;
109  case kLT:
110  qual_range.setIntMax(std::min(qual_range.getIntMax(), const_val - 1));
111  break;
112  case kLE:
113  qual_range.setIntMax(std::min(qual_range.getIntMax(), const_val));
114  break;
115  case kEQ:
116  qual_range.setIntMin(std::max(qual_range.getIntMin(), const_val));
117  qual_range.setIntMax(std::min(qual_range.getIntMax(), const_val));
118  break;
119  default: // there may be other operators, but don't do anything with them
120  break;
121  }
122 }
123 
124 void apply_hpt_qual(const Datum const_datum,
125  const SQLTypes const_type,
126  const int32_t const_dimen,
127  const int32_t col_dimen,
128  const SQLOps sql_op,
129  ExpressionRange& qual_range) {
130  CHECK(const_dimen != col_dimen);
131  Datum datum{0};
132  if (const_dimen > col_dimen) {
133  datum.bigintval =
134  get_value_from_datum<int64_t>(const_datum, const_type) /
135  DateTimeUtils::get_timestamp_precision_scale(const_dimen - col_dimen);
136  } else {
137  datum.bigintval =
138  get_value_from_datum<int64_t>(const_datum, const_type) *
139  DateTimeUtils::get_timestamp_precision_scale(col_dimen - const_dimen);
140  }
141  apply_int_qual(datum, const_type, sql_op, qual_range);
142 }
143 
145  const Analyzer::ColumnVar* col_expr,
146  const ExpressionRange& col_range,
147  const boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
148  if (!simple_quals) {
149  return col_range;
150  }
151  ExpressionRange qual_range(col_range);
152  for (auto const& itr : simple_quals.get()) {
153  auto qual_bin_oper = dynamic_cast<Analyzer::BinOper*>(itr.get());
154  if (!qual_bin_oper) {
155  continue;
156  }
157  const Analyzer::Expr* left_operand = qual_bin_oper->get_left_operand();
158  auto qual_col = dynamic_cast<const Analyzer::ColumnVar*>(left_operand);
159  if (!qual_col) {
160  // Check for possibility that column is wrapped in a cast
161  // Presumes that only simple casts (i.e. timestamp to timestamp or int to int) have
162  // been passed through by BinOper::normalize_simple_predicate
163  auto u_expr = dynamic_cast<const Analyzer::UOper*>(left_operand);
164  if (!u_expr) {
165  continue;
166  }
167  qual_col = dynamic_cast<const Analyzer::ColumnVar*>(u_expr->get_operand());
168  if (!qual_col) {
169  continue;
170  }
171  }
172  if (qual_col->get_table_id() != col_expr->get_table_id() ||
173  qual_col->get_column_id() != col_expr->get_column_id()) {
174  continue;
175  }
176  const Analyzer::Expr* right_operand = qual_bin_oper->get_right_operand();
177  auto qual_const = dynamic_cast<const Analyzer::Constant*>(right_operand);
178  if (!qual_const) {
179  continue;
180  }
181  if (qual_range.getType() == ExpressionRangeType::Float ||
182  qual_range.getType() == ExpressionRangeType::Double) {
183  apply_fp_qual(qual_const->get_constval(),
184  qual_const->get_type_info().get_type(),
185  qual_bin_oper->get_optype(),
186  qual_range);
187  } else if ((qual_col->get_type_info().is_timestamp() ||
188  qual_const->get_type_info().is_timestamp()) &&
189  (qual_col->get_type_info().get_dimension() !=
190  qual_const->get_type_info().get_dimension())) {
191  apply_hpt_qual(qual_const->get_constval(),
192  qual_const->get_type_info().get_type(),
193  qual_const->get_type_info().get_dimension(),
194  qual_col->get_type_info().get_dimension(),
195  qual_bin_oper->get_optype(),
196  qual_range);
197  } else {
198  apply_int_qual(qual_const->get_constval(),
199  qual_const->get_type_info().get_type(),
200  qual_bin_oper->get_optype(),
201  qual_range);
202  }
203  }
204  return qual_range;
205 }
206 
211  }
212  if (other.int_min_ * other.int_max_ <= 0) {
213  // if the other interval contains 0, the rule is more complicated;
214  // punt for now, we can revisit by splitting the other interval and
215  // taking the convex hull of the resulting two intervals
217  }
218  auto div_range = binOp<int64_t>(other, [](const int64_t x, const int64_t y) {
219  return int64_t(checked_int64_t(x) / y);
220  });
221  if (g_null_div_by_zero) {
222  div_range.setHasNulls();
223  }
224  return div_range;
225 }
226 
228  if (type_ != other.type_) {
230  }
232  switch (type_) {
237  result.has_nulls_ = has_nulls_ || other.has_nulls_;
238  result.int_min_ = std::min(int_min_, other.int_min_);
239  result.int_max_ = std::max(int_max_, other.int_max_);
240  result.bucket_ = std::min(bucket_, other.bucket_);
241  break;
242  }
245  result.type_ = type_;
246  result.has_nulls_ = has_nulls_ || other.has_nulls_;
247  result.fp_min_ = std::min(fp_min_, other.fp_min_);
248  result.fp_max_ = std::max(fp_max_, other.fp_max_);
249  break;
250  }
251  default:
252  CHECK(false);
253  }
254  return result;
255 }
256 
258  if (type_ != other.type_) {
259  return false;
260  }
261  switch (type_) {
263  return true;
265  return has_nulls_ == other.has_nulls_ && int_min_ == other.int_min_ &&
266  int_max_ == other.int_max_;
267  }
270  return has_nulls_ == other.has_nulls_ && fp_min_ == other.fp_min_ &&
271  fp_max_ == other.fp_max_;
272  }
273  default:
274  CHECK(false);
275  }
276  return false;
277 }
278 
280  if (ti.is_array()) {
281  return typeSupportsRange(ti.get_elem_type());
282  } else {
283  return (ti.is_number() || ti.is_boolean() || ti.is_time() ||
284  (ti.is_string() && ti.get_compression() == kENCODING_DICT));
285  }
286 }
287 
289  const Analyzer::BinOper* expr,
290  const std::vector<InputTableInfo>& query_infos,
291  const Executor*,
292  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals);
293 
295 
297  const Analyzer::ColumnVar* col_expr,
298  const std::vector<InputTableInfo>& query_infos,
299  const Executor* executor,
300  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals);
301 
303  const Executor* executor);
304 
306 
308  const std::vector<InputTableInfo>& query_infos,
309  const Executor*);
310 
312  const Analyzer::UOper* u_expr,
313  const std::vector<InputTableInfo>& query_infos,
314  const Executor*,
315  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals);
316 
318  const Analyzer::ExtractExpr* extract_expr,
319  const std::vector<InputTableInfo>& query_infos,
320  const Executor*,
321  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals);
322 
324  const Analyzer::DatetruncExpr* datetrunc_expr,
325  const std::vector<InputTableInfo>& query_infos,
326  const Executor* executor,
327  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals);
328 
331  const std::vector<InputTableInfo>& query_infos,
332  const Executor* executor,
333  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals);
334 
336  const Analyzer::Expr* expr,
337  const std::vector<InputTableInfo>& query_infos,
338  const Executor* executor,
339  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
342  } else if (auto bin_oper_expr = dynamic_cast<const Analyzer::BinOper*>(expr)) {
343  return getExpressionRange(bin_oper_expr, query_infos, executor, simple_quals);
344  } else if (auto constant_expr = dynamic_cast<const Analyzer::Constant*>(expr)) {
345  return getExpressionRange(constant_expr);
346  } else if (auto column_var_expr = dynamic_cast<const Analyzer::ColumnVar*>(expr)) {
347  return getExpressionRange(column_var_expr, query_infos, executor, simple_quals);
348  } else if (auto string_oper_expr = dynamic_cast<const Analyzer::StringOper*>(expr)) {
349  return getExpressionRange(string_oper_expr, executor);
350  } else if (auto like_expr = dynamic_cast<const Analyzer::LikeExpr*>(expr)) {
351  return getExpressionRange(like_expr);
352  } else if (auto case_expr = dynamic_cast<const Analyzer::CaseExpr*>(expr)) {
353  return getExpressionRange(case_expr, query_infos, executor);
354  } else if (auto u_expr = dynamic_cast<const Analyzer::UOper*>(expr)) {
355  return getExpressionRange(u_expr, query_infos, executor, simple_quals);
356  } else if (auto extract_expr = dynamic_cast<const Analyzer::ExtractExpr*>(expr)) {
357  return getExpressionRange(extract_expr, query_infos, executor, simple_quals);
358  } else if (auto datetrunc_expr = dynamic_cast<const Analyzer::DatetruncExpr*>(expr)) {
359  return getExpressionRange(datetrunc_expr, query_infos, executor, simple_quals);
360  } else if (auto width_expr = dynamic_cast<const Analyzer::WidthBucketExpr*>(expr)) {
361  return getExpressionRange(width_expr, query_infos, executor, simple_quals);
362  }
364 }
365 
366 namespace {
367 
368 int64_t scale_up_interval_endpoint(const int64_t endpoint, const SQLTypeInfo& ti) {
369  return endpoint * static_cast<int64_t>(exp_to_scale(ti.get_scale()));
370 }
371 
372 } // namespace
373 
375  const Analyzer::BinOper* expr,
376  const std::vector<InputTableInfo>& query_infos,
377  const Executor* executor,
378  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
379  const auto& lhs =
380  getExpressionRange(expr->get_left_operand(), query_infos, executor, simple_quals);
381  const auto& rhs =
382  getExpressionRange(expr->get_right_operand(), query_infos, executor, simple_quals);
383  switch (expr->get_optype()) {
384  case kPLUS:
385  return lhs + rhs;
386  case kMINUS:
387  return lhs - rhs;
388  case kMULTIPLY:
389  return lhs * rhs;
390  case kDIVIDE: {
391  const auto& lhs_type = expr->get_left_operand()->get_type_info();
392  if (lhs_type.is_decimal() && lhs.getType() != ExpressionRangeType::Invalid) {
393  CHECK(lhs.getType() == ExpressionRangeType::Integer);
394  const auto adjusted_lhs = ExpressionRange::makeIntRange(
395  scale_up_interval_endpoint(lhs.getIntMin(), lhs_type),
396  scale_up_interval_endpoint(lhs.getIntMax(), lhs_type),
397  0,
398  lhs.hasNulls());
399  return adjusted_lhs / rhs;
400  }
401  return lhs / rhs;
402  }
403  default:
404  break;
405  }
407 }
408 
410  if (constant_expr->get_is_null()) {
412  }
413  const auto constant_type = constant_expr->get_type_info().get_type();
414  const auto datum = constant_expr->get_constval();
415  switch (constant_type) {
416  case kTINYINT: {
417  const int64_t v = datum.tinyintval;
418  return ExpressionRange::makeIntRange(v, v, 0, false);
419  }
420  case kSMALLINT: {
421  const int64_t v = datum.smallintval;
422  return ExpressionRange::makeIntRange(v, v, 0, false);
423  }
424  case kINT: {
425  const int64_t v = datum.intval;
426  return ExpressionRange::makeIntRange(v, v, 0, false);
427  }
428  case kBIGINT:
429  case kNUMERIC:
430  case kDECIMAL: {
431  const int64_t v = datum.bigintval;
432  return ExpressionRange::makeIntRange(v, v, 0, false);
433  }
434  case kTIME:
435  case kTIMESTAMP:
436  case kDATE: {
437  const int64_t v = datum.bigintval;
438  return ExpressionRange::makeIntRange(v, v, 0, false);
439  }
440  case kFLOAT: {
441  return ExpressionRange::makeFloatRange(datum.floatval, datum.floatval, false);
442  }
443  case kDOUBLE: {
444  return ExpressionRange::makeDoubleRange(datum.doubleval, datum.doubleval, false);
445  }
446  default:
447  break;
448  }
450 }
451 
452 #define FIND_STAT_FRAG(stat_name) \
453  const auto stat_name##_frag_index = std::stat_name##_element( \
454  nonempty_fragment_indices.begin(), \
455  nonempty_fragment_indices.end(), \
456  [&fragments, &has_nulls, col_id, col_ti](const size_t lhs_idx, \
457  const size_t rhs_idx) { \
458  const auto& lhs = fragments[lhs_idx]; \
459  const auto& rhs = fragments[rhs_idx]; \
460  auto lhs_meta_it = lhs.getChunkMetadataMap().find(col_id); \
461  if (lhs_meta_it == lhs.getChunkMetadataMap().end()) { \
462  return false; \
463  } \
464  auto rhs_meta_it = rhs.getChunkMetadataMap().find(col_id); \
465  CHECK(rhs_meta_it != rhs.getChunkMetadataMap().end()); \
466  if (lhs_meta_it->second->chunkStats.has_nulls || \
467  rhs_meta_it->second->chunkStats.has_nulls) { \
468  has_nulls = true; \
469  } \
470  if (col_ti.is_fp()) { \
471  return extract_##stat_name##_stat_fp_type(lhs_meta_it->second->chunkStats, \
472  col_ti) < \
473  extract_##stat_name##_stat_fp_type(rhs_meta_it->second->chunkStats, \
474  col_ti); \
475  } \
476  return extract_##stat_name##_stat_int_type(lhs_meta_it->second->chunkStats, \
477  col_ti) < \
478  extract_##stat_name##_stat_int_type(rhs_meta_it->second->chunkStats, \
479  col_ti); \
480  }); \
481  if (stat_name##_frag_index == nonempty_fragment_indices.end()) { \
482  return ExpressionRange::makeInvalidRange(); \
483  }
484 
485 namespace {
486 
487 int64_t get_conservative_datetrunc_bucket(const DatetruncField datetrunc_field) {
488  const int64_t day_seconds{24 * 3600};
489  const int64_t year_days{365};
490  switch (datetrunc_field) {
491  case dtYEAR:
492  return year_days * day_seconds;
493  case dtQUARTER:
494  return 90 * day_seconds; // 90 is least number of days in any quater
495  case dtMONTH:
496  return 28 * day_seconds;
497  case dtDAY:
498  return day_seconds;
499  case dtHOUR:
500  return 3600;
501  case dtMINUTE:
502  return 60;
503  case dtMILLENNIUM:
504  return 1000 * year_days * day_seconds;
505  case dtCENTURY:
506  return 100 * year_days * day_seconds;
507  case dtDECADE:
508  return 10 * year_days * day_seconds;
509  case dtWEEK:
510  case dtWEEK_SUNDAY:
511  case dtWEEK_SATURDAY:
512  return 7 * day_seconds;
513  case dtQUARTERDAY:
514  return 4 * 60 * 50;
515  default:
516  return 0;
517  }
518 }
519 
520 } // namespace
521 
523  const std::vector<InputTableInfo>& query_infos,
524  const Executor* executor,
525  const bool is_outer_join_proj) {
526  bool has_nulls = is_outer_join_proj;
527  int col_id = col_expr->get_column_id();
528  const auto& col_phys_ti = col_expr->get_type_info().is_array()
529  ? col_expr->get_type_info().get_elem_type()
530  : col_expr->get_type_info();
531  const auto col_ti = get_logical_type_info(col_phys_ti);
532  switch (col_ti.get_type()) {
533  case kTEXT:
534  case kCHAR:
535  case kVARCHAR:
536  CHECK_EQ(kENCODING_DICT, col_ti.get_compression());
537  case kBOOLEAN:
538  case kTINYINT:
539  case kSMALLINT:
540  case kINT:
541  case kBIGINT:
542  case kDECIMAL:
543  case kNUMERIC:
544  case kDATE:
545  case kTIMESTAMP:
546  case kTIME:
547  case kFLOAT:
548  case kDOUBLE: {
549  std::optional<size_t> ti_idx;
550  for (size_t i = 0; i < query_infos.size(); ++i) {
551  if (col_expr->get_table_id() == query_infos[i].table_id) {
552  ti_idx = i;
553  break;
554  }
555  }
556  CHECK(ti_idx);
557  const auto& query_info = query_infos[*ti_idx].info;
558  const auto& fragments = query_info.fragments;
559  const auto cd = executor->getColumnDescriptor(col_expr);
560  if (cd && cd->isVirtualCol) {
561  CHECK(cd->columnName == "rowid");
562  CHECK_EQ(kBIGINT, col_ti.get_type());
563  const int64_t num_tuples = query_info.getNumTuples();
565  0, std::max(num_tuples - 1, int64_t(0)), 0, has_nulls);
566  }
567  if (query_info.getNumTuples() == 0) {
568  // The column doesn't contain any values, synthesize an empty range.
569  if (col_ti.is_fp()) {
570  return col_ti.get_type() == kFLOAT
571  ? ExpressionRange::makeFloatRange(0, -1, false)
572  : ExpressionRange::makeDoubleRange(0, -1, false);
573  }
574  return ExpressionRange::makeIntRange(0, -1, 0, false);
575  }
576  std::vector<size_t> nonempty_fragment_indices;
577  for (size_t i = 0; i < fragments.size(); ++i) {
578  const auto& fragment = fragments[i];
579  if (!fragment.isEmptyPhysicalFragment()) {
580  nonempty_fragment_indices.push_back(i);
581  }
582  }
583  FIND_STAT_FRAG(min);
584  FIND_STAT_FRAG(max);
585  const auto& min_frag = fragments[*min_frag_index];
586  const auto min_it = min_frag.getChunkMetadataMap().find(col_id);
587  if (min_it == min_frag.getChunkMetadataMap().end()) {
589  }
590  const auto& max_frag = fragments[*max_frag_index];
591  const auto max_it = max_frag.getChunkMetadataMap().find(col_id);
592  CHECK(max_it != max_frag.getChunkMetadataMap().end());
593  for (const auto& fragment : fragments) {
594  const auto it = fragment.getChunkMetadataMap().find(col_id);
595  if (it != fragment.getChunkMetadataMap().end()) {
596  if (it->second->chunkStats.has_nulls) {
597  has_nulls = true;
598  break;
599  }
600  }
601  }
602 
603  // Detect FSI placeholder metadata. If we let this through it will be treated as an
604  // empty range, when it really implies an unknown range.
605  if (min_it->second->isPlaceholder() || max_it->second->isPlaceholder()) {
607  }
608 
609  if (col_ti.is_fp()) {
610  const auto min_val = extract_min_stat_fp_type(min_it->second->chunkStats, col_ti);
611  const auto max_val = extract_max_stat_fp_type(max_it->second->chunkStats, col_ti);
612  return col_ti.get_type() == kFLOAT
613  ? ExpressionRange::makeFloatRange(min_val, max_val, has_nulls)
614  : ExpressionRange::makeDoubleRange(min_val, max_val, has_nulls);
615  }
616  const auto min_val = extract_min_stat_int_type(min_it->second->chunkStats, col_ti);
617  const auto max_val = extract_max_stat_int_type(max_it->second->chunkStats, col_ti);
618  if (max_val < min_val) {
619  // The column doesn't contain any non-null values, synthesize an empty range.
620  CHECK_GT(min_val, 0);
621  return ExpressionRange::makeIntRange(0, -1, 0, has_nulls);
622  }
623  const int64_t bucket =
624  col_ti.get_type() == kDATE ? get_conservative_datetrunc_bucket(dtDAY) : 0;
625  return ExpressionRange::makeIntRange(min_val, max_val, bucket, has_nulls);
626  }
627  default:
628  break;
629  }
631 }
632 
633 #undef FIND_STAT_FRAG
634 
636  const Analyzer::ColumnVar* col_expr,
637  const std::vector<InputTableInfo>& query_infos,
638  const Executor* executor,
639  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
640  const int rte_idx = col_expr->get_rte_idx();
641  CHECK_GE(rte_idx, 0);
642  CHECK_LT(static_cast<size_t>(rte_idx), query_infos.size());
643  bool is_outer_join_proj = rte_idx > 0 && executor->containsLeftDeepOuterJoin();
644  if (col_expr->get_table_id() > 0) {
645  auto col_range = executor->getColRange(
646  PhysicalInput{col_expr->get_column_id(), col_expr->get_table_id()});
647  if (is_outer_join_proj) {
648  col_range.setHasNulls();
649  }
650  return apply_simple_quals(col_expr, col_range, simple_quals);
651  }
652  return getLeafColumnRange(col_expr, query_infos, executor, is_outer_join_proj);
653 }
654 
656  const Executor* executor) {
657  auto chained_string_op_exprs = string_oper_expr->getChainedStringOpExprs();
658  if (chained_string_op_exprs.empty()) {
659  throw std::runtime_error(
660  "StringOper getExpressionRange() Expected folded string operator but found "
661  "operator unfolded.");
662  }
663  // Consider encapsulating below in an Analyzer::StringOper method to dedup
664  std::vector<StringOps_Namespace::StringOpInfo> string_op_infos;
665  for (const auto& chained_string_op_expr : chained_string_op_exprs) {
666  auto chained_string_op =
667  dynamic_cast<const Analyzer::StringOper*>(chained_string_op_expr.get());
668  CHECK(chained_string_op);
669  StringOps_Namespace::StringOpInfo string_op_info(chained_string_op->get_kind(),
670  chained_string_op->getLiteralArgs());
671  string_op_infos.emplace_back(string_op_info);
672  }
673 
674  const auto string_oper_col_var_expr = remove_cast(string_oper_expr->getArg(0));
675  CHECK(string_oper_col_var_expr);
676  const auto string_oper_col_var =
677  dynamic_cast<const Analyzer::ColumnVar*>(string_oper_col_var_expr);
678  CHECK(string_oper_col_var);
679  const auto string_oper_col_var_ti = string_oper_col_var->get_type_info();
680  if (string_oper_col_var_ti.is_none_encoded_string()) {
681  // If here the translation is done on the fly so unless this
682  // was the result of a previous step, we won't have the translated
683  // dictionary yet. Just throw an invalid range.
685  }
686  CHECK(string_oper_col_var_ti.is_dict_encoded_string());
687 
688  const auto expr_ti = string_oper_expr->get_type_info();
689  CHECK(expr_ti.is_string());
690  const auto dict_id = expr_ti.get_comp_param();
691 
692  const auto translation_map = executor->getStringProxyTranslationMap(
693  dict_id,
694  dict_id,
696  string_op_infos,
697  executor->getRowSetMemoryOwner(),
698  true);
699 
700  // Todo(todd): Track null presence in StringDictionaryProxy::IdMap
701  return ExpressionRange::makeIntRange(translation_map->rangeStart(),
702  translation_map->rangeEnd() - 1,
703  0 /* bucket */,
704  true /* assume has nulls */);
705 }
706 
708  const auto& ti = like_expr->get_type_info();
709  CHECK(ti.is_boolean());
710  const auto& arg_ti = like_expr->get_arg()->get_type_info();
712  arg_ti.get_notnull() ? 0 : inline_int_null_val(ti), 1, 0, false);
713 }
714 
716  const std::vector<InputTableInfo>& query_infos,
717  const Executor* executor) {
718  const auto& expr_pair_list = case_expr->get_expr_pair_list();
719  auto expr_range = ExpressionRange::makeInvalidRange();
720  bool has_nulls = false;
721  for (const auto& expr_pair : expr_pair_list) {
722  CHECK_EQ(expr_pair.first->get_type_info().get_type(), kBOOLEAN);
723  const auto crt_range =
724  getExpressionRange(expr_pair.second.get(), query_infos, executor);
725  if (crt_range.getType() == ExpressionRangeType::Null) {
726  has_nulls = true;
727  continue;
728  }
729  if (crt_range.getType() == ExpressionRangeType::Invalid) {
731  }
732  expr_range = (expr_range.getType() != ExpressionRangeType::Invalid)
733  ? expr_range || crt_range
734  : crt_range;
735  }
736  if (has_nulls && !(expr_range.getType() == ExpressionRangeType::Invalid)) {
737  expr_range.setHasNulls();
738  }
739  const auto else_expr = case_expr->get_else_expr();
740  CHECK(else_expr);
741  const auto else_null_expr = dynamic_cast<const Analyzer::Constant*>(else_expr);
742  if (else_null_expr && else_null_expr->get_is_null()) {
743  expr_range.setHasNulls();
744  return expr_range;
745  }
746  return expr_range || getExpressionRange(else_expr, query_infos, executor);
747 }
748 
749 namespace {
750 
752  const int64_t scale,
753  const SQLTypeInfo& target_ti) {
754  CHECK(target_ti.is_fp());
755  if (target_ti.get_type() == kFLOAT) {
757  static_cast<float>(arg_range.getIntMin()) / scale,
758  static_cast<float>(arg_range.getIntMax()) / scale,
759  arg_range.hasNulls());
760  }
762  static_cast<double>(arg_range.getIntMin()) / scale,
763  static_cast<double>(arg_range.getIntMax()) / scale,
764  arg_range.hasNulls());
765 }
766 
768  const SQLTypeInfo& oper_ti,
769  const SQLTypeInfo& target_ti) {
770  if (oper_ti.is_timestamp() && target_ti.is_date()) {
771  const auto field = dtDAY;
772  const int64_t scale =
775  : 1;
776  const int64_t min_ts = oper_ti.is_high_precision_timestamp()
777  ? DateTruncate(field, arg_range.getIntMin() / scale)
778  : DateTruncate(field, arg_range.getIntMin());
779  const int64_t max_ts = oper_ti.is_high_precision_timestamp()
780  ? DateTruncate(field, arg_range.getIntMax() / scale)
781  : DateTruncate(field, arg_range.getIntMax());
782  const int64_t bucket = get_conservative_datetrunc_bucket(field);
783 
784  return ExpressionRange::makeIntRange(min_ts, max_ts, bucket, arg_range.hasNulls());
785  }
786 
787  if (oper_ti.is_timestamp() && target_ti.is_any(kTIME)) {
788  // The min and max TS wouldn't make sense here, so return a range covering the whole
789  // day
790  return ExpressionRange::makeIntRange(0, kSecsPerDay, 0, arg_range.hasNulls());
791  }
792 
793  const int32_t ti_dimen = target_ti.get_dimension();
794  const int32_t oper_dimen = oper_ti.get_dimension();
795  CHECK(oper_dimen != ti_dimen);
796  const int64_t min_ts =
797  ti_dimen > oper_dimen
799  arg_range.getIntMin(),
800  abs(oper_dimen - ti_dimen))
803  arg_range.getIntMin(),
804  abs(oper_dimen - ti_dimen));
805  const int64_t max_ts =
806  ti_dimen > oper_dimen
808  arg_range.getIntMax(),
809  abs(oper_dimen - ti_dimen))
812  arg_range.getIntMax(),
813  abs(oper_dimen - ti_dimen));
814 
815  return ExpressionRange::makeIntRange(min_ts, max_ts, 0, arg_range.hasNulls());
816 }
817 
818 } // namespace
819 
821  const Analyzer::UOper* u_expr,
822  const std::vector<InputTableInfo>& query_infos,
823  const Executor* executor,
824  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
825  if (u_expr->get_optype() == kUNNEST) {
826  return getExpressionRange(u_expr->get_operand(), query_infos, executor, simple_quals);
827  }
828  if (u_expr->get_optype() != kCAST) {
830  }
831  const auto& ti = u_expr->get_type_info();
832  if (ti.is_string() && ti.get_compression() == kENCODING_DICT) {
833  const auto sdp = executor->getStringDictionaryProxy(
834  ti.get_comp_param(), executor->getRowSetMemoryOwner(), true);
835  CHECK(sdp);
836  const auto colvar_operand =
837  dynamic_cast<const Analyzer::ColumnVar*>(u_expr->get_operand());
838  if (colvar_operand) {
839  const auto& colvar_ti = colvar_operand->get_type_info();
840  if (!(colvar_ti.is_none_encoded_string() &&
841  ti.get_comp_param() == TRANSIENT_DICT_ID)) {
842  VLOG(1)
843  << "Unable to determine expression range for dictionary encoded expression "
844  << u_expr->get_operand()->toString() << ", proceeding with invalid range.";
846  }
847  CHECK_EQ(ti.get_comp_param(), TRANSIENT_DICT_ID);
848  CHECK_EQ(sdp->storageEntryCount(), 0UL);
849  const int64_t transient_entries = static_cast<int64_t>(sdp->transientEntryCount());
850  int64_t const tuples_upper_bound = static_cast<int64_t>(
851  std::accumulate(query_infos.cbegin(),
852  query_infos.cend(),
853  size_t(0),
854  [](auto max, auto const& query_info) {
855  return std::max(max, query_info.info.getNumTuples());
856  }));
857  const int64_t conservative_range_min = -1L - transient_entries - tuples_upper_bound;
858  return ExpressionRange::makeIntRange(conservative_range_min, -2L, 0, true);
859  }
860  const auto const_operand =
861  dynamic_cast<const Analyzer::Constant*>(u_expr->get_operand());
862  if (!const_operand) {
863  // casted subquery result. return invalid for now, but we could attempt to pull the
864  // range from the subquery result in the future
865  CHECK(u_expr->get_operand());
866  VLOG(1) << "Unable to determine expression range for dictionary encoded expression "
867  << u_expr->get_operand()->toString() << ", proceeding with invalid range.";
869  }
870 
871  if (const_operand->get_is_null()) {
873  }
874  CHECK(const_operand->get_constval().stringval);
875  const int64_t v = sdp->getIdOfString(*const_operand->get_constval().stringval);
876  return ExpressionRange::makeIntRange(v, v, 0, false);
877  }
878  const auto arg_range =
879  getExpressionRange(u_expr->get_operand(), query_infos, executor, simple_quals);
880  const auto& arg_ti = u_expr->get_operand()->get_type_info();
881  // Timestamp to Date OR Date/Timestamp casts with different precision
882  if ((ti.is_timestamp() && (arg_ti.get_dimension() != ti.get_dimension())) ||
883  ((arg_ti.is_timestamp() && ti.is_any(kDATE, kTIME)))) {
884  return getDateTimePrecisionCastRange(arg_range, arg_ti, ti);
885  }
886  switch (arg_range.getType()) {
889  if (ti.is_fp()) {
890  return ti.get_type() == kDOUBLE
892  arg_range.getFpMin(), arg_range.getFpMax(), arg_range.hasNulls())
893  : ExpressionRange::makeFloatRange(arg_range.getFpMin(),
894  arg_range.getFpMax(),
895  arg_range.hasNulls());
896  }
897  if (ti.is_integer()) {
898  return ExpressionRange::makeIntRange(std::floor(arg_range.getFpMin()),
899  std::ceil(arg_range.getFpMax()),
900  0,
901  arg_range.hasNulls());
902  }
903  break;
904  }
906  if (ti.is_decimal()) {
907  CHECK_EQ(int64_t(0), arg_range.getBucket());
908  const int64_t scale = exp_to_scale(ti.get_scale() - arg_ti.get_scale());
909  return ExpressionRange::makeIntRange(arg_range.getIntMin() * scale,
910  arg_range.getIntMax() * scale,
911  0,
912  arg_range.hasNulls());
913  }
914  if (arg_ti.is_decimal()) {
915  CHECK_EQ(int64_t(0), arg_range.getBucket());
916  const int64_t scale = exp_to_scale(arg_ti.get_scale());
917  const int64_t scale_half = scale / 2;
918  if (ti.is_fp()) {
919  return fpRangeFromDecimal(arg_range, scale, ti);
920  }
921  return ExpressionRange::makeIntRange((arg_range.getIntMin() - scale_half) / scale,
922  (arg_range.getIntMax() + scale_half) / scale,
923  0,
924  arg_range.hasNulls());
925  }
926  if (ti.is_integer() || ti.is_time()) {
927  return arg_range;
928  }
929  if (ti.get_type() == kFLOAT) {
931  arg_range.getIntMin(), arg_range.getIntMax(), arg_range.hasNulls());
932  }
933  if (ti.get_type() == kDOUBLE) {
935  arg_range.getIntMin(), arg_range.getIntMax(), arg_range.hasNulls());
936  }
937  break;
938  }
940  break;
941  default:
942  CHECK(false);
943  }
945 }
946 
948  const Analyzer::ExtractExpr* extract_expr,
949  const std::vector<InputTableInfo>& query_infos,
950  const Executor* executor,
951  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
952  const int32_t extract_field{extract_expr->get_field()};
953  const auto arg_range = getExpressionRange(
954  extract_expr->get_from_expr(), query_infos, executor, simple_quals);
955  const bool has_nulls =
956  arg_range.getType() == ExpressionRangeType::Invalid || arg_range.hasNulls();
957  const auto& extract_expr_ti = extract_expr->get_from_expr()->get_type_info();
958  switch (extract_field) {
959  case kYEAR: {
960  if (arg_range.getType() == ExpressionRangeType::Invalid) {
962  }
963  CHECK(arg_range.getType() == ExpressionRangeType::Integer);
964  const int64_t year_range_min =
965  extract_expr_ti.is_high_precision_timestamp()
966  ? ExtractFromTime(
967  kYEAR,
968  arg_range.getIntMin() /
969  get_timestamp_precision_scale(extract_expr_ti.get_dimension()))
970  : ExtractFromTime(kYEAR, arg_range.getIntMin());
971  const int64_t year_range_max =
972  extract_expr_ti.is_high_precision_timestamp()
973  ? ExtractFromTime(
974  kYEAR,
975  arg_range.getIntMax() /
976  get_timestamp_precision_scale(extract_expr_ti.get_dimension()))
977  : ExtractFromTime(kYEAR, arg_range.getIntMax());
979  year_range_min, year_range_max, 0, arg_range.hasNulls());
980  }
981  case kEPOCH:
982  case kDATEEPOCH:
983  return arg_range;
984  case kQUARTERDAY:
985  case kQUARTER:
986  return ExpressionRange::makeIntRange(1, 4, 0, has_nulls);
987  case kMONTH:
988  return ExpressionRange::makeIntRange(1, 12, 0, has_nulls);
989  case kDAY:
990  return ExpressionRange::makeIntRange(1, 31, 0, has_nulls);
991  case kHOUR:
992  return ExpressionRange::makeIntRange(0, 23, 0, has_nulls);
993  case kMINUTE:
994  return ExpressionRange::makeIntRange(0, 59, 0, has_nulls);
995  case kSECOND:
996  return ExpressionRange::makeIntRange(0, 60, 0, has_nulls);
997  case kMILLISECOND:
998  return ExpressionRange::makeIntRange(0, 999, 0, has_nulls);
999  case kMICROSECOND:
1000  return ExpressionRange::makeIntRange(0, 999999, 0, has_nulls);
1001  case kNANOSECOND:
1002  return ExpressionRange::makeIntRange(0, 999999999, 0, has_nulls);
1003  case kDOW:
1004  return ExpressionRange::makeIntRange(0, 6, 0, has_nulls);
1005  case kISODOW:
1006  return ExpressionRange::makeIntRange(1, 7, 0, has_nulls);
1007  case kDOY:
1008  return ExpressionRange::makeIntRange(1, 366, 0, has_nulls);
1009  case kWEEK:
1010  case kWEEK_SUNDAY:
1011  case kWEEK_SATURDAY:
1012  return ExpressionRange::makeIntRange(1, 53, 0, has_nulls);
1013  default:
1014  CHECK(false);
1015  }
1017 }
1018 
1020  const Analyzer::DatetruncExpr* datetrunc_expr,
1021  const std::vector<InputTableInfo>& query_infos,
1022  const Executor* executor,
1023  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
1024  const auto arg_range = getExpressionRange(
1025  datetrunc_expr->get_from_expr(), query_infos, executor, simple_quals);
1026  if (arg_range.getType() == ExpressionRangeType::Invalid) {
1028  }
1029  const auto& datetrunc_expr_ti = datetrunc_expr->get_from_expr()->get_type_info();
1030  const int64_t min_ts = DateTimeTranslator::getDateTruncConstantValue(
1031  arg_range.getIntMin(), datetrunc_expr->get_field(), datetrunc_expr_ti);
1032  const int64_t max_ts = DateTimeTranslator::getDateTruncConstantValue(
1033  arg_range.getIntMax(), datetrunc_expr->get_field(), datetrunc_expr_ti);
1034  const int64_t bucket =
1035  datetrunc_expr_ti.is_high_precision_timestamp()
1036  ? get_conservative_datetrunc_bucket(datetrunc_expr->get_field()) *
1038  datetrunc_expr_ti.get_dimension())
1039  : get_conservative_datetrunc_bucket(datetrunc_expr->get_field());
1040 
1041  return ExpressionRange::makeIntRange(min_ts, max_ts, bucket, arg_range.hasNulls());
1042 }
1043 
1046  const std::vector<InputTableInfo>& query_infos,
1047  const Executor* executor,
1048  boost::optional<std::list<std::shared_ptr<Analyzer::Expr>>> simple_quals) {
1049  auto target_value_expr = width_bucket_expr->get_target_value();
1050  auto target_value_range = getExpressionRange(target_value_expr, query_infos, executor);
1051  auto target_ti = target_value_expr->get_type_info();
1052  if (width_bucket_expr->is_constant_expr() &&
1053  target_value_range.getType() != ExpressionRangeType::Invalid) {
1054  auto const_target_value = dynamic_cast<const Analyzer::Constant*>(target_value_expr);
1055  if (const_target_value) {
1056  if (const_target_value->get_is_null()) {
1057  // null constant, return default width_bucket range
1059  0, width_bucket_expr->get_partition_count_val(), 0, true);
1060  } else {
1061  CHECK(target_value_range.getFpMax() == target_value_range.getFpMin());
1062  auto target_value_bucket =
1063  width_bucket_expr->compute_bucket(target_value_range.getFpMax(), target_ti);
1065  target_value_bucket, target_value_bucket, 0, target_value_range.hasNulls());
1066  }
1067  }
1068  // compute possible bucket range based on lower and upper bound constants
1069  // to elucidate a target bucket range
1070  const auto target_value_range_with_qual =
1071  getExpressionRange(target_value_expr, query_infos, executor, simple_quals);
1072  auto compute_bucket_range = [&width_bucket_expr](const ExpressionRange& target_range,
1073  SQLTypeInfo ti) {
1074  // we casted bucket bound exprs to double
1075  auto lower_bound_bucket =
1076  width_bucket_expr->compute_bucket<double>(target_range.getFpMin(), ti);
1077  auto upper_bound_bucket =
1078  width_bucket_expr->compute_bucket<double>(target_range.getFpMax(), ti);
1080  lower_bound_bucket, upper_bound_bucket, 0, target_range.hasNulls());
1081  };
1082  auto res_range = compute_bucket_range(target_value_range_with_qual, target_ti);
1083  // check target_value expression's col range to be not nullable iff it has its filter
1084  // expression i.e., in simple_quals
1085  // todo (yoonmin) : need to search simple_quals to cover more cases?
1086  if (target_value_range.getFpMin() < target_value_range_with_qual.getFpMin() ||
1087  target_value_range.getFpMax() > target_value_range_with_qual.getFpMax()) {
1088  res_range.setNulls(false);
1089  }
1090  return res_range;
1091  } else {
1092  // we cannot determine a possibility of skipping oob check safely
1093  const bool has_nulls = target_value_range.getType() == ExpressionRangeType::Invalid ||
1094  target_value_range.hasNulls();
1095  auto partition_expr_range = getExpressionRange(
1096  width_bucket_expr->get_partition_count(), query_infos, executor, simple_quals);
1097  auto res = ExpressionRange::makeIntRange(0, INT32_MAX, 0, has_nulls);
1098  switch (partition_expr_range.getType()) {
1100  res.setIntMax(partition_expr_range.getIntMax() + 1);
1101  break;
1102  }
1105  res.setIntMax(static_cast<int64_t>(partition_expr_range.getFpMax()) + 1);
1106  break;
1107  }
1108  default:
1109  break;
1110  }
1111  return res;
1112  }
1113 }
int get_table_id() const
Definition: Analyzer.h:201
static constexpr int64_t kSecsPerDay
int64_t getIntMin() const
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define FIND_STAT_FRAG(stat_name)
const Expr * get_from_expr() const
Definition: Analyzer.h:1305
const Expr * get_partition_count() const
Definition: Analyzer.h:1044
bool is_constant_expr() const
Definition: Analyzer.h:1119
const Expr * get_else_expr() const
Definition: Analyzer.h:1260
static ExpressionRange makeNullRange()
Definition: sqltypes.h:63
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4244
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
SQLTypes
Definition: sqltypes.h:52
bool is_timestamp() const
Definition: sqltypes.h:1020
bool operator==(const ExpressionRange &other) const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void >> checked_int64_t
bool is_any(Types...types) const
Definition: sqltypes.h:597
void apply_hpt_qual(const Datum const_datum, const SQLTypes const_type, const int32_t const_dimen, const int32_t col_dimen, const SQLOps sql_op, ExpressionRange &qual_range)
void apply_int_qual(const Datum const_datum, const SQLTypes const_type, const SQLOps sql_op, ExpressionRange &qual_range)
double extract_max_stat_fp_type(const ChunkStats &stats, const SQLTypeInfo &ti)
ExtractField get_field() const
Definition: Analyzer.h:1304
bool is_fp() const
Definition: sqltypes.h:604
HOST DEVICE int get_scale() const
Definition: sqltypes.h:409
const Expr * get_right_operand() const
Definition: Analyzer.h:451
SQLOps
Definition: sqldefs.h:28
Definition: sqldefs.h:34
Definition: sqldefs.h:35
#define DEF_OPERATOR(fname, op)
bool get_is_null() const
Definition: Analyzer.h:342
#define CHECK_GE(x, y)
Definition: Logger.h:235
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1221
Definition: sqldefs.h:48
Definition: sqldefs.h:29
DatetruncField get_field() const
Definition: Analyzer.h:1429
Definition: sqldefs.h:40
int64_t scale_up_interval_endpoint(const int64_t endpoint, const SQLTypeInfo &ti)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
void setIntMin(const int64_t int_min)
bool is_number() const
Definition: sqltypes.h:605
#define CHECK_GT(x, y)
Definition: Logger.h:234
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
const Expr * get_arg() const
Definition: Analyzer.h:904
int64_t extract_max_stat_int_type(const ChunkStats &stats, const SQLTypeInfo &ti)
bool is_time() const
Definition: sqltypes.h:606
static ExpressionRange makeFloatRange(const float fp_min, const float fp_max, const bool has_nulls)
ExpressionRange apply_simple_quals(const Analyzer::ColumnVar *col_expr, const ExpressionRange &col_range, const boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
bool g_null_div_by_zero
Definition: Execute.cpp:88
SQLOps get_optype() const
Definition: Analyzer.h:447
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
ExpressionRangeType type_
ExpressionRange operator||(const ExpressionRange &other) const
DatetruncField
Definition: DateTruncate.h:27
int64_t get_conservative_datetrunc_bucket(const DatetruncField datetrunc_field)
double extract_min_stat_fp_type(const ChunkStats &stats, const SQLTypeInfo &ti)
void apply_fp_qual(const Datum const_datum, const SQLTypes const_type, const SQLOps sql_op, ExpressionRange &qual_range)
int64_t bigintval
Definition: sqltypes.h:235
int64_t extract_min_stat_int_type(const ChunkStats &stats, const SQLTypeInfo &ti)
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
ExpressionRange getLeafColumnRange(const Analyzer::ColumnVar *col_expr, const std::vector< InputTableInfo > &query_infos, const Executor *executor, const bool is_outer_join_proj)
bool is_boolean() const
Definition: sqltypes.h:607
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
bool hasNulls() const
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
Definition: sqldefs.h:33
static ExpressionRange makeDoubleRange(const double fp_min, const double fp_max, const bool has_nulls)
#define CHECK_LT(x, y)
Definition: Logger.h:232
Definition: sqltypes.h:66
Definition: sqltypes.h:67
double getFpMax() const
Definition: sqldefs.h:39
virtual std::string toString() const =0
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1464
const Expr * get_from_expr() const
Definition: Analyzer.h:1430
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:334
double getFpMin() const
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:412
int get_rte_idx() const
Definition: Analyzer.h:203
const Expr * get_operand() const
Definition: Analyzer.h:379
Datum get_constval() const
Definition: Analyzer.h:343
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:406
ExpressionRange operator/(const ExpressionRange &other) const
int32_t get_partition_count_val() const
Definition: Analyzer.cpp:3693
DEVICE int64_t ExtractFromTime(ExtractField field, const int64_t timeval)
Definition: sqltypes.h:55
void setIntMax(const int64_t int_max)
const Expr * get_target_value() const
Definition: Analyzer.h:1041
ExpressionRangeType getType() const
int64_t getIntMax() const
#define CHECK(condition)
Definition: Logger.h:222
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:1010
Find out all the physical inputs (columns) a query is using.
uint64_t exp_to_scale(const unsigned exp)
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int32_t compute_bucket(T target_const_val, SQLTypeInfo &ti) const
Definition: Analyzer.h:1082
Definition: sqldefs.h:32
const Expr * get_left_operand() const
Definition: Analyzer.h:450
static bool typeSupportsRange(const SQLTypeInfo &ti)
Definition: sqltypes.h:59
int get_column_id() const
Definition: Analyzer.h:202
static ExpressionRange makeInvalidRange()
bool is_string() const
Definition: sqltypes.h:600
static int64_t getDateTruncConstantValue(const int64_t &timeval, const DatetruncField &field, const SQLTypeInfo &ti)
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:981
std::vector< std::shared_ptr< Analyzer::Expr > > getChainedStringOpExprs() const
Definition: Analyzer.h:1531
ExpressionRange getDateTimePrecisionCastRange(const ExpressionRange &arg_range, const SQLTypeInfo &oper_ti, const SQLTypeInfo &target_ti)
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1519
SQLOps get_optype() const
Definition: Analyzer.h:378
bool is_date() const
Definition: sqltypes.h:1008
bool is_array() const
Definition: sqltypes.h:608
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > & get_expr_pair_list() const
Definition: Analyzer.h:1257
#define VLOG(n)
Definition: Logger.h:316
ExpressionRange fpRangeFromDecimal(const ExpressionRange &arg_range, const int64_t scale, const SQLTypeInfo &target_ti)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int32_t width_bucket_expr(const double target_value, const bool reversed, const double lower_bound, const double upper_bound, const int32_t partition_count)