OmniSciDB  a5dc49c757
 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:74
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 291 of file ParserNode.cpp.

References kARRAY, kARRAY_AT, and kONE.

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

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

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

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

2155  {
2156  std::string op_str[] = {
2157  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
2158  std::string str;
2159  if (optype_ == kUMINUS) {
2160  str = "-(" + left_->to_string() + ")";
2161  } else if (optype_ == kNOT) {
2162  str = "NOT (" + left_->to_string() + ")";
2163  } else if (optype_ == kARRAY_AT) {
2164  str = left_->to_string() + "[" + right_->to_string() + "]";
2165  } else if (optype_ == kUNNEST) {
2166  str = "UNNEST(" + left_->to_string() + ")";
2167  } else if (optype_ == kIN) {
2168  str = "(" + left_->to_string() + " IN " + right_->to_string() + ")";
2169  } else {
2170  str = "(" + left_->to_string() + op_str[optype_] + right_->to_string() + ")";
2171  }
2172  return str;
2173 }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:322
std::unique_ptr< Expr > left_
Definition: ParserNode.h:321
Definition: sqldefs.h:55
Definition: sqldefs.h:41

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: