OmniSciDB  c07336695a
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::Exprnormalize (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 297 of file ParserNode.h.

Constructor & Destructor Documentation

◆ OperExpr() [1/2]

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:321
SQLQualifier opqualifier
Definition: ParserNode.h:319
std::unique_ptr< Expr > left
Definition: ParserNode.h:320
Definition: sqldefs.h:69

◆ OperExpr() [2/2]

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:321
SQLQualifier opqualifier
Definition: ParserNode.h:319
std::unique_ptr< Expr > left
Definition: ParserNode.h:320

Member Function Documentation

◆ analyze()

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

References kARRAY, kARRAY_AT, and kONE.

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

◆ get_left()

const Expr* Parser::OperExpr::get_left ( ) const
inline

Definition at line 304 of file ParserNode.h.

304 { return left.get(); }
std::unique_ptr< Expr > left
Definition: ParserNode.h:320

◆ get_optype()

SQLOps Parser::OperExpr::get_optype ( ) const
inline

Definition at line 303 of file ParserNode.h.

303 { return optype; }

◆ get_right()

const Expr* Parser::OperExpr::get_right ( ) const
inline

Definition at line 305 of file ParserNode.h.

References anonymous_namespace{UpdateMetadataTest.cpp}::query, and to_string().

305 { return right.get(); }
std::unique_ptr< Expr > right
Definition: ParserNode.h:321
+ Here is the call graph for this function:

◆ normalize()

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

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

◆ to_string()

std::string Parser::OperExpr::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 1328 of file ParserNode.cpp.

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

1328  {
1329  std::string op_str[] = {
1330  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
1331  std::string str;
1332  if (optype == kUMINUS) {
1333  str = "-(" + left->to_string() + ")";
1334  } else if (optype == kNOT) {
1335  str = "NOT (" + left->to_string() + ")";
1336  } else if (optype == kARRAY_AT) {
1337  str = left->to_string() + "[" + right->to_string() + "]";
1338  } else if (optype == kUNNEST) {
1339  str = "UNNEST(" + left->to_string() + ")";
1340  } else if (optype == kIN) {
1341  str = "(" + left->to_string() + " IN " + right->to_string() + ")";
1342  } else {
1343  str = "(" + left->to_string() + op_str[optype] + right->to_string() + ")";
1344  }
1345  return str;
1346 }
std::unique_ptr< Expr > right
Definition: ParserNode.h:321
std::unique_ptr< Expr > left
Definition: ParserNode.h:320
Definition: sqldefs.h:53
Definition: sqldefs.h:39

Member Data Documentation

◆ left

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

Definition at line 320 of file ParserNode.h.

◆ opqualifier

SQLQualifier Parser::OperExpr::opqualifier
private

Definition at line 319 of file ParserNode.h.

◆ optype

SQLOps Parser::OperExpr::optype
private

Definition at line 318 of file ParserNode.h.

◆ right

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

Definition at line 321 of file ParserNode.h.


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