OmniSciDB  a987f07e93
 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 286 of file ParserNode.cpp.

References kARRAY, kARRAY_AT, and kONE.

289  {
290  auto left_expr = left_->analyze(catalog, query, allow_tlist_ref);
291  const auto& left_type = left_expr->get_type_info();
292  if (right_ == nullptr) {
293  return makeExpr<Analyzer::UOper>(
294  left_type, left_expr->get_contains_agg(), optype_, left_expr->decompress());
295  }
296  if (optype_ == kARRAY_AT) {
297  if (left_type.get_type() != kARRAY) {
298  throw std::runtime_error(left_->to_string() + " is not of array type.");
299  }
300  auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
301  const auto& right_type = right_expr->get_type_info();
302  if (!right_type.is_integer()) {
303  throw std::runtime_error(right_->to_string() + " is not of integer type.");
304  }
305  return makeExpr<Analyzer::BinOper>(
306  left_type.get_elem_type(), false, kARRAY_AT, kONE, left_expr, right_expr);
307  }
308  auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
309  return normalize(optype_, opqualifier_, left_expr, right_expr);
310 }
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:370
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 370 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().

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

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

2115  {
2116  std::string op_str[] = {
2117  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
2118  std::string str;
2119  if (optype_ == kUMINUS) {
2120  str = "-(" + left_->to_string() + ")";
2121  } else if (optype_ == kNOT) {
2122  str = "NOT (" + left_->to_string() + ")";
2123  } else if (optype_ == kARRAY_AT) {
2124  str = left_->to_string() + "[" + right_->to_string() + "]";
2125  } else if (optype_ == kUNNEST) {
2126  str = "UNNEST(" + left_->to_string() + ")";
2127  } else if (optype_ == kIN) {
2128  str = "(" + left_->to_string() + " IN " + right_->to_string() + ")";
2129  } else {
2130  str = "(" + left_->to_string() + op_str[optype_] + right_->to_string() + ")";
2131  }
2132  return str;
2133 }
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: