OmniSciDB  b24e664e58
 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 235 of file ParserNode.cpp.

References kARRAY, kARRAY_AT, and kONE.

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

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

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

1343  {
1344  std::string op_str[] = {
1345  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
1346  std::string str;
1347  if (optype == kUMINUS) {
1348  str = "-(" + left->to_string() + ")";
1349  } else if (optype == kNOT) {
1350  str = "NOT (" + left->to_string() + ")";
1351  } else if (optype == kARRAY_AT) {
1352  str = left->to_string() + "[" + right->to_string() + "]";
1353  } else if (optype == kUNNEST) {
1354  str = "UNNEST(" + left->to_string() + ")";
1355  } else if (optype == kIN) {
1356  str = "(" + left->to_string() + " IN " + right->to_string() + ")";
1357  } else {
1358  str = "(" + left->to_string() + op_str[optype] + right->to_string() + ")";
1359  }
1360  return str;
1361 }
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: