OmniSciDB  a667adc9c8
 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 221 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().

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

References left_operand, and right_operand.

1380  {
1381  left_operand->check_group_by(groupby);
1382  right_operand->check_group_by(groupby);
1383 }
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 436 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().

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

397  {
398  SQLTypeInfo common_type;
400  int comp_param = 0;
401  CHECK(type1.is_string() && type2.is_string());
402  // if type1 and type2 have the same DICT encoding then keep it
403  // otherwise, they must be decompressed
404  if (type1.get_compression() == kENCODING_DICT &&
405  type2.get_compression() == kENCODING_DICT) {
406  if (type1.get_comp_param() == type2.get_comp_param() ||
407  type1.get_comp_param() == TRANSIENT_DICT(type2.get_comp_param())) {
408  comp = kENCODING_DICT;
409  comp_param = std::min(type1.get_comp_param(), type2.get_comp_param());
410  }
411  } else if (type1.get_compression() == kENCODING_DICT &&
412  type2.get_compression() == kENCODING_NONE) {
413  comp_param = type1.get_comp_param();
414  } else if (type1.get_compression() == kENCODING_NONE &&
415  type2.get_compression() == kENCODING_DICT) {
416  comp_param = type2.get_comp_param();
417  } else {
418  comp_param = std::max(type1.get_comp_param(),
419  type2.get_comp_param()); // preserve previous comp_param if set
420  }
421  const bool notnull = type1.get_notnull() && type2.get_notnull();
422  if (type1.get_type() == kTEXT || type2.get_type() == kTEXT) {
423  common_type = SQLTypeInfo(kTEXT, 0, 0, notnull, comp, comp_param, kNULLT);
424  return common_type;
425  }
426  common_type = SQLTypeInfo(kVARCHAR,
427  std::max(type1.get_dimension(), type2.get_dimension()),
428  0,
429  notnull,
430  comp,
431  comp_param,
432  kNULLT);
433  return common_type;
434 }
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:197
bool is_string() const
Definition: sqltypes.h:488
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 97 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().

97  {
98  return makeExpr<BinOper>(type_info,
100  optype,
101  qualifier,
102  left_operand->deep_copy(),
103  right_operand->deep_copy());
104 }
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 2825 of file Analyzer.cpp.

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

2825  {
2826  if (f(this)) {
2827  add_unique(expr_list);
2828  return;
2829  }
2830  left_operand->find_expr(f, expr_list);
2831  right_operand->find_expr(f, expr_list);
2832 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2815
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 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 1483 of file Analyzer.cpp.

References kAND, left_operand, optype, and right_operand.

1485  {
1486  if (optype == kAND) {
1487  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1488  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1489  return;
1490  }
1491  std::set<int> rte_idx_set;
1492  left_operand->collect_rte_idx(rte_idx_set);
1493  right_operand->collect_rte_idx(rte_idx_set);
1494  if (rte_idx_set.size() > 1) {
1495  join_predicates.push_back(this);
1496  } else if (rte_idx_set.size() == 1) {
1497  scan_predicates.push_back(this);
1498  } else {
1499  const_predicates.push_back(this);
1500  }
1501 }
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 1418 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.

1418  {
1419  rte_idx = -1;
1420  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1421  return nullptr;
1422  }
1423  if (expr_is<UOper>(left_operand)) {
1425  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1426  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1427  rte_idx = cv->get_rte_idx();
1428  return this->deep_copy();
1429  }
1430  } else if (expr_is<UOper>(right_operand)) {
1432  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1433  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1434  rte_idx = cv->get_rte_idx();
1435  return makeExpr<BinOper>(type_info,
1436  contains_agg,
1438  qualifier,
1439  right_operand->deep_copy(),
1440  left_operand->deep_copy());
1441  }
1442  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1443  expr_is<Constant>(right_operand)) {
1444  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1445  rte_idx = cv->get_rte_idx();
1446  return this->deep_copy();
1447  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1448  !expr_is<Var>(right_operand)) {
1449  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1450  rte_idx = cv->get_rte_idx();
1451  return makeExpr<BinOper>(type_info,
1452  contains_agg,
1454  qualifier,
1455  right_operand->deep_copy(),
1456  left_operand->deep_copy());
1457  }
1458  return nullptr;
1459 }
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:1394
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:97
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 2126 of file Analyzer.cpp.

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

2126  {
2127  if (typeid(rhs) != typeid(BinOper)) {
2128  return false;
2129  }
2130  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2131  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2132  *right_operand == *rhs_bo.get_right_operand();
2133 }
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 1394 of file Analyzer.cpp.

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

Referenced by normalize_simple_predicate().

1396  {
1397  if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1398  auto u_expr = std::dynamic_pointer_cast<UOper>(cast_operand);
1399  if (u_expr->get_optype() != kCAST) {
1400  return false;
1401  }
1402  if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1403  !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1404  return false;
1405  }
1406  const auto& ti = u_expr->get_type_info();
1407  if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1408  // Allow casts between time types to pass through
1409  return true;
1410  } else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1411  // Allow casts between integer types to pass through
1412  return true;
1413  }
1414  }
1415  return false;
1416 }
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 2468 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().

2468  {
2469  std::string op;
2470  switch (optype) {
2471  case kEQ:
2472  op = "= ";
2473  break;
2474  case kNE:
2475  op = "<> ";
2476  break;
2477  case kLT:
2478  op = "< ";
2479  break;
2480  case kLE:
2481  op = "<= ";
2482  break;
2483  case kGT:
2484  op = "> ";
2485  break;
2486  case kGE:
2487  op = ">= ";
2488  break;
2489  case kAND:
2490  op = "AND ";
2491  break;
2492  case kOR:
2493  op = "OR ";
2494  break;
2495  case kMINUS:
2496  op = "- ";
2497  break;
2498  case kPLUS:
2499  op = "+ ";
2500  break;
2501  case kMULTIPLY:
2502  op = "* ";
2503  break;
2504  case kDIVIDE:
2505  op = "/ ";
2506  break;
2507  case kMODULO:
2508  op = "% ";
2509  break;
2510  case kARRAY_AT:
2511  op = "[] ";
2512  break;
2513  case kOVERLAPS:
2514  op = "OVERLAPS ";
2515  break;
2516  default:
2517  break;
2518  }
2519  std::string str{"("};
2520  str += op;
2521  if (qualifier == kANY) {
2522  str += "ANY ";
2523  } else if (qualifier == kALL) {
2524  str += "ALL ";
2525  }
2526  str += left_operand->toString();
2527  str += right_operand->toString();
2528  str += ") ";
2529  return str;
2530 }
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: