OmniSciDB  8fa3bf436f
 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 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) {}
tuple r
Definition: test_fsi.py:16
std::unique_ptr< Expr > right
Definition: ParserNode.h:320
SQLQualifier opqualifier
Definition: ParserNode.h:318
std::unique_ptr< Expr > left
Definition: ParserNode.h:319
Definition: sqldefs.h:69
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) {}
tuple r
Definition: test_fsi.py:16
std::unique_ptr< Expr > right
Definition: ParserNode.h:320
SQLQualifier opqualifier
Definition: ParserNode.h:318
std::unique_ptr< Expr > left
Definition: ParserNode.h:319
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 258 of file ParserNode.cpp.

References kARRAY, kARRAY_AT, and kONE.

261  {
262  auto left_expr = left->analyze(catalog, query, allow_tlist_ref);
263  const auto& left_type = left_expr->get_type_info();
264  if (right == nullptr) {
265  return makeExpr<Analyzer::UOper>(
266  left_type, left_expr->get_contains_agg(), optype, left_expr->decompress());
267  }
268  if (optype == kARRAY_AT) {
269  if (left_type.get_type() != kARRAY) {
270  throw std::runtime_error(left->to_string() + " is not of array type.");
271  }
272  auto right_expr = right->analyze(catalog, query, allow_tlist_ref);
273  const auto& right_type = right_expr->get_type_info();
274  if (!right_type.is_integer()) {
275  throw std::runtime_error(right->to_string() + " is not of integer type.");
276  }
277  return makeExpr<Analyzer::BinOper>(
278  left_type.get_elem_type(), false, kARRAY_AT, kONE, left_expr, right_expr);
279  }
280  auto right_expr = right->analyze(catalog, query, allow_tlist_ref);
281  return normalize(optype, opqualifier, left_expr, right_expr);
282 }
std::unique_ptr< Expr > right
Definition: ParserNode.h:320
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:284
SQLQualifier opqualifier
Definition: ParserNode.h:318
std::unique_ptr< Expr > left
Definition: ParserNode.h:319
Definition: sqldefs.h:69
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 284 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().

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

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

1320  {
1321  std::string op_str[] = {
1322  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
1323  std::string str;
1324  if (optype == kUMINUS) {
1325  str = "-(" + left->to_string() + ")";
1326  } else if (optype == kNOT) {
1327  str = "NOT (" + left->to_string() + ")";
1328  } else if (optype == kARRAY_AT) {
1329  str = left->to_string() + "[" + right->to_string() + "]";
1330  } else if (optype == kUNNEST) {
1331  str = "UNNEST(" + left->to_string() + ")";
1332  } else if (optype == kIN) {
1333  str = "(" + left->to_string() + " IN " + right->to_string() + ")";
1334  } else {
1335  str = "(" + left->to_string() + op_str[optype] + right->to_string() + ")";
1336  }
1337  return str;
1338 }
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: