OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::OperExpr Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::OperExpr:
+ Collaboration diagram for Parser::OperExpr:

Public Member Functions

 OperExpr (SQLOps t, Expr *l, Expr *r)
 
 OperExpr (SQLOps t, SQLQualifier q, Expr *l, Expr *r)
 
SQLOps get_optype () const
 
const Exprget_left () const
 
const Exprget_right () const
 
std::shared_ptr< Analyzer::Expranalyze (const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
 
std::string to_string () const override
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Static Public Member Functions

static std::shared_ptr
< Analyzer::Expr
normalize (const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr, const Executor *executor=nullptr)
 

Private Attributes

SQLOps optype_
 
SQLQualifier opqualifier_
 
std::unique_ptr< Exprleft_
 
std::unique_ptr< Exprright_
 

Additional Inherited Members

- Public Types inherited from Parser::Expr
enum  TlistRefType { TLIST_NONE, TLIST_REF, TLIST_COPY }
 

Detailed Description

Definition at line 296 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::OperExpr::OperExpr ( SQLOps  t,
Expr l,
Expr r 
)
inline

Definition at line 298 of file ParserNode.h.

299  : optype_(t), opqualifier_(kONE), left_(l), right_(r) {}
std::unique_ptr< Expr > right_
Definition: ParserNode.h:321
std::unique_ptr< Expr > left_
Definition: ParserNode.h:320
Definition: sqldefs.h:71
SQLQualifier opqualifier_
Definition: ParserNode.h:319
Parser::OperExpr::OperExpr ( SQLOps  t,
SQLQualifier  q,
Expr l,
Expr r 
)
inline

Definition at line 300 of file ParserNode.h.

301  : optype_(t), opqualifier_(q), left_(l), right_(r) {}
std::unique_ptr< Expr > right_
Definition: ParserNode.h:321
std::unique_ptr< Expr > left_
Definition: ParserNode.h:320
SQLQualifier opqualifier_
Definition: ParserNode.h:319

Member Function Documentation

std::shared_ptr< Analyzer::Expr > Parser::OperExpr::analyze ( const Catalog_Namespace::Catalog catalog,
Analyzer::Query query,
TlistRefType  allow_tlist_ref = TLIST_NONE 
) const
overridevirtual

Implements Parser::Expr.

Definition at line 287 of file ParserNode.cpp.

References kARRAY, kARRAY_AT, and kONE.

290  {
291  auto left_expr = left_->analyze(catalog, query, allow_tlist_ref);
292  const auto& left_type = left_expr->get_type_info();
293  if (right_ == nullptr) {
294  return makeExpr<Analyzer::UOper>(
295  left_type, left_expr->get_contains_agg(), optype_, left_expr->decompress());
296  }
297  if (optype_ == kARRAY_AT) {
298  if (left_type.get_type() != kARRAY) {
299  throw std::runtime_error(left_->to_string() + " is not of array type.");
300  }
301  auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
302  const auto& right_type = right_expr->get_type_info();
303  if (!right_type.is_integer()) {
304  throw std::runtime_error(right_->to_string() + " is not of integer type.");
305  }
306  return makeExpr<Analyzer::BinOper>(
307  left_type.get_elem_type(), false, kARRAY_AT, kONE, left_expr, right_expr);
308  }
309  auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
310  return normalize(optype_, opqualifier_, left_expr, right_expr);
311 }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:321
std::unique_ptr< Expr > left_
Definition: ParserNode.h:320
static std::shared_ptr< Analyzer::Expr > normalize(const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr, const Executor *executor=nullptr)
Definition: ParserNode.cpp:372
Definition: sqldefs.h:71
SQLQualifier opqualifier_
Definition: ParserNode.h:319
const Expr* Parser::OperExpr::get_left ( ) const
inline

Definition at line 303 of file ParserNode.h.

References left_.

303 { return left_.get(); }
std::unique_ptr< Expr > left_
Definition: ParserNode.h:320
SQLOps Parser::OperExpr::get_optype ( ) const
inline

Definition at line 302 of file ParserNode.h.

References optype_.

302 { return optype_; }
const Expr* Parser::OperExpr::get_right ( ) const
inline

Definition at line 304 of file ParserNode.h.

References right_.

304 { return right_.get(); }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:321
std::shared_ptr< Analyzer::Expr > Parser::OperExpr::normalize ( const SQLOps  optype,
const SQLQualifier  qual,
std::shared_ptr< Analyzer::Expr left_expr,
std::shared_ptr< Analyzer::Expr right_expr,
const Executor executor = nullptr 
)
static

Definition at line 372 of file ParserNode.cpp.

References Analyzer::BinOper::analyze_type_info(), CHECK, Parser::exprs_share_one_and_same_rte_idx(), SQLTypeInfo::get_array_type(), SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), Parser::get_str_dict_cast_type(), SQLTypeInfo::getStringDictKey(), IS_COMPARISON, SQLTypeInfo::is_geometry(), kARRAY, kENCODING_DICT, kENCODING_NONE, kEQ, kNE, kONE, kOVERLAPS, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), SQLTypeInfo::set_dict_intersection(), SQLTypeInfo::set_fixed_size(), and SQLTypeInfo::setStringDictKey().

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::build_logical_expression(), anonymous_namespace{CompareIR.cpp}::lower_bw_eq(), anonymous_namespace{CompareIR.cpp}::make_eq(), anonymous_namespace{RelAlgExecutor.cpp}::reverse_logical_distribution(), RelAlgTranslator::translateFunction(), and RelAlgTranslator::translateOper().

377  {
378  if (left_expr->get_type_info().is_date_in_days() ||
379  right_expr->get_type_info().is_date_in_days()) {
380  // Do not propogate encoding
381  left_expr = left_expr->decompress();
382  right_expr = right_expr->decompress();
383  }
384  const auto& left_type = left_expr->get_type_info();
385  auto right_type = right_expr->get_type_info();
386  if (qual != kONE) {
387  // subquery not supported yet.
388  CHECK(!std::dynamic_pointer_cast<Analyzer::Subquery>(right_expr));
389  if (right_type.get_type() != kARRAY) {
390  throw std::runtime_error(
391  "Existential or universal qualifiers can only be used in front of a subquery "
392  "or an "
393  "expression of array type.");
394  }
395  right_type = right_type.get_elem_type();
396  }
397  SQLTypeInfo new_left_type;
398  SQLTypeInfo new_right_type;
399  auto result_type = Analyzer::BinOper::analyze_type_info(
400  optype, left_type, right_type, &new_left_type, &new_right_type);
401  if (result_type.is_timeinterval()) {
402  return makeExpr<Analyzer::BinOper>(
403  result_type, false, optype, qual, left_expr, right_expr);
404  }
405  if (left_type != new_left_type) {
406  left_expr = left_expr->add_cast(new_left_type);
407  }
408  if (right_type != new_right_type) {
409  if (qual == kONE) {
410  right_expr = right_expr->add_cast(new_right_type);
411  } else {
412  right_expr = right_expr->add_cast(new_right_type.get_array_type());
413  }
414  }
415 
416  if (IS_COMPARISON(optype)) {
417  if (optype != kOVERLAPS && new_left_type.is_geometry() &&
418  new_right_type.is_geometry()) {
419  throw std::runtime_error(
420  "Comparison operators are not yet supported for geospatial types.");
421  }
422 
423  if (new_left_type.get_compression() == kENCODING_DICT &&
424  new_right_type.get_compression() == kENCODING_DICT) {
425  if (new_left_type.getStringDictKey() != new_right_type.getStringDictKey()) {
426  if (optype == kEQ || optype == kNE) {
427  // Join framework does its own string dictionary translation
428  // (at least partly since the rhs table projection does not use
429  // the normal runtime execution framework), so if we detect
430  // that the rte idxs of the two tables are different, bail
431  // on translating
432  const bool should_translate_strings =
433  exprs_share_one_and_same_rte_idx(left_expr, right_expr);
434  if (should_translate_strings && (optype == kEQ || optype == kNE)) {
435  CHECK(executor);
436  // Make the type we're casting to the transient dictionary, if it exists,
437  // otherwise the largest dictionary in terms of number of entries
438  SQLTypeInfo ti(
439  get_str_dict_cast_type(new_left_type, new_right_type, executor));
440  auto& expr_to_cast = ti == new_left_type ? right_expr : left_expr;
441  ti.set_fixed_size();
442  ti.set_dict_intersection();
443  expr_to_cast = expr_to_cast->add_cast(ti);
444  } else { // Ordered comparison operator
445  // We do not currently support ordered (i.e. >, <=) comparisons between
446  // dictionary-encoded columns, and need to decompress when translation
447  // is turned off even for kEQ and KNE
448  left_expr = left_expr->decompress();
449  right_expr = right_expr->decompress();
450  }
451  } else { // Ordered comparison operator
452  // We do not currently support ordered (i.e. >, <=) comparisons between
453  // dictionary-encoded columns, and need to decompress when translation
454  // is turned off even for kEQ and KNE
455  left_expr = left_expr->decompress();
456  right_expr = right_expr->decompress();
457  }
458  } else { // Strings shared comp param
459  if (!(optype == kEQ || optype == kNE)) {
460  // We do not currently support ordered (i.e. >, <=) comparisons between
461  // encoded columns, so try to decode (will only succeed with watchdog off)
462  left_expr = left_expr->decompress();
463  right_expr = right_expr->decompress();
464  } else {
465  // do nothing, can directly support equals/non-equals comparisons between two
466  // dictionary encoded columns sharing the same dictionary as these are
467  // effectively integer comparisons in the same dictionary space
468  }
469  }
470  } else if (new_left_type.get_compression() == kENCODING_DICT &&
471  new_right_type.get_compression() == kENCODING_NONE) {
472  SQLTypeInfo ti(new_right_type);
473  ti.set_compression(new_left_type.get_compression());
474  ti.set_comp_param(new_left_type.get_comp_param());
475  ti.setStringDictKey(new_left_type.getStringDictKey());
476  ti.set_fixed_size();
477  right_expr = right_expr->add_cast(ti);
478  } else if (new_right_type.get_compression() == kENCODING_DICT &&
479  new_left_type.get_compression() == kENCODING_NONE) {
480  SQLTypeInfo ti(new_left_type);
481  ti.set_compression(new_right_type.get_compression());
482  ti.set_comp_param(new_right_type.get_comp_param());
483  ti.setStringDictKey(new_right_type.getStringDictKey());
484  ti.set_fixed_size();
485  left_expr = left_expr->add_cast(ti);
486  } else {
487  left_expr = left_expr->decompress();
488  right_expr = right_expr->decompress();
489  }
490  } else {
491  // Is this now a no-op just for pairs of none-encoded string columns
492  left_expr = left_expr->decompress();
493  right_expr = right_expr->decompress();
494  }
495  bool has_agg = (left_expr->get_contains_agg() || right_expr->get_contains_agg());
496  return makeExpr<Analyzer::BinOper>(
497  result_type, has_agg, optype, qual, left_expr, right_expr);
498 }
Definition: sqldefs.h:29
void set_fixed_size()
Definition: sqltypes.h:502
bool exprs_share_one_and_same_rte_idx(const std::shared_ptr< Analyzer::Expr > &lhs_expr, const std::shared_ptr< Analyzer::Expr > &rhs_expr)
Definition: ParserNode.cpp:313
SQLTypeInfo get_array_type() const
Definition: sqltypes.h:980
Definition: sqldefs.h:71
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
Definition: sqldefs.h:31
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:392
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:592
static SQLTypeInfo analyze_type_info(SQLOps op, const SQLTypeInfo &left_type, const SQLTypeInfo &right_type, SQLTypeInfo *new_left_type, SQLTypeInfo *new_right_type)
Definition: Analyzer.cpp:250
SQLTypeInfo const & get_str_dict_cast_type(const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
Definition: ParserNode.cpp:324
#define IS_COMPARISON(X)
Definition: sqldefs.h:58
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1021

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Parser::OperExpr::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 2123 of file ParserNode.cpp.

References kARRAY_AT, kIN, kNOT, kUMINUS, and kUNNEST.

2123  {
2124  std::string op_str[] = {
2125  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
2126  std::string str;
2127  if (optype_ == kUMINUS) {
2128  str = "-(" + left_->to_string() + ")";
2129  } else if (optype_ == kNOT) {
2130  str = "NOT (" + left_->to_string() + ")";
2131  } else if (optype_ == kARRAY_AT) {
2132  str = left_->to_string() + "[" + right_->to_string() + "]";
2133  } else if (optype_ == kUNNEST) {
2134  str = "UNNEST(" + left_->to_string() + ")";
2135  } else if (optype_ == kIN) {
2136  str = "(" + left_->to_string() + " IN " + right_->to_string() + ")";
2137  } else {
2138  str = "(" + left_->to_string() + op_str[optype_] + right_->to_string() + ")";
2139  }
2140  return str;
2141 }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:321
std::unique_ptr< Expr > left_
Definition: ParserNode.h:320
Definition: sqldefs.h:52
Definition: sqldefs.h:38

Member Data Documentation

std::unique_ptr<Expr> Parser::OperExpr::left_
private

Definition at line 320 of file ParserNode.h.

Referenced by get_left().

SQLQualifier Parser::OperExpr::opqualifier_
private

Definition at line 319 of file ParserNode.h.

SQLOps Parser::OperExpr::optype_
private

Definition at line 318 of file ParserNode.h.

Referenced by get_optype().

std::unique_ptr<Expr> Parser::OperExpr::right_
private

Definition at line 321 of file ParserNode.h.

Referenced by get_right().


The documentation for this class was generated from the following files: