OmniSciDB  e465130ba1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 308 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 310 of file ParserNode.h.

311  : optype(t), opqualifier(kONE), left(l), right(r) {}
std::unique_ptr< Expr > right
Definition: ParserNode.h:332
SQLQualifier opqualifier
Definition: ParserNode.h:330
std::unique_ptr< Expr > left
Definition: ParserNode.h:331
Definition: sqldefs.h:69
Parser::OperExpr::OperExpr ( SQLOps  t,
SQLQualifier  q,
Expr l,
Expr r 
)
inline

Definition at line 312 of file ParserNode.h.

313  : optype(t), opqualifier(q), left(l), right(r) {}
std::unique_ptr< Expr > right
Definition: ParserNode.h:332
SQLQualifier opqualifier
Definition: ParserNode.h:330
std::unique_ptr< Expr > left
Definition: ParserNode.h:331

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

References kARRAY, kARRAY_AT, and kONE.

240  {
241  auto left_expr = left->analyze(catalog, query, allow_tlist_ref);
242  const auto& left_type = left_expr->get_type_info();
243  if (right == nullptr) {
244  return makeExpr<Analyzer::UOper>(
245  left_type, left_expr->get_contains_agg(), optype, left_expr->decompress());
246  }
247  if (optype == kARRAY_AT) {
248  if (left_type.get_type() != kARRAY) {
249  throw std::runtime_error(left->to_string() + " is not of array type.");
250  }
251  auto right_expr = right->analyze(catalog, query, allow_tlist_ref);
252  const auto& right_type = right_expr->get_type_info();
253  if (!right_type.is_integer()) {
254  throw std::runtime_error(right->to_string() + " is not of integer type.");
255  }
256  return makeExpr<Analyzer::BinOper>(
257  left_type.get_elem_type(), false, kARRAY_AT, kONE, left_expr, right_expr);
258  }
259  auto right_expr = right->analyze(catalog, query, allow_tlist_ref);
260  return normalize(optype, opqualifier, left_expr, right_expr);
261 }
std::unique_ptr< Expr > right
Definition: ParserNode.h:332
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:263
SQLQualifier opqualifier
Definition: ParserNode.h:330
std::unique_ptr< Expr > left
Definition: ParserNode.h:331
Definition: sqldefs.h:69
const Expr* Parser::OperExpr::get_left ( ) const
inline

Definition at line 315 of file ParserNode.h.

References left.

315 { return left.get(); }
std::unique_ptr< Expr > left
Definition: ParserNode.h:331
SQLOps Parser::OperExpr::get_optype ( ) const
inline

Definition at line 314 of file ParserNode.h.

References optype.

314 { return optype; }
const Expr* Parser::OperExpr::get_right ( ) const
inline

Definition at line 316 of file ParserNode.h.

References right.

316 { return right.get(); }
std::unique_ptr< Expr > right
Definition: ParserNode.h:332
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 263 of file ParserNode.cpp.

References Analyzer::BinOper::analyze_type_info(), CHECK(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_array_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), IS_COMPARISON, kARRAY, kENCODING_DICT, kENCODING_NONE, kONE, SQLTypeInfoCore< TYPE_FACET_PACK >::set_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_compression(), and SQLTypeInfoCore< TYPE_FACET_PACK >::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(), anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateOp(), and RelAlgTranslator::translateOper().

267  {
268  if (left_expr->get_type_info().is_date_in_days() ||
269  right_expr->get_type_info().is_date_in_days()) {
270  // Do not propogate encoding
271  left_expr = left_expr->decompress();
272  right_expr = right_expr->decompress();
273  }
274  const auto& left_type = left_expr->get_type_info();
275  auto right_type = right_expr->get_type_info();
276  if (qual != kONE) {
277  // subquery not supported yet.
278  CHECK(!std::dynamic_pointer_cast<Analyzer::Subquery>(right_expr));
279  if (right_type.get_type() != kARRAY) {
280  throw std::runtime_error(
281  "Existential or universal qualifiers can only be used in front of a subquery "
282  "or an "
283  "expression of array type.");
284  }
285  right_type = right_type.get_elem_type();
286  }
287  SQLTypeInfo new_left_type;
288  SQLTypeInfo new_right_type;
289  auto result_type = Analyzer::BinOper::analyze_type_info(
290  optype, left_type, right_type, &new_left_type, &new_right_type);
291  if (result_type.is_timeinterval()) {
292  return makeExpr<Analyzer::BinOper>(
293  result_type, false, optype, qual, left_expr, right_expr);
294  }
295  if (left_type != new_left_type) {
296  left_expr = left_expr->add_cast(new_left_type);
297  }
298  if (right_type != new_right_type) {
299  if (qual == kONE) {
300  right_expr = right_expr->add_cast(new_right_type);
301  } else {
302  right_expr = right_expr->add_cast(new_right_type.get_array_type());
303  }
304  }
305  auto check_compression = IS_COMPARISON(optype);
306  if (check_compression) {
307  if (new_left_type.get_compression() == kENCODING_DICT &&
308  new_right_type.get_compression() == kENCODING_DICT &&
309  new_left_type.get_comp_param() == new_right_type.get_comp_param()) {
310  // do nothing
311  } else if (new_left_type.get_compression() == kENCODING_DICT &&
312  new_right_type.get_compression() == kENCODING_NONE) {
313  SQLTypeInfo ti(new_right_type);
314  ti.set_compression(new_left_type.get_compression());
315  ti.set_comp_param(new_left_type.get_comp_param());
316  ti.set_fixed_size();
317  right_expr = right_expr->add_cast(ti);
318  } else if (new_right_type.get_compression() == kENCODING_DICT &&
319  new_left_type.get_compression() == kENCODING_NONE) {
320  SQLTypeInfo ti(new_left_type);
321  ti.set_compression(new_right_type.get_compression());
322  ti.set_comp_param(new_right_type.get_comp_param());
323  ti.set_fixed_size();
324  left_expr = left_expr->add_cast(ti);
325  } else {
326  left_expr = left_expr->decompress();
327  right_expr = right_expr->decompress();
328  }
329  } else {
330  left_expr = left_expr->decompress();
331  right_expr = right_expr->decompress();
332  }
333  bool has_agg = (left_expr->get_contains_agg() || right_expr->get_contains_agg());
334  return makeExpr<Analyzer::BinOper>(
335  result_type, has_agg, optype, qual, left_expr, right_expr);
336 }
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:336
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:337
CHECK(cgen_state)
Definition: sqldefs.h:69
SQLTypeInfoCore get_array_type() const
Definition: sqltypes.h:678
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:212
#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 1345 of file ParserNode.cpp.

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

1345  {
1346  std::string op_str[] = {
1347  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
1348  std::string str;
1349  if (optype == kUMINUS) {
1350  str = "-(" + left->to_string() + ")";
1351  } else if (optype == kNOT) {
1352  str = "NOT (" + left->to_string() + ")";
1353  } else if (optype == kARRAY_AT) {
1354  str = left->to_string() + "[" + right->to_string() + "]";
1355  } else if (optype == kUNNEST) {
1356  str = "UNNEST(" + left->to_string() + ")";
1357  } else if (optype == kIN) {
1358  str = "(" + left->to_string() + " IN " + right->to_string() + ")";
1359  } else {
1360  str = "(" + left->to_string() + op_str[optype] + right->to_string() + ")";
1361  }
1362  return str;
1363 }
std::unique_ptr< Expr > right
Definition: ParserNode.h:332
std::unique_ptr< Expr > left
Definition: ParserNode.h:331
Definition: sqldefs.h:53
Definition: sqldefs.h:39

Member Data Documentation

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

Definition at line 331 of file ParserNode.h.

Referenced by get_left().

SQLQualifier Parser::OperExpr::opqualifier
private

Definition at line 330 of file ParserNode.h.

SQLOps Parser::OperExpr::optype
private

Definition at line 329 of file ParserNode.h.

Referenced by get_optype().

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

Definition at line 332 of file ParserNode.h.

Referenced by get_right().


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