OmniSciDB  085a039ca4
 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 size_t get_num_column_vars (const bool include_agg) const
 
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 427 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 429 of file Analyzer.h.

435  : Expr(ti, has_agg), optype(o), qualifier(q), left_operand(l), right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:72
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
SQLQualifier qualifier
Definition: Analyzer.h:521
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
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 436 of file Analyzer.h.

441  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
442  , optype(o)
443  , qualifier(q)
444  , left_operand(l)
445  , right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:72
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
SQLQualifier qualifier
Definition: Analyzer.h:521
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523

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

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

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

References left_operand, and right_operand.

1451  {
1452  left_operand->check_group_by(groupby);
1453  right_operand->check_group_by(groupby);
1454 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
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 477 of file Analyzer.h.

References left_operand, and right_operand.

480  {
481  left_operand->collect_column_var(colvar_set, include_agg);
482  right_operand->collect_column_var(colvar_set, include_agg);
483  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
void Analyzer::BinOper::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 473 of file Analyzer.h.

References left_operand, and right_operand.

473  {
474  left_operand->collect_rte_idx(rte_idx_set);
475  right_operand->collect_rte_idx(rte_idx_set);
476  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
SQLTypeInfo Analyzer::BinOper::common_numeric_type ( const SQLTypeInfo type1,
const SQLTypeInfo type2 
)
static

Definition at line 455 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().

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

416  {
417  SQLTypeInfo common_type;
419  int comp_param = 0;
420  CHECK(type1.is_string() && type2.is_string());
421  // if type1 and type2 have the same DICT encoding then keep it
422  // otherwise, they must be decompressed
423  if (type1.get_compression() == kENCODING_DICT &&
424  type2.get_compression() == kENCODING_DICT) {
425  if (type1.get_comp_param() == type2.get_comp_param() ||
426  type1.get_comp_param() == TRANSIENT_DICT(type2.get_comp_param())) {
427  comp = kENCODING_DICT;
428  comp_param = std::min(type1.get_comp_param(), type2.get_comp_param());
429  }
430  } else if (type1.get_compression() == kENCODING_DICT &&
431  type2.get_compression() == kENCODING_NONE) {
432  comp_param = type1.get_comp_param();
433  } else if (type1.get_compression() == kENCODING_NONE &&
434  type2.get_compression() == kENCODING_DICT) {
435  comp_param = type2.get_comp_param();
436  } else {
437  comp_param = std::max(type1.get_comp_param(),
438  type2.get_comp_param()); // preserve previous comp_param if set
439  }
440  const bool notnull = type1.get_notnull() && type2.get_notnull();
441  if (type1.get_type() == kTEXT || type2.get_type() == kTEXT) {
442  common_type = SQLTypeInfo(kTEXT, 0, 0, notnull, comp, comp_param, kNULLT);
443  return common_type;
444  }
445  common_type = SQLTypeInfo(kVARCHAR,
446  std::max(type1.get_dimension(), type2.get_dimension()),
447  0,
448  notnull,
449  comp,
450  comp_param,
451  kNULLT);
452  return common_type;
453 }
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:223
bool is_string() const
Definition: sqltypes.h:510
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 108 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().

108  {
109  return makeExpr<BinOper>(type_info,
110  contains_agg,
111  optype,
112  qualifier,
113  left_operand->deep_copy(),
114  right_operand->deep_copy());
115 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
SQLQualifier qualifier
Definition: Analyzer.h:521
SQLTypeInfo type_info
Definition: Analyzer.h:182
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
bool contains_agg
Definition: Analyzer.h:183

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

References Analyzer::Expr::add_unique(), anonymous_namespace{Utm.h}::f, left_operand, and right_operand.

2998  {
2999  if (f(this)) {
3000  add_unique(expr_list);
3001  return;
3002  }
3003  left_operand->find_expr(f, expr_list);
3004  right_operand->find_expr(f, expr_list);
3005 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2988
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523

+ Here is the call graph for this function:

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

Definition at line 449 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().

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

+ Here is the caller graph for this function:

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

Definition at line 454 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().

454  {
455  return right_operand;
456  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524

+ Here is the caller graph for this function:

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

Definition at line 448 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().

448 { return qualifier; }
SQLQualifier qualifier
Definition: Analyzer.h:521

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

References kAND, left_operand, optype, and right_operand.

1556  {
1557  if (optype == kAND) {
1558  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1559  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1560  return;
1561  }
1562  std::set<int> rte_idx_set;
1563  left_operand->collect_rte_idx(rte_idx_set);
1564  right_operand->collect_rte_idx(rte_idx_set);
1565  if (rte_idx_set.size() > 1) {
1566  join_predicates.push_back(this);
1567  } else if (rte_idx_set.size() == 1) {
1568  scan_predicates.push_back(this);
1569  } else {
1570  const_predicates.push_back(this);
1571  }
1572 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
Definition: sqldefs.h:37
bool Analyzer::BinOper::is_overlaps_oper ( ) const
inline

Definition at line 447 of file Analyzer.h.

References kOVERLAPS, and optype.

Referenced by HashJoin::normalizeColumnPairs().

447 { 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 1489 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.

1489  {
1490  rte_idx = -1;
1491  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1492  return nullptr;
1493  }
1494  if (expr_is<UOper>(left_operand)) {
1496  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1497  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1498  rte_idx = cv->get_rte_idx();
1499  return this->deep_copy();
1500  }
1501  } else if (expr_is<UOper>(right_operand)) {
1503  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1504  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1505  rte_idx = cv->get_rte_idx();
1506  return makeExpr<BinOper>(type_info,
1507  contains_agg,
1509  qualifier,
1510  right_operand->deep_copy(),
1511  left_operand->deep_copy());
1512  }
1513  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1514  expr_is<Constant>(right_operand)) {
1515  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1516  rte_idx = cv->get_rte_idx();
1517  return this->deep_copy();
1518  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1519  !expr_is<Var>(right_operand)) {
1520  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1521  rte_idx = cv->get_rte_idx();
1522  return makeExpr<BinOper>(type_info,
1523  contains_agg,
1525  qualifier,
1526  right_operand->deep_copy(),
1527  left_operand->deep_copy());
1528  }
1529  return nullptr;
1530 }
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:1465
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
SQLQualifier qualifier
Definition: Analyzer.h:521
SQLTypeInfo type_info
Definition: Analyzer.h:182
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
Definition: sqldefs.h:71
#define COMMUTE_COMPARISON(X)
Definition: sqldefs.h:64
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:108
bool contains_agg
Definition: Analyzer.h:183
#define IS_COMPARISON(X)
Definition: sqldefs.h:58

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2240 of file Analyzer.cpp.

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

2240  {
2241  if (typeid(rhs) != typeid(BinOper)) {
2242  return false;
2243  }
2244  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2245  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2246  *right_operand == *rhs_bo.get_right_operand();
2247 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
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:429
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523

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

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

503  {
504  return makeExpr<BinOper>(type_info,
505  contains_agg,
506  optype,
507  qualifier,
508  left_operand->rewrite_agg_to_var(tlist),
509  right_operand->rewrite_agg_to_var(tlist));
510  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
SQLQualifier qualifier
Definition: Analyzer.h:521
SQLTypeInfo type_info
Definition: Analyzer.h:182
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
bool contains_agg
Definition: Analyzer.h:183
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 493 of file Analyzer.h.

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

494  {
495  return makeExpr<BinOper>(type_info,
496  contains_agg,
497  optype,
498  qualifier,
499  left_operand->rewrite_with_child_targetlist(tlist),
500  right_operand->rewrite_with_child_targetlist(tlist));
501  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
SQLQualifier qualifier
Definition: Analyzer.h:521
SQLTypeInfo type_info
Definition: Analyzer.h:182
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
bool contains_agg
Definition: Analyzer.h:183
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 484 of file Analyzer.h.

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

485  {
486  return makeExpr<BinOper>(type_info,
487  contains_agg,
488  optype,
489  qualifier,
490  left_operand->rewrite_with_targetlist(tlist),
491  right_operand->rewrite_with_targetlist(tlist));
492  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
SQLQualifier qualifier
Definition: Analyzer.h:521
SQLTypeInfo type_info
Definition: Analyzer.h:182
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
bool contains_agg
Definition: Analyzer.h:183
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 1465 of file Analyzer.cpp.

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

Referenced by normalize_simple_predicate().

1467  {
1468  if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1469  auto u_expr = std::dynamic_pointer_cast<UOper>(cast_operand);
1470  if (u_expr->get_optype() != kCAST) {
1471  return false;
1472  }
1473  if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1474  !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1475  return false;
1476  }
1477  const auto& ti = u_expr->get_type_info();
1478  if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1479  // Allow casts between time types to pass through
1480  return true;
1481  } else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1482  // Allow casts between integer types to pass through
1483  return true;
1484  }
1485  }
1486  return false;
1487 }
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 2605 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().

2605  {
2606  std::string op;
2607  switch (optype) {
2608  case kEQ:
2609  op = "= ";
2610  break;
2611  case kNE:
2612  op = "<> ";
2613  break;
2614  case kLT:
2615  op = "< ";
2616  break;
2617  case kLE:
2618  op = "<= ";
2619  break;
2620  case kGT:
2621  op = "> ";
2622  break;
2623  case kGE:
2624  op = ">= ";
2625  break;
2626  case kAND:
2627  op = "AND ";
2628  break;
2629  case kOR:
2630  op = "OR ";
2631  break;
2632  case kMINUS:
2633  op = "- ";
2634  break;
2635  case kPLUS:
2636  op = "+ ";
2637  break;
2638  case kMULTIPLY:
2639  op = "* ";
2640  break;
2641  case kDIVIDE:
2642  op = "/ ";
2643  break;
2644  case kMODULO:
2645  op = "% ";
2646  break;
2647  case kARRAY_AT:
2648  op = "[] ";
2649  break;
2650  case kOVERLAPS:
2651  op = "OVERLAPS ";
2652  break;
2653  default:
2654  break;
2655  }
2656  std::string str{"("};
2657  str += op;
2658  if (qualifier == kANY) {
2659  str += "ANY ";
2660  } else if (qualifier == kALL) {
2661  str += "ALL ";
2662  }
2663  str += left_operand->toString();
2664  str += right_operand->toString();
2665  str += ") ";
2666  return str;
2667 }
Definition: sqldefs.h:71
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
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:521
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
Definition: sqldefs.h:37
Definition: sqldefs.h:71
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: