OmniSciDB  085a039ca4
 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 297 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 299 of file ParserNode.h.

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

Definition at line 301 of file ParserNode.h.

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

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:322
std::unique_ptr< Expr > left_
Definition: ParserNode.h:321
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:371
Definition: sqldefs.h:71
SQLQualifier opqualifier_
Definition: ParserNode.h:320
const Expr* Parser::OperExpr::get_left ( ) const
inline

Definition at line 304 of file ParserNode.h.

References left_.

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

Definition at line 303 of file ParserNode.h.

References optype_.

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

Definition at line 305 of file ParserNode.h.

References right_.

305 { return right_.get(); }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:322
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 371 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(), 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(), and SQLTypeInfo::set_fixed_size().

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

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

+ 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 2095 of file ParserNode.cpp.

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

2095  {
2096  std::string op_str[] = {
2097  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
2098  std::string str;
2099  if (optype_ == kUMINUS) {
2100  str = "-(" + left_->to_string() + ")";
2101  } else if (optype_ == kNOT) {
2102  str = "NOT (" + left_->to_string() + ")";
2103  } else if (optype_ == kARRAY_AT) {
2104  str = left_->to_string() + "[" + right_->to_string() + "]";
2105  } else if (optype_ == kUNNEST) {
2106  str = "UNNEST(" + left_->to_string() + ")";
2107  } else if (optype_ == kIN) {
2108  str = "(" + left_->to_string() + " IN " + right_->to_string() + ")";
2109  } else {
2110  str = "(" + left_->to_string() + op_str[optype_] + right_->to_string() + ")";
2111  }
2112  return str;
2113 }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:322
std::unique_ptr< Expr > left_
Definition: ParserNode.h:321
Definition: sqldefs.h:53
Definition: sqldefs.h:39

Member Data Documentation

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

Definition at line 321 of file ParserNode.h.

Referenced by get_left().

SQLQualifier Parser::OperExpr::opqualifier_
private

Definition at line 320 of file ParserNode.h.

SQLOps Parser::OperExpr::optype_
private

Definition at line 319 of file ParserNode.h.

Referenced by get_optype().

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

Definition at line 322 of file ParserNode.h.

Referenced by get_right().


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