OmniSciDB  1dac507f6e
 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 414 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 416 of file Analyzer.h.

422  : 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:511
SQLQualifier qualifier
Definition: Analyzer.h:508
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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 423 of file Analyzer.h.

428  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
429  , optype(o)
430  , qualifier(q)
431  , left_operand(l)
432  , right_operand(r) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
SQLQualifier qualifier
Definition: Analyzer.h:508
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510

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

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

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

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

References left_operand, and right_operand.

1307  {
1308  left_operand->check_group_by(groupby);
1309  right_operand->check_group_by(groupby);
1310 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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 464 of file Analyzer.h.

References left_operand, and right_operand.

467  {
468  left_operand->collect_column_var(colvar_set, include_agg);
469  right_operand->collect_column_var(colvar_set, include_agg);
470  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
void Analyzer::BinOper::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 460 of file Analyzer.h.

References left_operand, and right_operand.

460  {
461  left_operand->collect_rte_idx(rte_idx_set);
462  right_operand->collect_rte_idx(rte_idx_set);
463  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
SQLTypeInfo Analyzer::BinOper::common_numeric_type ( const SQLTypeInfo type1,
const SQLTypeInfo type2 
)
static

Definition at line 427 of file Analyzer.cpp.

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

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

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

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

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

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

388  {
389  SQLTypeInfo common_type;
391  int comp_param = 0;
392  CHECK(type1.is_string() && type2.is_string());
393  // if type1 and type2 have the same DICT encoding then keep it
394  // otherwise, they must be decompressed
395  if (type1.get_compression() == kENCODING_DICT &&
396  type2.get_compression() == kENCODING_DICT) {
397  if (type1.get_comp_param() == type2.get_comp_param() ||
398  type1.get_comp_param() == TRANSIENT_DICT(type2.get_comp_param())) {
399  comp = kENCODING_DICT;
400  comp_param = std::min(type1.get_comp_param(), type2.get_comp_param());
401  }
402  } else if (type1.get_compression() == kENCODING_DICT &&
403  type2.get_compression() == kENCODING_NONE) {
404  comp_param = type1.get_comp_param();
405  } else if (type1.get_compression() == kENCODING_NONE &&
406  type2.get_compression() == kENCODING_DICT) {
407  comp_param = type2.get_comp_param();
408  } else {
409  comp_param = std::max(type1.get_comp_param(),
410  type2.get_comp_param()); // preserve previous comp_param if set
411  }
412  const bool notnull = type1.get_notnull() && type2.get_notnull();
413  if (type1.get_type() == kTEXT || type2.get_type() == kTEXT) {
414  common_type = SQLTypeInfo(kTEXT, 0, 0, notnull, comp, comp_param, kNULLT);
415  return common_type;
416  }
417  common_type = SQLTypeInfo(kVARCHAR,
418  std::max(type1.get_dimension(), type2.get_dimension()),
419  0,
420  notnull,
421  comp,
422  comp_param,
423  kNULLT);
424  return common_type;
425 }
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:335
EncodingType
Definition: encodetypes.h:22
CHECK(cgen_state)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:333
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
Definition: sqltypes.h:55
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:328
bool is_string() const
Definition: sqltypes.h:477
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:190

+ 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:511
SQLQualifier qualifier
Definition: Analyzer.h:508
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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 2649 of file Analyzer.cpp.

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

2649  {
2650  if (f(this)) {
2651  add_unique(expr_list);
2652  return;
2653  }
2654  left_operand->find_expr(f, expr_list);
2655  right_operand->find_expr(f, expr_list);
2656 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2639
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510

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

438  {
439  return left_operand;
440  }
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510

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

441  {
442  return right_operand;
443  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511

+ Here is the caller graph for this function:

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

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

435 { return qualifier; }
SQLQualifier qualifier
Definition: Analyzer.h:508

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

References kAND, left_operand, optype, and right_operand.

1412  {
1413  if (optype == kAND) {
1414  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1415  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1416  return;
1417  }
1418  std::set<int> rte_idx_set;
1419  left_operand->collect_rte_idx(rte_idx_set);
1420  right_operand->collect_rte_idx(rte_idx_set);
1421  if (rte_idx_set.size() > 1) {
1422  join_predicates.push_back(this);
1423  } else if (rte_idx_set.size() == 1) {
1424  scan_predicates.push_back(this);
1425  } else {
1426  const_predicates.push_back(this);
1427  }
1428 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
Definition: sqldefs.h:37
bool Analyzer::BinOper::is_overlaps_oper ( ) const
inline

Definition at line 434 of file Analyzer.h.

References kOVERLAPS, and optype.

Referenced by normalize_column_pairs().

434 { 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 1345 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.

1345  {
1346  rte_idx = -1;
1347  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1348  return nullptr;
1349  }
1350  if (expr_is<UOper>(left_operand)) {
1352  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1353  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1354  rte_idx = cv->get_rte_idx();
1355  return this->deep_copy();
1356  }
1357  } else if (expr_is<UOper>(right_operand)) {
1359  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1360  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1361  rte_idx = cv->get_rte_idx();
1362  return makeExpr<BinOper>(type_info,
1363  contains_agg,
1365  qualifier,
1366  right_operand->deep_copy(),
1367  left_operand->deep_copy());
1368  }
1369  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1370  expr_is<Constant>(right_operand)) {
1371  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1372  rte_idx = cv->get_rte_idx();
1373  return this->deep_copy();
1374  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1375  !expr_is<Var>(right_operand)) {
1376  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1377  rte_idx = cv->get_rte_idx();
1378  return makeExpr<BinOper>(type_info,
1379  contains_agg,
1381  qualifier,
1382  right_operand->deep_copy(),
1383  left_operand->deep_copy());
1384  }
1385  return nullptr;
1386 }
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:1321
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
SQLQualifier qualifier
Definition: Analyzer.h:508
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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: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 2039 of file Analyzer.cpp.

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

2039  {
2040  if (typeid(rhs) != typeid(BinOper)) {
2041  return false;
2042  }
2043  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2044  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2045  *right_operand == *rhs_bo.get_right_operand();
2046 }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
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:416
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510

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

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

490  {
491  return makeExpr<BinOper>(type_info,
492  contains_agg,
493  optype,
494  qualifier,
495  left_operand->rewrite_agg_to_var(tlist),
496  right_operand->rewrite_agg_to_var(tlist));
497  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
SQLQualifier qualifier
Definition: Analyzer.h:508
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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 480 of file Analyzer.h.

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

481  {
482  return makeExpr<BinOper>(type_info,
483  contains_agg,
484  optype,
485  qualifier,
486  left_operand->rewrite_with_child_targetlist(tlist),
487  right_operand->rewrite_with_child_targetlist(tlist));
488  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
SQLQualifier qualifier
Definition: Analyzer.h:508
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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 471 of file Analyzer.h.

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

472  {
473  return makeExpr<BinOper>(type_info,
474  contains_agg,
475  optype,
476  qualifier,
477  left_operand->rewrite_with_targetlist(tlist),
478  right_operand->rewrite_with_targetlist(tlist));
479  }
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
SQLQualifier qualifier
Definition: Analyzer.h:508
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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 1321 of file Analyzer.cpp.

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

Referenced by normalize_simple_predicate().

1323  {
1324  if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1325  auto u_expr = std::dynamic_pointer_cast<UOper>(cast_operand);
1326  if (u_expr->get_optype() != kCAST) {
1327  return false;
1328  }
1329  if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1330  !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1331  return false;
1332  }
1333  const auto& ti = u_expr->get_type_info();
1334  if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1335  // Allow casts between time types to pass through
1336  return true;
1337  } else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1338  // Allow casts between integer types to pass through
1339  return true;
1340  }
1341  }
1342  return false;
1343 }
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 2349 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().

2349  {
2350  std::string op;
2351  switch (optype) {
2352  case kEQ:
2353  op = "= ";
2354  break;
2355  case kNE:
2356  op = "<> ";
2357  break;
2358  case kLT:
2359  op = "< ";
2360  break;
2361  case kLE:
2362  op = "<= ";
2363  break;
2364  case kGT:
2365  op = "> ";
2366  break;
2367  case kGE:
2368  op = ">= ";
2369  break;
2370  case kAND:
2371  op = "AND ";
2372  break;
2373  case kOR:
2374  op = "OR ";
2375  break;
2376  case kMINUS:
2377  op = "- ";
2378  break;
2379  case kPLUS:
2380  op = "+ ";
2381  break;
2382  case kMULTIPLY:
2383  op = "* ";
2384  break;
2385  case kDIVIDE:
2386  op = "/ ";
2387  break;
2388  case kMODULO:
2389  op = "% ";
2390  break;
2391  case kARRAY_AT:
2392  op = "[] ";
2393  break;
2394  case kOVERLAPS:
2395  op = "OVERLAPS ";
2396  break;
2397  default:
2398  break;
2399  }
2400  std::string str{"("};
2401  str += op;
2402  if (qualifier == kANY) {
2403  str += "ANY ";
2404  } else if (qualifier == kALL) {
2405  str += "ALL ";
2406  }
2407  str += left_operand->toString();
2408  str += right_operand->toString();
2409  str += ") ";
2410  return str;
2411 }
Definition: sqldefs.h:69
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
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:508
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
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: