OmniSciDB  d2f719934e
 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)
 

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:320
std::unique_ptr< Expr > left_
Definition: ParserNode.h:319
Definition: sqldefs.h:69
SQLQualifier opqualifier_
Definition: ParserNode.h:318
char * t
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:320
std::unique_ptr< Expr > left_
Definition: ParserNode.h:319
SQLQualifier opqualifier_
Definition: ParserNode.h:318
char * t

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

References kARRAY, kARRAY_AT, and kONE.

268  {
269  auto left_expr = left_->analyze(catalog, query, allow_tlist_ref);
270  const auto& left_type = left_expr->get_type_info();
271  if (right_ == nullptr) {
272  return makeExpr<Analyzer::UOper>(
273  left_type, left_expr->get_contains_agg(), optype_, left_expr->decompress());
274  }
275  if (optype_ == kARRAY_AT) {
276  if (left_type.get_type() != kARRAY) {
277  throw std::runtime_error(left_->to_string() + " is not of array type.");
278  }
279  auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
280  const auto& right_type = right_expr->get_type_info();
281  if (!right_type.is_integer()) {
282  throw std::runtime_error(right_->to_string() + " is not of integer type.");
283  }
284  return makeExpr<Analyzer::BinOper>(
285  left_type.get_elem_type(), false, kARRAY_AT, kONE, left_expr, right_expr);
286  }
287  auto right_expr = right_->analyze(catalog, query, allow_tlist_ref);
288  return normalize(optype_, opqualifier_, left_expr, right_expr);
289 }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:320
std::unique_ptr< Expr > left_
Definition: ParserNode.h:319
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)
Definition: ParserNode.cpp:291
Definition: sqldefs.h:69
SQLQualifier opqualifier_
Definition: ParserNode.h:318
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:319
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:320
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 
)
static

Definition at line 291 of file ParserNode.cpp.

References Analyzer::BinOper::analyze_type_info(), CHECK, SQLTypeInfo::get_array_type(), SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), IS_COMPARISON, SQLTypeInfo::is_geometry(), kARRAY, kENCODING_DICT, kENCODING_NONE, kONE, kOVERLAPS, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), 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().

295  {
296  if (left_expr->get_type_info().is_date_in_days() ||
297  right_expr->get_type_info().is_date_in_days()) {
298  // Do not propogate encoding
299  left_expr = left_expr->decompress();
300  right_expr = right_expr->decompress();
301  }
302  const auto& left_type = left_expr->get_type_info();
303  auto right_type = right_expr->get_type_info();
304  if (qual != kONE) {
305  // subquery not supported yet.
306  CHECK(!std::dynamic_pointer_cast<Analyzer::Subquery>(right_expr));
307  if (right_type.get_type() != kARRAY) {
308  throw std::runtime_error(
309  "Existential or universal qualifiers can only be used in front of a subquery "
310  "or an "
311  "expression of array type.");
312  }
313  right_type = right_type.get_elem_type();
314  }
315  SQLTypeInfo new_left_type;
316  SQLTypeInfo new_right_type;
317  auto result_type = Analyzer::BinOper::analyze_type_info(
318  optype, left_type, right_type, &new_left_type, &new_right_type);
319  if (result_type.is_timeinterval()) {
320  return makeExpr<Analyzer::BinOper>(
321  result_type, false, optype, qual, left_expr, right_expr);
322  }
323  if (left_type != new_left_type) {
324  left_expr = left_expr->add_cast(new_left_type);
325  }
326  if (right_type != new_right_type) {
327  if (qual == kONE) {
328  right_expr = right_expr->add_cast(new_right_type);
329  } else {
330  right_expr = right_expr->add_cast(new_right_type.get_array_type());
331  }
332  }
333 
334  if (IS_COMPARISON(optype)) {
335  if (optype != kOVERLAPS && new_left_type.is_geometry() &&
336  new_right_type.is_geometry()) {
337  throw std::runtime_error(
338  "Comparison operators are not yet supported for geospatial types.");
339  }
340 
341  if (new_left_type.get_compression() == kENCODING_DICT &&
342  new_right_type.get_compression() == kENCODING_DICT &&
343  new_left_type.get_comp_param() == new_right_type.get_comp_param()) {
344  // do nothing
345  } else if (new_left_type.get_compression() == kENCODING_DICT &&
346  new_right_type.get_compression() == kENCODING_NONE) {
347  SQLTypeInfo ti(new_right_type);
348  ti.set_compression(new_left_type.get_compression());
349  ti.set_comp_param(new_left_type.get_comp_param());
350  ti.set_fixed_size();
351  right_expr = right_expr->add_cast(ti);
352  } else if (new_right_type.get_compression() == kENCODING_DICT &&
353  new_left_type.get_compression() == kENCODING_NONE) {
354  SQLTypeInfo ti(new_left_type);
355  ti.set_compression(new_right_type.get_compression());
356  ti.set_comp_param(new_right_type.get_comp_param());
357  ti.set_fixed_size();
358  left_expr = left_expr->add_cast(ti);
359  } else {
360  left_expr = left_expr->decompress();
361  right_expr = right_expr->decompress();
362  }
363  } else {
364  left_expr = left_expr->decompress();
365  right_expr = right_expr->decompress();
366  }
367  bool has_agg = (left_expr->get_contains_agg() || right_expr->get_contains_agg());
368  return makeExpr<Analyzer::BinOper>(
369  result_type, has_agg, optype, qual, left_expr, right_expr);
370 }
SQLTypeInfo get_array_type() const
Definition: sqltypes.h:865
Definition: sqldefs.h:69
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
#define CHECK(condition)
Definition: Logger.h:211
bool is_geometry() const
Definition: sqltypes.h:531
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:236
#define IS_COMPARISON(X)
Definition: sqldefs.h:57

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

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

1434  {
1435  std::string op_str[] = {
1436  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
1437  std::string str;
1438  if (optype_ == kUMINUS) {
1439  str = "-(" + left_->to_string() + ")";
1440  } else if (optype_ == kNOT) {
1441  str = "NOT (" + left_->to_string() + ")";
1442  } else if (optype_ == kARRAY_AT) {
1443  str = left_->to_string() + "[" + right_->to_string() + "]";
1444  } else if (optype_ == kUNNEST) {
1445  str = "UNNEST(" + left_->to_string() + ")";
1446  } else if (optype_ == kIN) {
1447  str = "(" + left_->to_string() + " IN " + right_->to_string() + ")";
1448  } else {
1449  str = "(" + left_->to_string() + op_str[optype_] + right_->to_string() + ")";
1450  }
1451  return str;
1452 }
std::unique_ptr< Expr > right_
Definition: ParserNode.h:320
std::unique_ptr< Expr > left_
Definition: ParserNode.h:319
Definition: sqldefs.h:53
Definition: sqldefs.h:39

Member Data Documentation

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

Definition at line 319 of file ParserNode.h.

Referenced by get_left().

SQLQualifier Parser::OperExpr::opqualifier_
private

Definition at line 318 of file ParserNode.h.

SQLOps Parser::OperExpr::optype_
private

Definition at line 317 of file ParserNode.h.

Referenced by get_optype().

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

Definition at line 320 of file ParserNode.h.

Referenced by get_right().


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