OmniSciDB  c07336695a
Analyzer::BinOper Class Reference

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::BinOper:
+ Collaboration diagram for Analyzer::BinOper:

Public Member Functions

 BinOper (const SQLTypeInfo &ti, bool has_agg, SQLOps o, SQLQualifier q, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
 
 BinOper (SQLTypes t, SQLOps o, SQLQualifier q, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
 
SQLOps get_optype () const
 
bool is_overlaps_oper () const
 
SQLQualifier get_qualifier () const
 
const Exprget_left_operand () const
 
const Exprget_right_operand () const
 
const std::shared_ptr< Analyzer::Exprget_own_left_operand () const
 
const std::shared_ptr< Analyzer::Exprget_own_right_operand () const
 
void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
std::shared_ptr< Analyzer::Exprnormalize_simple_predicate (int &rte_idx) const override
 
void group_predicates (std::list< const Expr *> &scan_predicates, std::list< const Expr *> &join_predicates, std::list< const Expr *> &const_predicates) const override
 
void collect_rte_idx (std::set< int > &rte_idx_set) const override
 
void collect_column_var (std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
 
std::shared_ptr< Analyzer::Exprrewrite_with_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_with_child_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_agg_to_var (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
bool operator== (const Expr &rhs) const override
 
std::string toString () const override
 
void find_expr (bool(*f)(const Expr *), std::list< const Expr *> &expr_list) const override
 
- Public Member Functions inherited from Analyzer::Expr
 Expr (SQLTypes t, bool notnull)
 
 Expr (SQLTypes t, int d, bool notnull)
 
 Expr (SQLTypes t, int d, int s, bool notnull)
 
 Expr (const SQLTypeInfo &ti, bool has_agg=false)
 
virtual ~Expr ()
 
const SQLTypeInfoget_type_info () const
 
void set_type_info (const SQLTypeInfo &ti)
 
bool get_contains_agg () const
 
void set_contains_agg (bool a)
 
virtual std::shared_ptr< Analyzer::Expradd_cast (const SQLTypeInfo &new_type_info)
 
virtual void print () const
 
virtual void add_unique (std::list< const Expr *> &expr_list) const
 
std::shared_ptr< Analyzer::Exprdecompress ()
 
virtual void get_domain (DomainSet &domain_set) const
 

Static Public Member Functions

static SQLTypeInfo analyze_type_info (SQLOps op, const SQLTypeInfo &left_type, const SQLTypeInfo &right_type, SQLTypeInfo *new_left_type, SQLTypeInfo *new_right_type)
 
static SQLTypeInfo common_numeric_type (const SQLTypeInfo &type1, const SQLTypeInfo &type2)
 
static SQLTypeInfo common_string_type (const SQLTypeInfo &type1, const SQLTypeInfo &type2)
 
static bool simple_predicate_has_simple_cast (const std::shared_ptr< Analyzer::Expr > cast_operand, const std::shared_ptr< Analyzer::Expr > const_operand)
 

Private Attributes

SQLOps optype
 
SQLQualifier qualifier
 
std::shared_ptr< Analyzer::Exprleft_operand
 
std::shared_ptr< Analyzer::Exprright_operand
 

Additional Inherited Members

- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 413 of file Analyzer.h.

Constructor & Destructor Documentation

◆ BinOper() [1/2]

Analyzer::BinOper::BinOper ( const SQLTypeInfo ti,
bool  has_agg,
SQLOps  o,
SQLQualifier  q,
std::shared_ptr< Analyzer::Expr l,
std::shared_ptr< Analyzer::Expr r 
)
inline

Definition at line 415 of file Analyzer.h.

421  : Expr(ti, has_agg), optype(o), qualifier(q), left_operand(l), right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
SQLQualifier qualifier
Definition: Analyzer.h:507
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509

◆ BinOper() [2/2]

Analyzer::BinOper::BinOper ( SQLTypes  t,
SQLOps  o,
SQLQualifier  q,
std::shared_ptr< Analyzer::Expr l,
std::shared_ptr< Analyzer::Expr r 
)
inline

Definition at line 422 of file Analyzer.h.

427  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
428  , optype(o)
429  , qualifier(q)
430  , left_operand(l)
431  , right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
SQLQualifier qualifier
Definition: Analyzer.h:507
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509

Member Function Documentation

◆ analyze_type_info()

SQLTypeInfo Analyzer::BinOper::analyze_type_info ( SQLOps  op,
const SQLTypeInfo left_type,
const SQLTypeInfo right_type,
SQLTypeInfo new_left_type,
SQLTypeInfo new_right_type 
)
static

Definition at line 204 of file Analyzer.cpp.

References CHECK, SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_notnull(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type_name(), IS_ARITHMETIC, SQLTypeInfoCore< TYPE_FACET_PACK >::is_boolean(), IS_COMPARISON, SQLTypeInfoCore< TYPE_FACET_PACK >::is_decimal(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_integer(), IS_LOGIC, SQLTypeInfoCore< TYPE_FACET_PACK >::is_number(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_time(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_timeinterval(), kBOOLEAN, kDATE, kMINUS, kMODULO, kMULTIPLY, kPLUS, kTIME, kTIMESTAMP, SQLTypeInfoCore< TYPE_FACET_PACK >::set_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_notnull(), and SQLTypeInfoCore< TYPE_FACET_PACK >::set_scale().

Referenced by Parser::BetweenExpr::analyze(), and Parser::OperExpr::normalize().

208  {
209  SQLTypeInfo result_type;
210  SQLTypeInfo common_type;
211  *new_left_type = left_type;
212  *new_right_type = right_type;
213  if (IS_LOGIC(op)) {
214  if (left_type.get_type() != kBOOLEAN || right_type.get_type() != kBOOLEAN) {
215  throw std::runtime_error(
216  "non-boolean operands cannot be used in logic operations.");
217  }
218  result_type = SQLTypeInfo(kBOOLEAN, false);
219  } else if (IS_COMPARISON(op)) {
220  if (left_type != right_type) {
221  if (left_type.is_number() && right_type.is_number()) {
222  common_type = common_numeric_type(left_type, right_type);
223  *new_left_type = common_type;
224  new_left_type->set_notnull(left_type.get_notnull());
225  *new_right_type = common_type;
226  new_right_type->set_notnull(right_type.get_notnull());
227  } else if (left_type.is_time() && right_type.is_time()) {
228  switch (left_type.get_type()) {
229  case kTIMESTAMP:
230  switch (right_type.get_type()) {
231  case kTIME:
232  throw std::runtime_error("Cannont compare between TIMESTAMP and TIME.");
233  break;
234  case kDATE:
235  *new_left_type = SQLTypeInfo(left_type.get_type(),
236  left_type.get_dimension(),
237  0,
238  left_type.get_notnull());
239  *new_right_type = *new_left_type;
240  new_right_type->set_notnull(right_type.get_notnull());
241  break;
242  case kTIMESTAMP:
243  *new_left_type = SQLTypeInfo(
244  kTIMESTAMP,
245  std::max(left_type.get_dimension(), right_type.get_dimension()),
246  0,
247  left_type.get_notnull());
248  *new_right_type = SQLTypeInfo(
249  kTIMESTAMP,
250  std::max(left_type.get_dimension(), right_type.get_dimension()),
251  0,
252  right_type.get_notnull());
253  break;
254  default:
255  CHECK(false);
256  }
257  break;
258  case kTIME:
259  switch (right_type.get_type()) {
260  case kTIMESTAMP:
261  throw std::runtime_error("Cannont compare between TIME and TIMESTAMP.");
262  break;
263  case kDATE:
264  throw std::runtime_error("Cannont compare between TIME and DATE.");
265  break;
266  case kTIME:
267  *new_left_type = SQLTypeInfo(
268  kTIME,
269  std::max(left_type.get_dimension(), right_type.get_dimension()),
270  0,
271  left_type.get_notnull());
272  *new_right_type = SQLTypeInfo(
273  kTIME,
274  std::max(left_type.get_dimension(), right_type.get_dimension()),
275  0,
276  right_type.get_notnull());
277  break;
278  default:
279  CHECK(false);
280  }
281  break;
282  case kDATE:
283  switch (right_type.get_type()) {
284  case kTIMESTAMP:
285  *new_left_type = SQLTypeInfo(right_type.get_type(),
286  right_type.get_dimension(),
287  0,
288  left_type.get_notnull());
289  *new_right_type = *new_left_type;
290  new_right_type->set_notnull(right_type.get_notnull());
291  break;
292  case kDATE:
293  *new_left_type = SQLTypeInfo(left_type.get_type(),
294  left_type.get_dimension(),
295  0,
296  left_type.get_notnull());
297  *new_right_type = *new_left_type;
298  new_right_type->set_notnull(right_type.get_notnull());
299  break;
300  case kTIME:
301  throw std::runtime_error("Cannont compare between DATE and TIME.");
302  break;
303  default:
304  CHECK(false);
305  }
306  break;
307  default:
308  CHECK(false);
309  }
310  } else if (left_type.is_string() && right_type.is_time()) {
311  *new_left_type = right_type;
312  new_left_type->set_notnull(left_type.get_notnull());
313  *new_right_type = right_type;
314  } else if (left_type.is_time() && right_type.is_string()) {
315  *new_left_type = left_type;
316  *new_right_type = left_type;
317  new_right_type->set_notnull(right_type.get_notnull());
318  } else if (left_type.is_string() && right_type.is_string()) {
319  *new_left_type = left_type;
320  *new_right_type = right_type;
321  } else if (left_type.is_boolean() && right_type.is_boolean()) {
322  const bool notnull = left_type.get_notnull() && right_type.get_notnull();
323  common_type = SQLTypeInfo(kBOOLEAN, notnull);
324  *new_left_type = common_type;
325  *new_right_type = common_type;
326  } else {
327  throw std::runtime_error("Cannot compare between " + left_type.get_type_name() +
328  " and " + right_type.get_type_name());
329  }
330  }
331  result_type = SQLTypeInfo(kBOOLEAN, false);
332  } else if (op == kMINUS &&
333  (left_type.get_type() == kDATE || left_type.get_type() == kTIMESTAMP) &&
334  right_type.is_timeinterval()) {
335  *new_left_type = left_type;
336  *new_right_type = right_type;
337  result_type = left_type;
338  } else if (IS_ARITHMETIC(op)) {
339  if (!(left_type.is_number() || left_type.is_timeinterval()) ||
340  !(right_type.is_number() || right_type.is_timeinterval())) {
341  throw std::runtime_error("non-numeric operands in arithmetic operations.");
342  }
343  if (op == kMODULO && (!left_type.is_integer() || !right_type.is_integer())) {
344  throw std::runtime_error("non-integer operands in modulo operation.");
345  }
346  common_type = common_numeric_type(left_type, right_type);
347  if (common_type.is_decimal()) {
348  if (op == kMULTIPLY) {
349  // Decimal multiplication requires common_type adjustment:
350  // dimension and scale of the result should be increased.
351  auto new_dimension = left_type.get_dimension() + right_type.get_dimension();
352  // If new dimension is over 20 digits, the result may overflow, or it may not.
353  // Rely on the runtime overflow detection rather than a static check here.
354  if (common_type.get_dimension() < new_dimension) {
355  common_type.set_dimension(new_dimension);
356  }
357  common_type.set_scale(left_type.get_scale() + right_type.get_scale());
358  } else if (op == kPLUS || op == kMINUS) {
359  // Scale should remain the same but dimension could actually go up
360  common_type.set_dimension(common_type.get_dimension() + 1);
361  }
362  }
363  *new_left_type = common_type;
364  new_left_type->set_notnull(left_type.get_notnull());
365  *new_right_type = common_type;
366  new_right_type->set_notnull(right_type.get_notnull());
367  if (op == kMULTIPLY) {
368  new_left_type->set_scale(left_type.get_scale());
369  new_right_type->set_scale(right_type.get_scale());
370  }
371  result_type = common_type;
372  } else {
373  throw std::runtime_error("invalid binary operator type.");
374  }
375  result_type.set_notnull(left_type.get_notnull() && right_type.get_notnull());
376  return result_type;
377 }
#define IS_LOGIC(X)
Definition: sqldefs.h:60
bool is_time() const
Definition: sqltypes.h:452
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
Definition: sqltypes.h:51
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:326
HOST DEVICE int get_scale() const
Definition: sqltypes.h:324
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
Definition: sqldefs.h:41
void set_dimension(int d)
Definition: sqltypes.h:411
void set_scale(int s)
Definition: sqltypes.h:414
void set_notnull(bool n)
Definition: sqltypes.h:416
std::string get_type_name() const
Definition: sqltypes.h:422
bool is_timeinterval() const
Definition: sqltypes.h:457
bool is_integer() const
Definition: sqltypes.h:448
bool is_decimal() const
Definition: sqltypes.h:449
static SQLTypeInfo common_numeric_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
Definition: Analyzer.cpp:419
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:819
bool is_boolean() const
Definition: sqltypes.h:453
Definition: sqltypes.h:55
Definition: sqldefs.h:40
#define IS_ARITHMETIC(X)
Definition: sqldefs.h:61
bool is_number() const
Definition: sqltypes.h:451
#define CHECK(condition)
Definition: Logger.h:187
bool is_string() const
Definition: sqltypes.h:446
#define IS_COMPARISON(X)
Definition: sqldefs.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_group_by()

void Analyzer::BinOper::check_group_by ( const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1298 of file Analyzer.cpp.

1299  {
1300  left_operand->check_group_by(groupby);
1301  right_operand->check_group_by(groupby);
1302 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509

◆ collect_column_var()

void Analyzer::BinOper::collect_column_var ( std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &  colvar_set,
bool  include_agg 
) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 463 of file Analyzer.h.

466  {
467  left_operand->collect_column_var(colvar_set, include_agg);
468  right_operand->collect_column_var(colvar_set, include_agg);
469  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509

◆ collect_rte_idx()

void Analyzer::BinOper::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 459 of file Analyzer.h.

459  {
460  left_operand->collect_rte_idx(rte_idx_set);
461  right_operand->collect_rte_idx(rte_idx_set);
462  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509

◆ common_numeric_type()

SQLTypeInfo Analyzer::BinOper::common_numeric_type ( const SQLTypeInfo type1,
const SQLTypeInfo type2 
)
static

Definition at line 419 of file Analyzer.cpp.

References CHECK, SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_notnull(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type_name(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_boolean(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_integer(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_number(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_timeinterval(), kBIGINT, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTINYINT, and SQLTypeInfoCore< TYPE_FACET_PACK >::set_fixed_size().

Referenced by Parser::InValues::analyze(), and Parser::CaseExpr::normalize().

420  {
421  SQLTypeInfo common_type;
422  const bool notnull = type1.get_notnull() && type2.get_notnull();
423  if (type1.get_type() == type2.get_type()) {
424  CHECK(((type1.is_number() || type1.is_timeinterval()) &&
425  (type2.is_number() || type2.is_timeinterval())) ||
426  (type1.is_boolean() && type2.is_boolean()));
427  common_type = SQLTypeInfo(type1.get_type(),
428  std::max(type1.get_dimension(), type2.get_dimension()),
429  std::max(type1.get_scale(), type2.get_scale()),
430  notnull);
431  return common_type;
432  }
433  std::string timeinterval_op_error{
434  "Operator type not supported for time interval arithmetic: "};
435  if (type1.is_timeinterval()) {
436  if (!type2.is_integer()) {
437  throw std::runtime_error(timeinterval_op_error + type2.get_type_name());
438  }
439  return type1;
440  }
441  if (type2.is_timeinterval()) {
442  if (!type1.is_integer()) {
443  throw std::runtime_error(timeinterval_op_error + type1.get_type_name());
444  }
445  return type2;
446  }
447  CHECK(type1.is_number() && type2.is_number());
448  switch (type1.get_type()) {
449  case kTINYINT:
450  switch (type2.get_type()) {
451  case kSMALLINT:
452  common_type = SQLTypeInfo(kSMALLINT, notnull);
453  break;
454  case kINT:
455  common_type = SQLTypeInfo(kINT, notnull);
456  break;
457  case kBIGINT:
458  common_type = SQLTypeInfo(kBIGINT, notnull);
459  break;
460  case kFLOAT:
461  common_type = SQLTypeInfo(kFLOAT, notnull);
462  break;
463  case kDOUBLE:
464  common_type = SQLTypeInfo(kDOUBLE, notnull);
465  break;
466  case kNUMERIC:
467  case kDECIMAL:
468  common_type =
470  std::max(5 + type2.get_scale(), type2.get_dimension()),
471  type2.get_scale(),
472  notnull);
473  break;
474  default:
475  CHECK(false);
476  }
477  break;
478  case kSMALLINT:
479  switch (type2.get_type()) {
480  case kTINYINT:
481  common_type = SQLTypeInfo(kSMALLINT, notnull);
482  break;
483  case kINT:
484  common_type = SQLTypeInfo(kINT, notnull);
485  break;
486  case kBIGINT:
487  common_type = SQLTypeInfo(kBIGINT, notnull);
488  break;
489  case kFLOAT:
490  common_type = SQLTypeInfo(kFLOAT, notnull);
491  break;
492  case kDOUBLE:
493  common_type = SQLTypeInfo(kDOUBLE, notnull);
494  break;
495  case kNUMERIC:
496  case kDECIMAL:
497  common_type =
499  std::max(5 + type2.get_scale(), type2.get_dimension()),
500  type2.get_scale(),
501  notnull);
502  break;
503  default:
504  CHECK(false);
505  }
506  break;
507  case kINT:
508  switch (type2.get_type()) {
509  case kTINYINT:
510  common_type = SQLTypeInfo(kINT, notnull);
511  break;
512  case kSMALLINT:
513  common_type = SQLTypeInfo(kINT, notnull);
514  break;
515  case kBIGINT:
516  common_type = SQLTypeInfo(kBIGINT, notnull);
517  break;
518  case kFLOAT:
519  common_type = SQLTypeInfo(kFLOAT, notnull);
520  break;
521  case kDOUBLE:
522  common_type = SQLTypeInfo(kDOUBLE, notnull);
523  break;
524  case kNUMERIC:
525  case kDECIMAL:
526  common_type = SQLTypeInfo(
527  kDECIMAL,
528  std::max(std::min(19, 10 + type2.get_scale()), type2.get_dimension()),
529  type2.get_scale(),
530  notnull);
531  break;
532  default:
533  CHECK(false);
534  }
535  break;
536  case kBIGINT:
537  switch (type2.get_type()) {
538  case kTINYINT:
539  common_type = SQLTypeInfo(kBIGINT, notnull);
540  break;
541  case kSMALLINT:
542  common_type = SQLTypeInfo(kBIGINT, notnull);
543  break;
544  case kINT:
545  common_type = SQLTypeInfo(kBIGINT, notnull);
546  break;
547  case kFLOAT:
548  common_type = SQLTypeInfo(kFLOAT, notnull);
549  break;
550  case kDOUBLE:
551  common_type = SQLTypeInfo(kDOUBLE, notnull);
552  break;
553  case kNUMERIC:
554  case kDECIMAL:
555  common_type = SQLTypeInfo(kDECIMAL, 19, type2.get_scale(), notnull);
556  break;
557  default:
558  CHECK(false);
559  }
560  break;
561  case kFLOAT:
562  switch (type2.get_type()) {
563  case kTINYINT:
564  common_type = SQLTypeInfo(kFLOAT, notnull);
565  break;
566  case kSMALLINT:
567  common_type = SQLTypeInfo(kFLOAT, notnull);
568  break;
569  case kINT:
570  common_type = SQLTypeInfo(kFLOAT, notnull);
571  break;
572  case kBIGINT:
573  common_type = SQLTypeInfo(kFLOAT, notnull);
574  break;
575  case kDOUBLE:
576  common_type = SQLTypeInfo(kDOUBLE, notnull);
577  break;
578  case kNUMERIC:
579  case kDECIMAL:
580  common_type = SQLTypeInfo(kFLOAT, notnull);
581  break;
582  default:
583  CHECK(false);
584  }
585  break;
586  case kDOUBLE:
587  switch (type2.get_type()) {
588  case kTINYINT:
589  case kSMALLINT:
590  case kINT:
591  case kBIGINT:
592  case kFLOAT:
593  case kNUMERIC:
594  case kDECIMAL:
595  common_type = SQLTypeInfo(kDOUBLE, notnull);
596  break;
597  default:
598  CHECK(false);
599  }
600  break;
601  case kNUMERIC:
602  case kDECIMAL:
603  switch (type2.get_type()) {
604  case kSMALLINT:
605  common_type =
607  std::max(5 + type1.get_scale(), type1.get_dimension()),
608  type1.get_scale(),
609  notnull);
610  break;
611  case kINT:
612  common_type = SQLTypeInfo(
613  kDECIMAL,
614  std::max(std::min(19, 10 + type1.get_scale()), type2.get_dimension()),
615  type1.get_scale(),
616  notnull);
617  break;
618  case kBIGINT:
619  common_type = SQLTypeInfo(kDECIMAL, 19, type1.get_scale(), notnull);
620  break;
621  case kFLOAT:
622  common_type = SQLTypeInfo(kFLOAT, notnull);
623  break;
624  case kDOUBLE:
625  common_type = SQLTypeInfo(kDOUBLE, notnull);
626  break;
627  case kNUMERIC:
628  case kDECIMAL: {
629  int common_scale = std::max(type1.get_scale(), type2.get_scale());
630  common_type = SQLTypeInfo(kDECIMAL,
631  std::max(type1.get_dimension() - type1.get_scale(),
632  type2.get_dimension() - type2.get_scale()) +
633  common_scale,
634  common_scale,
635  notnull);
636  break;
637  }
638  default:
639  CHECK(false);
640  }
641  break;
642  default:
643  CHECK(false);
644  }
645  common_type.set_fixed_size();
646  return common_type;
647 }
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:326
HOST DEVICE int get_scale() const
Definition: sqltypes.h:324
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
std::string get_type_name() const
Definition: sqltypes.h:422
bool is_timeinterval() const
Definition: sqltypes.h:457
bool is_integer() const
Definition: sqltypes.h:448
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:819
bool is_boolean() const
Definition: sqltypes.h:453
bool is_number() const
Definition: sqltypes.h:451
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ common_string_type()

SQLTypeInfo Analyzer::BinOper::common_string_type ( const SQLTypeInfo type1,
const SQLTypeInfo type2 
)
static

Definition at line 379 of file Analyzer.cpp.

References CHECK, SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_notnull(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), kENCODING_DICT, kENCODING_NONE, kNULLT, kTEXT, kVARCHAR, and TRANSIENT_DICT.

Referenced by Parser::InValues::analyze(), and Parser::CaseExpr::normalize().

380  {
381  SQLTypeInfo common_type;
383  int comp_param = 0;
384  CHECK(type1.is_string() && type2.is_string());
385  // if type1 and type2 have the same DICT encoding then keep it
386  // otherwise, they must be decompressed
387  if (type1.get_compression() == kENCODING_DICT &&
388  type2.get_compression() == kENCODING_DICT) {
389  if (type1.get_comp_param() == type2.get_comp_param() ||
390  type1.get_comp_param() == TRANSIENT_DICT(type2.get_comp_param())) {
391  comp = kENCODING_DICT;
392  comp_param = std::min(type1.get_comp_param(), type2.get_comp_param());
393  }
394  } else if (type1.get_compression() == kENCODING_DICT &&
395  type2.get_compression() == kENCODING_NONE) {
396  comp_param = type1.get_comp_param();
397  } else if (type1.get_compression() == kENCODING_NONE &&
398  type2.get_compression() == kENCODING_DICT) {
399  comp_param = type2.get_comp_param();
400  } else {
401  comp_param = std::max(type1.get_comp_param(),
402  type2.get_comp_param()); // preserve previous comp_param if set
403  }
404  const bool notnull = type1.get_notnull() && type2.get_notnull();
405  if (type1.get_type() == kTEXT || type2.get_type() == kTEXT) {
406  common_type = SQLTypeInfo(kTEXT, 0, 0, notnull, comp, comp_param, kNULLT);
407  return common_type;
408  }
409  common_type = SQLTypeInfo(kVARCHAR,
410  std::max(type1.get_dimension(), type2.get_dimension()),
411  0,
412  notnull,
413  comp,
414  comp_param,
415  kNULLT);
416  return common_type;
417 }
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
EncodingType
Definition: encodetypes.h:22
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:326
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:327
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:819
Definition: sqltypes.h:54
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:328
#define CHECK(condition)
Definition: Logger.h:187
bool is_string() const
Definition: sqltypes.h:446
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:188
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deep_copy()

std::shared_ptr< Analyzer::Expr > Analyzer::BinOper::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 99 of file Analyzer.cpp.

References Analyzer::Expr::contains_agg, and Analyzer::Expr::type_info.

99  {
100  return makeExpr<BinOper>(type_info,
101  contains_agg,
102  optype,
103  qualifier,
104  left_operand->deep_copy(),
105  right_operand->deep_copy());
106 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
SQLQualifier qualifier
Definition: Analyzer.h:507
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
bool contains_agg
Definition: Analyzer.h:176

◆ find_expr()

void Analyzer::BinOper::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr *> &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2595 of file Analyzer.cpp.

References Analyzer::Expr::add_unique().

2595  {
2596  if (f(this)) {
2597  add_unique(expr_list);
2598  return;
2599  }
2600  left_operand->find_expr(f, expr_list);
2601  right_operand->find_expr(f, expr_list);
2602 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
virtual void add_unique(std::list< const Expr *> &expr_list) const
Definition: Analyzer.cpp:2585
+ Here is the call graph for this function:

◆ get_left_operand()

◆ get_optype()

◆ get_own_left_operand()

const std::shared_ptr<Analyzer::Expr> Analyzer::BinOper::get_own_left_operand ( ) const
inline

Definition at line 437 of file Analyzer.h.

Referenced by CodeGenerator::codegenCmp(), anonymous_namespace{CompareIR.cpp}::lower_bw_eq(), anonymous_namespace{ExpressionRewrite.cpp}::OrToInVisitor::visitBinOper(), anonymous_namespace{ExpressionRewrite.cpp}::RecursiveOrToInVisitor::visitBinOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitBinOper().

437  {
438  return left_operand;
439  }
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
+ Here is the caller graph for this function:

◆ get_own_right_operand()

const std::shared_ptr<Analyzer::Expr> Analyzer::BinOper::get_own_right_operand ( ) const
inline

Definition at line 440 of file Analyzer.h.

Referenced by CodeGenerator::codegenCmp(), anonymous_namespace{CompareIR.cpp}::lower_bw_eq(), anonymous_namespace{ExpressionRewrite.cpp}::OrToInVisitor::visitBinOper(), anonymous_namespace{ExpressionRewrite.cpp}::RecursiveOrToInVisitor::visitBinOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitBinOper().

440  {
441  return right_operand;
442  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
+ Here is the caller graph for this function:

◆ get_qualifier()

SQLQualifier Analyzer::BinOper::get_qualifier ( ) const
inline

◆ get_right_operand()

◆ group_predicates()

void Analyzer::BinOper::group_predicates ( std::list< const Expr *> &  scan_predicates,
std::list< const Expr *> &  join_predicates,
std::list< const Expr *> &  const_predicates 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1402 of file Analyzer.cpp.

References kAND.

1404  {
1405  if (optype == kAND) {
1406  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1407  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1408  return;
1409  }
1410  std::set<int> rte_idx_set;
1411  left_operand->collect_rte_idx(rte_idx_set);
1412  right_operand->collect_rte_idx(rte_idx_set);
1413  if (rte_idx_set.size() > 1) {
1414  join_predicates.push_back(this);
1415  } else if (rte_idx_set.size() == 1) {
1416  scan_predicates.push_back(this);
1417  } else {
1418  const_predicates.push_back(this);
1419  }
1420 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
Definition: sqldefs.h:37

◆ is_overlaps_oper()

bool Analyzer::BinOper::is_overlaps_oper ( ) const
inline

Definition at line 433 of file Analyzer.h.

References kOVERLAPS.

Referenced by normalize_column_pairs().

433 { return optype == kOVERLAPS; }
+ Here is the caller graph for this function:

◆ normalize_simple_predicate()

std::shared_ptr< Analyzer::Expr > Analyzer::BinOper::normalize_simple_predicate ( int &  rte_idx) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1337 of file Analyzer.cpp.

References COMMUTE_COMPARISON, Analyzer::Expr::contains_agg, Analyzer::Constant::deep_copy(), Analyzer::ColumnVar::get_rte_idx(), IS_COMPARISON, kONE, simple_predicate_has_simple_cast(), and Analyzer::Expr::type_info.

1337  {
1338  rte_idx = -1;
1339  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1340  return nullptr;
1341  }
1342  if (expr_is<UOper>(left_operand)) {
1344  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1345  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1346  rte_idx = cv->get_rte_idx();
1347  return this->deep_copy();
1348  }
1349  } else if (expr_is<UOper>(right_operand)) {
1351  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1352  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1353  rte_idx = cv->get_rte_idx();
1354  return makeExpr<BinOper>(type_info,
1355  contains_agg,
1357  qualifier,
1358  right_operand->deep_copy(),
1359  left_operand->deep_copy());
1360  }
1361  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1362  expr_is<Constant>(right_operand)) {
1363  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1364  rte_idx = cv->get_rte_idx();
1365  return this->deep_copy();
1366  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1367  !expr_is<Var>(right_operand)) {
1368  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1369  rte_idx = cv->get_rte_idx();
1370  return makeExpr<BinOper>(type_info,
1371  contains_agg,
1373  qualifier,
1374  right_operand->deep_copy(),
1375  left_operand->deep_copy());
1376  }
1377  return nullptr;
1378 }
static bool simple_predicate_has_simple_cast(const std::shared_ptr< Analyzer::Expr > cast_operand, const std::shared_ptr< Analyzer::Expr > const_operand)
Definition: Analyzer.cpp:1313
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
SQLQualifier qualifier
Definition: Analyzer.h:507
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
Definition: sqldefs.h:69
#define COMMUTE_COMPARISON(X)
Definition: sqldefs.h:63
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:99
bool contains_agg
Definition: Analyzer.h:176
#define IS_COMPARISON(X)
Definition: sqldefs.h:57
+ Here is the call graph for this function:

◆ operator==()

bool Analyzer::BinOper::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2017 of file Analyzer.cpp.

References get_left_operand(), get_optype(), and get_right_operand().

2017  {
2018  if (typeid(rhs) != typeid(BinOper)) {
2019  return false;
2020  }
2021  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2022  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2023  *right_operand == *rhs_bo.get_right_operand();
2024 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
BinOper(const SQLTypeInfo &ti, bool has_agg, SQLOps o, SQLQualifier q, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
Definition: Analyzer.h:415
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
+ Here is the call graph for this function:

◆ rewrite_agg_to_var()

std::shared_ptr<Analyzer::Expr> Analyzer::BinOper::rewrite_agg_to_var ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 488 of file Analyzer.h.

References operator==().

489  {
490  return makeExpr<BinOper>(type_info,
491  contains_agg,
492  optype,
493  qualifier,
494  left_operand->rewrite_agg_to_var(tlist),
495  right_operand->rewrite_agg_to_var(tlist));
496  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
SQLQualifier qualifier
Definition: Analyzer.h:507
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
bool contains_agg
Definition: Analyzer.h:176
+ Here is the call graph for this function:

◆ rewrite_with_child_targetlist()

std::shared_ptr<Analyzer::Expr> Analyzer::BinOper::rewrite_with_child_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 479 of file Analyzer.h.

480  {
481  return makeExpr<BinOper>(type_info,
482  contains_agg,
483  optype,
484  qualifier,
485  left_operand->rewrite_with_child_targetlist(tlist),
486  right_operand->rewrite_with_child_targetlist(tlist));
487  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
SQLQualifier qualifier
Definition: Analyzer.h:507
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
bool contains_agg
Definition: Analyzer.h:176

◆ rewrite_with_targetlist()

std::shared_ptr<Analyzer::Expr> Analyzer::BinOper::rewrite_with_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 470 of file Analyzer.h.

471  {
472  return makeExpr<BinOper>(type_info,
473  contains_agg,
474  optype,
475  qualifier,
476  left_operand->rewrite_with_targetlist(tlist),
477  right_operand->rewrite_with_targetlist(tlist));
478  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
SQLQualifier qualifier
Definition: Analyzer.h:507
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
bool contains_agg
Definition: Analyzer.h:176

◆ simple_predicate_has_simple_cast()

bool Analyzer::BinOper::simple_predicate_has_simple_cast ( const std::shared_ptr< Analyzer::Expr cast_operand,
const std::shared_ptr< Analyzer::Expr const_operand 
)
static

Definition at line 1313 of file Analyzer.cpp.

References Analyzer::Expr::get_type_info(), and kCAST.

Referenced by normalize_simple_predicate().

1315  {
1316  if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1317  auto u_expr = std::dynamic_pointer_cast<UOper>(cast_operand);
1318  if (u_expr->get_optype() != kCAST) {
1319  return false;
1320  }
1321  if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1322  !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1323  return false;
1324  }
1325  const auto& ti = u_expr->get_type_info();
1326  if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1327  // Allow casts between time types to pass through
1328  return true;
1329  } else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1330  // Allow casts between integer types to pass through
1331  return true;
1332  }
1333  }
1334  return false;
1335 }
Definition: sqldefs.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

std::string Analyzer::BinOper::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2308 of file Analyzer.cpp.

References kALL, kAND, kANY, kARRAY_AT, kDIVIDE, kEQ, kGE, kGT, kLE, kLT, kMINUS, kMODULO, kMULTIPLY, kNE, kOR, kOVERLAPS, and kPLUS.

Referenced by CodeGenerator::getArithWithOverflowIntrinsic().

2308  {
2309  std::string op;
2310  switch (optype) {
2311  case kEQ:
2312  op = "= ";
2313  break;
2314  case kNE:
2315  op = "<> ";
2316  break;
2317  case kLT:
2318  op = "< ";
2319  break;
2320  case kLE:
2321  op = "<= ";
2322  break;
2323  case kGT:
2324  op = "> ";
2325  break;
2326  case kGE:
2327  op = ">= ";
2328  break;
2329  case kAND:
2330  op = "AND ";
2331  break;
2332  case kOR:
2333  op = "OR ";
2334  break;
2335  case kMINUS:
2336  op = "- ";
2337  break;
2338  case kPLUS:
2339  op = "+ ";
2340  break;
2341  case kMULTIPLY:
2342  op = "* ";
2343  break;
2344  case kDIVIDE:
2345  op = "/ ";
2346  break;
2347  case kMODULO:
2348  op = "% ";
2349  break;
2350  case kARRAY_AT:
2351  op = "[] ";
2352  break;
2353  case kOVERLAPS:
2354  op = "OVERLAPS ";
2355  break;
2356  default:
2357  break;
2358  }
2359  std::string str{"("};
2360  str += op;
2361  if (qualifier == kANY) {
2362  str += "ANY ";
2363  } else if (qualifier == kALL) {
2364  str += "ALL ";
2365  }
2366  str += left_operand->toString();
2367  str += right_operand->toString();
2368  str += ") ";
2369  return str;
2370 }
Definition: sqldefs.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:510
Definition: sqldefs.h:35
Definition: sqldefs.h:36
Definition: sqldefs.h:38
Definition: sqldefs.h:30
Definition: sqldefs.h:41
SQLQualifier qualifier
Definition: Analyzer.h:507
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:509
Definition: sqldefs.h:37
Definition: sqldefs.h:69
Definition: sqldefs.h:34
Definition: sqldefs.h:40
Definition: sqldefs.h:32
Definition: sqldefs.h:33
+ Here is the caller graph for this function:

Member Data Documentation

◆ left_operand

std::shared_ptr<Analyzer::Expr> Analyzer::BinOper::left_operand
private

Definition at line 509 of file Analyzer.h.

◆ optype

SQLOps Analyzer::BinOper::optype
private

Definition at line 506 of file Analyzer.h.

◆ qualifier

SQLQualifier Analyzer::BinOper::qualifier
private

Definition at line 507 of file Analyzer.h.

◆ right_operand

std::shared_ptr<Analyzer::Expr> Analyzer::BinOper::right_operand
private

Definition at line 510 of file Analyzer.h.


The documentation for this class was generated from the following files: