OmniSciDB  8fa3bf436f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 420 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 422 of file Analyzer.h.

428  : 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:517
tuple r
Definition: test_fsi.py:16
SQLQualifier qualifier
Definition: Analyzer.h:514
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
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 429 of file Analyzer.h.

434  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
435  , optype(o)
436  , qualifier(q)
437  , left_operand(l)
438  , right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
tuple r
Definition: test_fsi.py:16
SQLQualifier qualifier
Definition: Analyzer.h:514
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
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 222 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().

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

References left_operand, and right_operand.

1433  {
1434  left_operand->check_group_by(groupby);
1435  right_operand->check_group_by(groupby);
1436 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
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 470 of file Analyzer.h.

References left_operand, and right_operand.

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

Reimplemented from Analyzer::Expr.

Definition at line 466 of file Analyzer.h.

References left_operand, and right_operand.

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

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

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

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

398  {
399  SQLTypeInfo common_type;
401  int comp_param = 0;
402  CHECK(type1.is_string() && type2.is_string());
403  // if type1 and type2 have the same DICT encoding then keep it
404  // otherwise, they must be decompressed
405  if (type1.get_compression() == kENCODING_DICT &&
406  type2.get_compression() == kENCODING_DICT) {
407  if (type1.get_comp_param() == type2.get_comp_param() ||
408  type1.get_comp_param() == TRANSIENT_DICT(type2.get_comp_param())) {
409  comp = kENCODING_DICT;
410  comp_param = std::min(type1.get_comp_param(), type2.get_comp_param());
411  }
412  } else if (type1.get_compression() == kENCODING_DICT &&
413  type2.get_compression() == kENCODING_NONE) {
414  comp_param = type1.get_comp_param();
415  } else if (type1.get_compression() == kENCODING_NONE &&
416  type2.get_compression() == kENCODING_DICT) {
417  comp_param = type2.get_comp_param();
418  } else {
419  comp_param = std::max(type1.get_comp_param(),
420  type2.get_comp_param()); // preserve previous comp_param if set
421  }
422  const bool notnull = type1.get_notnull() && type2.get_notnull();
423  if (type1.get_type() == kTEXT || type2.get_type() == kTEXT) {
424  common_type = SQLTypeInfo(kTEXT, 0, 0, notnull, comp, comp_param, kNULLT);
425  return common_type;
426  }
427  common_type = SQLTypeInfo(kVARCHAR,
428  std::max(type1.get_dimension(), type2.get_dimension()),
429  0,
430  notnull,
431  comp,
432  comp_param,
433  kNULLT);
434  return common_type;
435 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
EncodingType
Definition: sqltypes.h:227
Definition: sqltypes.h:51
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:316
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:323
#define CHECK(condition)
Definition: Logger.h:203
bool is_string() const
Definition: sqltypes.h:489
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:321
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:254

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

98  {
99  return makeExpr<BinOper>(type_info,
100  contains_agg,
101  optype,
102  qualifier,
103  left_operand->deep_copy(),
104  right_operand->deep_copy());
105 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
SQLQualifier qualifier
Definition: Analyzer.h:514
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
bool contains_agg
Definition: Analyzer.h:177

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

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

2878  {
2879  if (f(this)) {
2880  add_unique(expr_list);
2881  return;
2882  }
2883  left_operand->find_expr(f, expr_list);
2884  right_operand->find_expr(f, expr_list);
2885 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2868
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
char * f

+ Here is the call graph for this function:

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

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

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

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

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

+ Here is the caller graph for this function:

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

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

441 { return qualifier; }
SQLQualifier qualifier
Definition: Analyzer.h:514

+ Here is the caller graph for this function:

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

References kAND, left_operand, optype, and right_operand.

1538  {
1539  if (optype == kAND) {
1540  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1541  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1542  return;
1543  }
1544  std::set<int> rte_idx_set;
1545  left_operand->collect_rte_idx(rte_idx_set);
1546  right_operand->collect_rte_idx(rte_idx_set);
1547  if (rte_idx_set.size() > 1) {
1548  join_predicates.push_back(this);
1549  } else if (rte_idx_set.size() == 1) {
1550  scan_predicates.push_back(this);
1551  } else {
1552  const_predicates.push_back(this);
1553  }
1554 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
Definition: sqldefs.h:37
bool Analyzer::BinOper::is_overlaps_oper ( ) const
inline

Definition at line 440 of file Analyzer.h.

References kOVERLAPS, and optype.

Referenced by normalize_column_pairs().

440 { 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 1471 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.

1471  {
1472  rte_idx = -1;
1473  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1474  return nullptr;
1475  }
1476  if (expr_is<UOper>(left_operand)) {
1478  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1479  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1480  rte_idx = cv->get_rte_idx();
1481  return this->deep_copy();
1482  }
1483  } else if (expr_is<UOper>(right_operand)) {
1485  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1486  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1487  rte_idx = cv->get_rte_idx();
1488  return makeExpr<BinOper>(type_info,
1489  contains_agg,
1491  qualifier,
1492  right_operand->deep_copy(),
1493  left_operand->deep_copy());
1494  }
1495  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1496  expr_is<Constant>(right_operand)) {
1497  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1498  rte_idx = cv->get_rte_idx();
1499  return this->deep_copy();
1500  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1501  !expr_is<Var>(right_operand)) {
1502  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1503  rte_idx = cv->get_rte_idx();
1504  return makeExpr<BinOper>(type_info,
1505  contains_agg,
1507  qualifier,
1508  right_operand->deep_copy(),
1509  left_operand->deep_copy());
1510  }
1511  return nullptr;
1512 }
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:1447
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
SQLQualifier qualifier
Definition: Analyzer.h:514
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
Definition: sqldefs.h:69
#define COMMUTE_COMPARISON(X)
Definition: sqldefs.h:63
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:98
bool contains_agg
Definition: Analyzer.h:177
#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 2179 of file Analyzer.cpp.

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

2179  {
2180  if (typeid(rhs) != typeid(BinOper)) {
2181  return false;
2182  }
2183  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2184  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2185  *right_operand == *rhs_bo.get_right_operand();
2186 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
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:422
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516

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

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

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

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

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

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

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

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

Referenced by normalize_simple_predicate().

1449  {
1450  if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1451  auto u_expr = std::dynamic_pointer_cast<UOper>(cast_operand);
1452  if (u_expr->get_optype() != kCAST) {
1453  return false;
1454  }
1455  if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1456  !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1457  return false;
1458  }
1459  const auto& ti = u_expr->get_type_info();
1460  if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1461  // Allow casts between time types to pass through
1462  return true;
1463  } else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1464  // Allow casts between integer types to pass through
1465  return true;
1466  }
1467  }
1468  return false;
1469 }
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 2521 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().

2521  {
2522  std::string op;
2523  switch (optype) {
2524  case kEQ:
2525  op = "= ";
2526  break;
2527  case kNE:
2528  op = "<> ";
2529  break;
2530  case kLT:
2531  op = "< ";
2532  break;
2533  case kLE:
2534  op = "<= ";
2535  break;
2536  case kGT:
2537  op = "> ";
2538  break;
2539  case kGE:
2540  op = ">= ";
2541  break;
2542  case kAND:
2543  op = "AND ";
2544  break;
2545  case kOR:
2546  op = "OR ";
2547  break;
2548  case kMINUS:
2549  op = "- ";
2550  break;
2551  case kPLUS:
2552  op = "+ ";
2553  break;
2554  case kMULTIPLY:
2555  op = "* ";
2556  break;
2557  case kDIVIDE:
2558  op = "/ ";
2559  break;
2560  case kMODULO:
2561  op = "% ";
2562  break;
2563  case kARRAY_AT:
2564  op = "[] ";
2565  break;
2566  case kOVERLAPS:
2567  op = "OVERLAPS ";
2568  break;
2569  default:
2570  break;
2571  }
2572  std::string str{"("};
2573  str += op;
2574  if (qualifier == kANY) {
2575  str += "ANY ";
2576  } else if (qualifier == kALL) {
2577  str += "ALL ";
2578  }
2579  str += left_operand->toString();
2580  str += right_operand->toString();
2581  str += ") ";
2582  return str;
2583 }
Definition: sqldefs.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:517
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:514
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:516
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: