OmniSciDB  72c90bc290
 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 290 of file ParserNode.cpp.

References kARRAY, kARRAY_AT, and kONE.

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

References Analyzer::BinOper::analyze_type_info(), CHECK, 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, kBBOX_INTERSECT, kENCODING_DICT, kENCODING_NONE, kEQ, kNE, kONE, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), SQLTypeInfo::set_dict_intersection(), SQLTypeInfo::set_fixed_size(), SQLTypeInfo::setStringDictKey(), and Parser::should_translate_strings().

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

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

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

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

2145  {
2146  std::string op_str[] = {
2147  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
2148  std::string str;
2149  if (optype_ == kUMINUS) {
2150  str = "-(" + left_->to_string() + ")";
2151  } else if (optype_ == kNOT) {
2152  str = "NOT (" + left_->to_string() + ")";
2153  } else if (optype_ == kARRAY_AT) {
2154  str = left_->to_string() + "[" + right_->to_string() + "]";
2155  } else if (optype_ == kUNNEST) {
2156  str = "UNNEST(" + left_->to_string() + ")";
2157  } else if (optype_ == kIN) {
2158  str = "(" + left_->to_string() + " IN " + right_->to_string() + ")";
2159  } else {
2160  str = "(" + left_->to_string() + op_str[optype_] + right_->to_string() + ")";
2161  }
2162  return str;
2163 }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:322
std::unique_ptr< Expr > left_
Definition: ParserNode.h:321
Definition: sqldefs.h:52
Definition: sqldefs.h:38

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: