OmniSciDB  06b3bd477c
 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 421 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 423 of file Analyzer.h.

429  : Expr(ti, has_agg), optype(o), qualifier(q), left_operand(l), right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:518
SQLQualifier qualifier
Definition: Analyzer.h:515
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517
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 430 of file Analyzer.h.

435  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
436  , optype(o)
437  , qualifier(q)
438  , left_operand(l)
439  , right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:518
SQLQualifier qualifier
Definition: Analyzer.h:515
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517

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

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

References left_operand, and right_operand.

1382  {
1383  left_operand->check_group_by(groupby);
1384  right_operand->check_group_by(groupby);
1385 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:518
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517
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 471 of file Analyzer.h.

References left_operand, and right_operand.

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

Reimplemented from Analyzer::Expr.

Definition at line 467 of file Analyzer.h.

References left_operand, and right_operand.

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

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

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

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

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

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

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

+ 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(), 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:518
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517

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

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

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

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

+ Here is the caller graph for this function:

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

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

442 { return qualifier; }
SQLQualifier qualifier
Definition: Analyzer.h:515

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

References kAND, left_operand, optype, and right_operand.

1487  {
1488  if (optype == kAND) {
1489  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1490  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1491  return;
1492  }
1493  std::set<int> rte_idx_set;
1494  left_operand->collect_rte_idx(rte_idx_set);
1495  right_operand->collect_rte_idx(rte_idx_set);
1496  if (rte_idx_set.size() > 1) {
1497  join_predicates.push_back(this);
1498  } else if (rte_idx_set.size() == 1) {
1499  scan_predicates.push_back(this);
1500  } else {
1501  const_predicates.push_back(this);
1502  }
1503 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:518
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517
Definition: sqldefs.h:37
bool Analyzer::BinOper::is_overlaps_oper ( ) const
inline

Definition at line 441 of file Analyzer.h.

References kOVERLAPS, and optype.

Referenced by normalize_column_pairs().

441 { 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 1420 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.

1420  {
1421  rte_idx = -1;
1422  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1423  return nullptr;
1424  }
1425  if (expr_is<UOper>(left_operand)) {
1427  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1428  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1429  rte_idx = cv->get_rte_idx();
1430  return this->deep_copy();
1431  }
1432  } else if (expr_is<UOper>(right_operand)) {
1434  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1435  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1436  rte_idx = cv->get_rte_idx();
1437  return makeExpr<BinOper>(type_info,
1438  contains_agg,
1440  qualifier,
1441  right_operand->deep_copy(),
1442  left_operand->deep_copy());
1443  }
1444  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1445  expr_is<Constant>(right_operand)) {
1446  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1447  rte_idx = cv->get_rte_idx();
1448  return this->deep_copy();
1449  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1450  !expr_is<Var>(right_operand)) {
1451  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1452  rte_idx = cv->get_rte_idx();
1453  return makeExpr<BinOper>(type_info,
1454  contains_agg,
1456  qualifier,
1457  right_operand->deep_copy(),
1458  left_operand->deep_copy());
1459  }
1460  return nullptr;
1461 }
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:1396
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:518
SQLQualifier qualifier
Definition: Analyzer.h:515
SQLTypeInfo type_info
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517
Definition: sqldefs.h:69
#define COMMUTE_COMPARISON(X)
Definition: sqldefs.h:63
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:99
bool contains_agg
Definition: Analyzer.h:178
#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 2128 of file Analyzer.cpp.

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

2128  {
2129  if (typeid(rhs) != typeid(BinOper)) {
2130  return false;
2131  }
2132  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2133  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2134  *right_operand == *rhs_bo.get_right_operand();
2135 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:518
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:423
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517

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

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

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

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

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

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

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

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

Referenced by normalize_simple_predicate().

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

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