OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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::Expr
get_own_left_operand () const
 
const std::shared_ptr
< Analyzer::Expr
get_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 ()
 
std::shared_ptr< Analyzer::Exprget_shared_ptr ()
 
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::Expr
add_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 419 of file Analyzer.h.

Constructor & Destructor Documentation

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 421 of file Analyzer.h.

427  : Expr(ti, has_agg), optype(o), qualifier(q), left_operand(l), right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
SQLQualifier qualifier
Definition: Analyzer.h:513
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
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 428 of file Analyzer.h.

433  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
434  , optype(o)
435  , qualifier(q)
436  , left_operand(l)
437  , right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
SQLQualifier qualifier
Definition: Analyzer.h:513
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
char * t

Member Function Documentation

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 236 of file Analyzer.cpp.

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

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

240  {
241  SQLTypeInfo result_type;
242  SQLTypeInfo common_type;
243  *new_left_type = left_type;
244  *new_right_type = right_type;
245  if (IS_LOGIC(op)) {
246  if (left_type.get_type() != kBOOLEAN || right_type.get_type() != kBOOLEAN) {
247  throw std::runtime_error(
248  "non-boolean operands cannot be used in logic operations.");
249  }
250  result_type = SQLTypeInfo(kBOOLEAN, false);
251  } else if (IS_COMPARISON(op)) {
252  if (left_type != right_type) {
253  if (left_type.is_number() && right_type.is_number()) {
254  common_type = common_numeric_type(left_type, right_type);
255  *new_left_type = common_type;
256  new_left_type->set_notnull(left_type.get_notnull());
257  *new_right_type = common_type;
258  new_right_type->set_notnull(right_type.get_notnull());
259  } else if (left_type.is_time() && right_type.is_time()) {
260  switch (left_type.get_type()) {
261  case kTIMESTAMP:
262  switch (right_type.get_type()) {
263  case kTIME:
264  throw std::runtime_error("Cannont compare between TIMESTAMP and TIME.");
265  break;
266  case kDATE:
267  *new_left_type = SQLTypeInfo(left_type.get_type(),
268  left_type.get_dimension(),
269  0,
270  left_type.get_notnull());
271  *new_right_type = *new_left_type;
272  new_right_type->set_notnull(right_type.get_notnull());
273  break;
274  case kTIMESTAMP:
275  *new_left_type = SQLTypeInfo(
276  kTIMESTAMP,
277  std::max(left_type.get_dimension(), right_type.get_dimension()),
278  0,
279  left_type.get_notnull());
280  *new_right_type = SQLTypeInfo(
281  kTIMESTAMP,
282  std::max(left_type.get_dimension(), right_type.get_dimension()),
283  0,
284  right_type.get_notnull());
285  break;
286  default:
287  CHECK(false);
288  }
289  break;
290  case kTIME:
291  switch (right_type.get_type()) {
292  case kTIMESTAMP:
293  throw std::runtime_error("Cannont compare between TIME and TIMESTAMP.");
294  break;
295  case kDATE:
296  throw std::runtime_error("Cannont compare between TIME and DATE.");
297  break;
298  case kTIME:
299  *new_left_type = SQLTypeInfo(
300  kTIME,
301  std::max(left_type.get_dimension(), right_type.get_dimension()),
302  0,
303  left_type.get_notnull());
304  *new_right_type = SQLTypeInfo(
305  kTIME,
306  std::max(left_type.get_dimension(), right_type.get_dimension()),
307  0,
308  right_type.get_notnull());
309  break;
310  default:
311  CHECK(false);
312  }
313  break;
314  case kDATE:
315  switch (right_type.get_type()) {
316  case kTIMESTAMP:
317  *new_left_type = SQLTypeInfo(right_type.get_type(),
318  right_type.get_dimension(),
319  0,
320  left_type.get_notnull());
321  *new_right_type = *new_left_type;
322  new_right_type->set_notnull(right_type.get_notnull());
323  break;
324  case kDATE:
325  *new_left_type = SQLTypeInfo(left_type.get_type(),
326  left_type.get_dimension(),
327  0,
328  left_type.get_notnull());
329  *new_right_type = *new_left_type;
330  new_right_type->set_notnull(right_type.get_notnull());
331  break;
332  case kTIME:
333  throw std::runtime_error("Cannont compare between DATE and TIME.");
334  break;
335  default:
336  CHECK(false);
337  }
338  break;
339  default:
340  CHECK(false);
341  }
342  } else if (left_type.is_string() && right_type.is_time()) {
343  *new_left_type = right_type;
344  new_left_type->set_notnull(left_type.get_notnull());
345  *new_right_type = right_type;
346  } else if (left_type.is_time() && right_type.is_string()) {
347  *new_left_type = left_type;
348  *new_right_type = left_type;
349  new_right_type->set_notnull(right_type.get_notnull());
350  } else if (left_type.is_string() && right_type.is_string()) {
351  *new_left_type = left_type;
352  *new_right_type = right_type;
353  } else if (left_type.is_boolean() && right_type.is_boolean()) {
354  const bool notnull = left_type.get_notnull() && right_type.get_notnull();
355  common_type = SQLTypeInfo(kBOOLEAN, notnull);
356  *new_left_type = common_type;
357  *new_right_type = common_type;
358  } else {
359  throw std::runtime_error("Cannot compare between " + left_type.get_type_name() +
360  " and " + right_type.get_type_name());
361  }
362  }
363  result_type = SQLTypeInfo(kBOOLEAN, false);
364  } else if (op == kMINUS &&
365  (left_type.get_type() == kDATE || left_type.get_type() == kTIMESTAMP) &&
366  right_type.is_timeinterval()) {
367  *new_left_type = left_type;
368  *new_right_type = right_type;
369  result_type = left_type;
370  } else if (IS_ARITHMETIC(op)) {
371  if (!(left_type.is_number() || left_type.is_timeinterval()) ||
372  !(right_type.is_number() || right_type.is_timeinterval())) {
373  throw std::runtime_error("non-numeric operands in arithmetic operations.");
374  }
375  if (op == kMODULO && (!left_type.is_integer() || !right_type.is_integer())) {
376  throw std::runtime_error("non-integer operands in modulo operation.");
377  }
378  common_type = common_numeric_type(left_type, right_type);
379  if (common_type.is_decimal()) {
380  if (op == kMULTIPLY) {
381  // Decimal multiplication requires common_type adjustment:
382  // dimension and scale of the result should be increased.
383  auto new_dimension = left_type.get_dimension() + right_type.get_dimension();
384  // If new dimension is over 20 digits, the result may overflow, or it may not.
385  // Rely on the runtime overflow detection rather than a static check here.
386  if (common_type.get_dimension() < new_dimension) {
387  common_type.set_dimension(new_dimension);
388  }
389  common_type.set_scale(left_type.get_scale() + right_type.get_scale());
390  } else if (op == kPLUS || op == kMINUS) {
391  // Scale should remain the same but dimension could actually go up
392  common_type.set_dimension(common_type.get_dimension() + 1);
393  }
394  }
395  *new_left_type = common_type;
396  new_left_type->set_notnull(left_type.get_notnull());
397  *new_right_type = common_type;
398  new_right_type->set_notnull(right_type.get_notnull());
399  if (op == kMULTIPLY) {
400  new_left_type->set_scale(left_type.get_scale());
401  new_right_type->set_scale(right_type.get_scale());
402  }
403  result_type = common_type;
404  } else {
405  throw std::runtime_error("invalid binary operator type.");
406  }
407  result_type.set_notnull(left_type.get_notnull() && right_type.get_notnull());
408  return result_type;
409 }
#define IS_LOGIC(X)
Definition: sqldefs.h:60
Definition: sqltypes.h:49
HOST DEVICE int get_scale() const
Definition: sqltypes.h:334
Definition: sqldefs.h:41
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
bool is_number() const
Definition: sqltypes.h:514
bool is_time() const
Definition: sqltypes.h:515
bool is_integer() const
Definition: sqltypes.h:511
void set_scale(int s)
Definition: sqltypes.h:424
bool is_timeinterval() const
Definition: sqltypes.h:520
static SQLTypeInfo common_numeric_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
Definition: Analyzer.cpp:451
bool is_boolean() const
Definition: sqltypes.h:516
Definition: sqltypes.h:53
Definition: sqldefs.h:40
#define IS_ARITHMETIC(X)
Definition: sqldefs.h:61
void set_dimension(int d)
Definition: sqltypes.h:421
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
std::string get_type_name() const
Definition: sqltypes.h:432
void set_notnull(bool n)
Definition: sqltypes.h:426
#define CHECK(condition)
Definition: Logger.h:209
bool is_string() const
Definition: sqltypes.h:509
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
bool is_decimal() const
Definition: sqltypes.h:512
#define IS_COMPARISON(X)
Definition: sqldefs.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Reimplemented from Analyzer::Expr.

Definition at line 1444 of file Analyzer.cpp.

References left_operand, and right_operand.

1445  {
1446  left_operand->check_group_by(groupby);
1447  right_operand->check_group_by(groupby);
1448 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
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 469 of file Analyzer.h.

References left_operand, and right_operand.

472  {
473  left_operand->collect_column_var(colvar_set, include_agg);
474  right_operand->collect_column_var(colvar_set, include_agg);
475  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
void Analyzer::BinOper::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 465 of file Analyzer.h.

References left_operand, and right_operand.

465  {
466  left_operand->collect_rte_idx(rte_idx_set);
467  right_operand->collect_rte_idx(rte_idx_set);
468  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
SQLTypeInfo Analyzer::BinOper::common_numeric_type ( const SQLTypeInfo type1,
const SQLTypeInfo type2 
)
static

Definition at line 451 of file Analyzer.cpp.

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

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

452  {
453  SQLTypeInfo common_type;
454  const bool notnull = type1.get_notnull() && type2.get_notnull();
455  if (type1.get_type() == type2.get_type()) {
456  CHECK(((type1.is_number() || type1.is_timeinterval()) &&
457  (type2.is_number() || type2.is_timeinterval())) ||
458  (type1.is_boolean() && type2.is_boolean()));
459  common_type = SQLTypeInfo(type1.get_type(),
460  std::max(type1.get_dimension(), type2.get_dimension()),
461  std::max(type1.get_scale(), type2.get_scale()),
462  notnull);
463  return common_type;
464  }
465  std::string timeinterval_op_error{
466  "Operator type not supported for time interval arithmetic: "};
467  if (type1.is_timeinterval()) {
468  if (!type2.is_integer()) {
469  throw std::runtime_error(timeinterval_op_error + type2.get_type_name());
470  }
471  return type1;
472  }
473  if (type2.is_timeinterval()) {
474  if (!type1.is_integer()) {
475  throw std::runtime_error(timeinterval_op_error + type1.get_type_name());
476  }
477  return type2;
478  }
479  CHECK(type1.is_number() && type2.is_number());
480  switch (type1.get_type()) {
481  case kTINYINT:
482  switch (type2.get_type()) {
483  case kSMALLINT:
484  common_type = SQLTypeInfo(kSMALLINT, notnull);
485  break;
486  case kINT:
487  common_type = SQLTypeInfo(kINT, notnull);
488  break;
489  case kBIGINT:
490  common_type = SQLTypeInfo(kBIGINT, notnull);
491  break;
492  case kFLOAT:
493  common_type = SQLTypeInfo(kFLOAT, notnull);
494  break;
495  case kDOUBLE:
496  common_type = SQLTypeInfo(kDOUBLE, notnull);
497  break;
498  case kNUMERIC:
499  case kDECIMAL:
500  common_type =
502  std::max(5 + type2.get_scale(), type2.get_dimension()),
503  type2.get_scale(),
504  notnull);
505  break;
506  default:
507  CHECK(false);
508  }
509  break;
510  case kSMALLINT:
511  switch (type2.get_type()) {
512  case kTINYINT:
513  common_type = SQLTypeInfo(kSMALLINT, notnull);
514  break;
515  case kINT:
516  common_type = SQLTypeInfo(kINT, notnull);
517  break;
518  case kBIGINT:
519  common_type = SQLTypeInfo(kBIGINT, notnull);
520  break;
521  case kFLOAT:
522  common_type = SQLTypeInfo(kFLOAT, notnull);
523  break;
524  case kDOUBLE:
525  common_type = SQLTypeInfo(kDOUBLE, notnull);
526  break;
527  case kNUMERIC:
528  case kDECIMAL:
529  common_type =
531  std::max(5 + type2.get_scale(), type2.get_dimension()),
532  type2.get_scale(),
533  notnull);
534  break;
535  default:
536  CHECK(false);
537  }
538  break;
539  case kINT:
540  switch (type2.get_type()) {
541  case kTINYINT:
542  common_type = SQLTypeInfo(kINT, notnull);
543  break;
544  case kSMALLINT:
545  common_type = SQLTypeInfo(kINT, notnull);
546  break;
547  case kBIGINT:
548  common_type = SQLTypeInfo(kBIGINT, notnull);
549  break;
550  case kFLOAT:
551  common_type = SQLTypeInfo(kFLOAT, notnull);
552  break;
553  case kDOUBLE:
554  common_type = SQLTypeInfo(kDOUBLE, notnull);
555  break;
556  case kNUMERIC:
557  case kDECIMAL:
558  common_type = SQLTypeInfo(
559  kDECIMAL,
560  std::max(std::min(19, 10 + type2.get_scale()), type2.get_dimension()),
561  type2.get_scale(),
562  notnull);
563  break;
564  default:
565  CHECK(false);
566  }
567  break;
568  case kBIGINT:
569  switch (type2.get_type()) {
570  case kTINYINT:
571  common_type = SQLTypeInfo(kBIGINT, notnull);
572  break;
573  case kSMALLINT:
574  common_type = SQLTypeInfo(kBIGINT, notnull);
575  break;
576  case kINT:
577  common_type = SQLTypeInfo(kBIGINT, notnull);
578  break;
579  case kFLOAT:
580  common_type = SQLTypeInfo(kFLOAT, notnull);
581  break;
582  case kDOUBLE:
583  common_type = SQLTypeInfo(kDOUBLE, notnull);
584  break;
585  case kNUMERIC:
586  case kDECIMAL:
587  common_type = SQLTypeInfo(kDECIMAL, 19, type2.get_scale(), notnull);
588  break;
589  default:
590  CHECK(false);
591  }
592  break;
593  case kFLOAT:
594  switch (type2.get_type()) {
595  case kTINYINT:
596  common_type = SQLTypeInfo(kFLOAT, notnull);
597  break;
598  case kSMALLINT:
599  common_type = SQLTypeInfo(kFLOAT, notnull);
600  break;
601  case kINT:
602  common_type = SQLTypeInfo(kFLOAT, notnull);
603  break;
604  case kBIGINT:
605  common_type = SQLTypeInfo(kFLOAT, notnull);
606  break;
607  case kDOUBLE:
608  common_type = SQLTypeInfo(kDOUBLE, notnull);
609  break;
610  case kNUMERIC:
611  case kDECIMAL:
612  common_type = SQLTypeInfo(kFLOAT, notnull);
613  break;
614  default:
615  CHECK(false);
616  }
617  break;
618  case kDOUBLE:
619  switch (type2.get_type()) {
620  case kTINYINT:
621  case kSMALLINT:
622  case kINT:
623  case kBIGINT:
624  case kFLOAT:
625  case kNUMERIC:
626  case kDECIMAL:
627  common_type = SQLTypeInfo(kDOUBLE, notnull);
628  break;
629  default:
630  CHECK(false);
631  }
632  break;
633  case kNUMERIC:
634  case kDECIMAL:
635  switch (type2.get_type()) {
636  case kTINYINT:
637  common_type =
639  std::max(3 + type1.get_scale(), type1.get_dimension()),
640  type1.get_scale(),
641  notnull);
642  break;
643  case kSMALLINT:
644  common_type =
646  std::max(5 + type1.get_scale(), type1.get_dimension()),
647  type1.get_scale(),
648  notnull);
649  break;
650  case kINT:
651  common_type = SQLTypeInfo(
652  kDECIMAL,
653  std::max(std::min(19, 10 + type1.get_scale()), type2.get_dimension()),
654  type1.get_scale(),
655  notnull);
656  break;
657  case kBIGINT:
658  common_type = SQLTypeInfo(kDECIMAL, 19, type1.get_scale(), notnull);
659  break;
660  case kFLOAT:
661  common_type = SQLTypeInfo(kFLOAT, notnull);
662  break;
663  case kDOUBLE:
664  common_type = SQLTypeInfo(kDOUBLE, notnull);
665  break;
666  case kNUMERIC:
667  case kDECIMAL: {
668  int common_scale = std::max(type1.get_scale(), type2.get_scale());
669  common_type = SQLTypeInfo(kDECIMAL,
670  std::max(type1.get_dimension() - type1.get_scale(),
671  type2.get_dimension() - type2.get_scale()) +
672  common_scale,
673  common_scale,
674  notnull);
675  break;
676  }
677  default:
678  CHECK(false);
679  }
680  break;
681  default:
682  CHECK(false);
683  }
684  common_type.set_fixed_size();
685  return common_type;
686 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:334
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
bool is_number() const
Definition: sqltypes.h:514
bool is_integer() const
Definition: sqltypes.h:511
bool is_timeinterval() const
Definition: sqltypes.h:520
bool is_boolean() const
Definition: sqltypes.h:516
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
std::string get_type_name() const
Definition: sqltypes.h:432
#define CHECK(condition)
Definition: Logger.h:209
Definition: sqltypes.h:45
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 411 of file Analyzer.cpp.

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

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

412  {
413  SQLTypeInfo common_type;
415  int comp_param = 0;
416  CHECK(type1.is_string() && type2.is_string());
417  // if type1 and type2 have the same DICT encoding then keep it
418  // otherwise, they must be decompressed
419  if (type1.get_compression() == kENCODING_DICT &&
420  type2.get_compression() == kENCODING_DICT) {
421  if (type1.get_comp_param() == type2.get_comp_param() ||
422  type1.get_comp_param() == TRANSIENT_DICT(type2.get_comp_param())) {
423  comp = kENCODING_DICT;
424  comp_param = std::min(type1.get_comp_param(), type2.get_comp_param());
425  }
426  } else if (type1.get_compression() == kENCODING_DICT &&
427  type2.get_compression() == kENCODING_NONE) {
428  comp_param = type1.get_comp_param();
429  } else if (type1.get_compression() == kENCODING_NONE &&
430  type2.get_compression() == kENCODING_DICT) {
431  comp_param = type2.get_comp_param();
432  } else {
433  comp_param = std::max(type1.get_comp_param(),
434  type2.get_comp_param()); // preserve previous comp_param if set
435  }
436  const bool notnull = type1.get_notnull() && type2.get_notnull();
437  if (type1.get_type() == kTEXT || type2.get_type() == kTEXT) {
438  common_type = SQLTypeInfo(kTEXT, 0, 0, notnull, comp, comp_param, kNULLT);
439  return common_type;
440  }
441  common_type = SQLTypeInfo(kVARCHAR,
442  std::max(type1.get_dimension(), type2.get_dimension()),
443  0,
444  notnull,
445  comp,
446  comp_param,
447  kNULLT);
448  return common_type;
449 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
EncodingType
Definition: sqltypes.h:233
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
#define CHECK(condition)
Definition: Logger.h:209
bool is_string() const
Definition: sqltypes.h:509
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:260

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

Definition at line 100 of file Analyzer.cpp.

References Analyzer::Expr::contains_agg, left_operand, optype, qualifier, right_operand, and Analyzer::Expr::type_info.

Referenced by normalize_simple_predicate().

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

+ Here is the caller graph for this function:

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

Reimplemented from Analyzer::Expr.

Definition at line 2975 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), f, left_operand, and right_operand.

2975  {
2976  if (f(this)) {
2977  add_unique(expr_list);
2978  return;
2979  }
2980  left_operand->find_expr(f, expr_list);
2981  right_operand->find_expr(f, expr_list);
2982 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2965
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
char * f

+ Here is the call graph for this function:

const Expr* Analyzer::BinOper::get_left_operand ( ) const
inline

Definition at line 441 of file Analyzer.h.

References left_operand.

Referenced by anonymous_namespace{CompareIR.cpp}::check_array_comp_cond(), CodeGenerator::checkExpressionRanges(), CodeGenerator::codegenArith(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenCmp(), CodeGenerator::codegenDeciDiv(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenIntArith(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), anonymous_namespace{PerfectJoinHashTable.cpp}::get_cols(), anonymous_namespace{HashJoin.cpp}::get_cols(), anonymous_namespace{LogicalIR.cpp}::get_likelihood(), anonymous_namespace{LogicalIR.cpp}::get_weight(), getExpressionRange(), CodeGenerator::hashJoinLhsTuple(), RelAlgExecutor::isRowidLookup(), anonymous_namespace{CompareIR.cpp}::lower_multicol_compare(), HashJoin::normalizeColumnPairs(), QueryPlanDagExtractor::normalizeColumnsPair(), operator==(), Executor::skipFragment(), ScalarExprToSql::visitBinOper(), anonymous_namespace{ExpressionRewrite.cpp}::OrToInVisitor::visitBinOper(), DeepCopyVisitor::visitBinOper(), ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitBinOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitBinOper().

441 { return left_operand.get(); }
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515

+ Here is the caller graph for this function:

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

Definition at line 443 of file Analyzer.h.

References left_operand.

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

443  {
444  return left_operand;
445  }
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515

+ Here is the caller graph for this function:

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

Definition at line 446 of file Analyzer.h.

References right_operand.

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

446  {
447  return right_operand;
448  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516

+ Here is the caller graph for this function:

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

Definition at line 440 of file Analyzer.h.

References qualifier.

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

440 { return qualifier; }
SQLQualifier qualifier
Definition: Analyzer.h:513

+ Here is the caller graph for this function:

const Expr* Analyzer::BinOper::get_right_operand ( ) const
inline
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 1548 of file Analyzer.cpp.

References kAND, left_operand, optype, and right_operand.

1550  {
1551  if (optype == kAND) {
1552  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1553  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1554  return;
1555  }
1556  std::set<int> rte_idx_set;
1557  left_operand->collect_rte_idx(rte_idx_set);
1558  right_operand->collect_rte_idx(rte_idx_set);
1559  if (rte_idx_set.size() > 1) {
1560  join_predicates.push_back(this);
1561  } else if (rte_idx_set.size() == 1) {
1562  scan_predicates.push_back(this);
1563  } else {
1564  const_predicates.push_back(this);
1565  }
1566 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
Definition: sqldefs.h:37
bool Analyzer::BinOper::is_overlaps_oper ( ) const
inline

Definition at line 439 of file Analyzer.h.

References kOVERLAPS, and optype.

Referenced by HashJoin::normalizeColumnPairs(), and QueryPlanDagExtractor::normalizeColumnsPair().

439 { return optype == kOVERLAPS; }

+ Here is the caller graph for this function:

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

Reimplemented from Analyzer::Expr.

Definition at line 1483 of file Analyzer.cpp.

References COMMUTE_COMPARISON, Analyzer::Expr::contains_agg, deep_copy(), Analyzer::ColumnVar::get_rte_idx(), IS_COMPARISON, kONE, left_operand, optype, qualifier, right_operand, simple_predicate_has_simple_cast(), and Analyzer::Expr::type_info.

1483  {
1484  rte_idx = -1;
1485  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1486  return nullptr;
1487  }
1488  if (expr_is<UOper>(left_operand)) {
1490  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1491  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1492  rte_idx = cv->get_rte_idx();
1493  return this->deep_copy();
1494  }
1495  } else if (expr_is<UOper>(right_operand)) {
1497  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1498  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1499  rte_idx = cv->get_rte_idx();
1500  return makeExpr<BinOper>(type_info,
1501  contains_agg,
1503  qualifier,
1504  right_operand->deep_copy(),
1505  left_operand->deep_copy());
1506  }
1507  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1508  expr_is<Constant>(right_operand)) {
1509  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1510  rte_idx = cv->get_rte_idx();
1511  return this->deep_copy();
1512  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1513  !expr_is<Var>(right_operand)) {
1514  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1515  rte_idx = cv->get_rte_idx();
1516  return makeExpr<BinOper>(type_info,
1517  contains_agg,
1519  qualifier,
1520  right_operand->deep_copy(),
1521  left_operand->deep_copy());
1522  }
1523  return nullptr;
1524 }
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:1459
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
SQLQualifier qualifier
Definition: Analyzer.h:513
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
Definition: sqldefs.h:69
#define COMMUTE_COMPARISON(X)
Definition: sqldefs.h:63
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:100
bool contains_agg
Definition: Analyzer.h:176
#define IS_COMPARISON(X)
Definition: sqldefs.h:57

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2205 of file Analyzer.cpp.

References get_left_operand(), get_optype(), get_right_operand(), left_operand, optype, and right_operand.

2205  {
2206  if (typeid(rhs) != typeid(BinOper)) {
2207  return false;
2208  }
2209  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2210  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2211  *right_operand == *rhs_bo.get_right_operand();
2212 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
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:421
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515

+ Here is the call graph for this function:

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 494 of file Analyzer.h.

References Analyzer::Expr::contains_agg, left_operand, optype, qualifier, right_operand, and Analyzer::Expr::type_info.

495  {
496  return makeExpr<BinOper>(type_info,
497  contains_agg,
498  optype,
499  qualifier,
500  left_operand->rewrite_agg_to_var(tlist),
501  right_operand->rewrite_agg_to_var(tlist));
502  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
SQLQualifier qualifier
Definition: Analyzer.h:513
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
bool contains_agg
Definition: Analyzer.h:176
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 485 of file Analyzer.h.

References Analyzer::Expr::contains_agg, left_operand, optype, qualifier, right_operand, and Analyzer::Expr::type_info.

486  {
487  return makeExpr<BinOper>(type_info,
488  contains_agg,
489  optype,
490  qualifier,
491  left_operand->rewrite_with_child_targetlist(tlist),
492  right_operand->rewrite_with_child_targetlist(tlist));
493  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
SQLQualifier qualifier
Definition: Analyzer.h:513
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
bool contains_agg
Definition: Analyzer.h:176
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 476 of file Analyzer.h.

References Analyzer::Expr::contains_agg, left_operand, optype, qualifier, right_operand, and Analyzer::Expr::type_info.

477  {
478  return makeExpr<BinOper>(type_info,
479  contains_agg,
480  optype,
481  qualifier,
482  left_operand->rewrite_with_targetlist(tlist),
483  right_operand->rewrite_with_targetlist(tlist));
484  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
SQLQualifier qualifier
Definition: Analyzer.h:513
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
bool contains_agg
Definition: Analyzer.h:176
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 1459 of file Analyzer.cpp.

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

Referenced by normalize_simple_predicate().

1461  {
1462  if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1463  auto u_expr = std::dynamic_pointer_cast<UOper>(cast_operand);
1464  if (u_expr->get_optype() != kCAST) {
1465  return false;
1466  }
1467  if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1468  !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1469  return false;
1470  }
1471  const auto& ti = u_expr->get_type_info();
1472  if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1473  // Allow casts between time types to pass through
1474  return true;
1475  } else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1476  // Allow casts between integer types to pass through
1477  return true;
1478  }
1479  }
1480  return false;
1481 }
Definition: sqldefs.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2578 of file Analyzer.cpp.

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

Referenced by CodeGenerator::getArithWithOverflowIntrinsic().

2578  {
2579  std::string op;
2580  switch (optype) {
2581  case kEQ:
2582  op = "= ";
2583  break;
2584  case kNE:
2585  op = "<> ";
2586  break;
2587  case kLT:
2588  op = "< ";
2589  break;
2590  case kLE:
2591  op = "<= ";
2592  break;
2593  case kGT:
2594  op = "> ";
2595  break;
2596  case kGE:
2597  op = ">= ";
2598  break;
2599  case kAND:
2600  op = "AND ";
2601  break;
2602  case kOR:
2603  op = "OR ";
2604  break;
2605  case kMINUS:
2606  op = "- ";
2607  break;
2608  case kPLUS:
2609  op = "+ ";
2610  break;
2611  case kMULTIPLY:
2612  op = "* ";
2613  break;
2614  case kDIVIDE:
2615  op = "/ ";
2616  break;
2617  case kMODULO:
2618  op = "% ";
2619  break;
2620  case kARRAY_AT:
2621  op = "[] ";
2622  break;
2623  case kOVERLAPS:
2624  op = "OVERLAPS ";
2625  break;
2626  default:
2627  break;
2628  }
2629  std::string str{"("};
2630  str += op;
2631  if (qualifier == kANY) {
2632  str += "ANY ";
2633  } else if (qualifier == kALL) {
2634  str += "ALL ";
2635  }
2636  str += left_operand->toString();
2637  str += right_operand->toString();
2638  str += ") ";
2639  return str;
2640 }
Definition: sqldefs.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:516
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:513
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:515
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


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