OmniSciDB  06b3bd477c
 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 292 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 294 of file ParserNode.h.

295  : optype(t), opqualifier(kONE), left(l), right(r) {}
std::unique_ptr< Expr > right
Definition: ParserNode.h:316
SQLQualifier opqualifier
Definition: ParserNode.h:314
std::unique_ptr< Expr > left
Definition: ParserNode.h:315
Definition: sqldefs.h:69
Parser::OperExpr::OperExpr ( SQLOps  t,
SQLQualifier  q,
Expr l,
Expr r 
)
inline

Definition at line 296 of file ParserNode.h.

297  : optype(t), opqualifier(q), left(l), right(r) {}
std::unique_ptr< Expr > right
Definition: ParserNode.h:316
SQLQualifier opqualifier
Definition: ParserNode.h:314
std::unique_ptr< Expr > left
Definition: ParserNode.h:315

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

References kARRAY, kARRAY_AT, and kONE.

249  {
250  auto left_expr = left->analyze(catalog, query, allow_tlist_ref);
251  const auto& left_type = left_expr->get_type_info();
252  if (right == nullptr) {
253  return makeExpr<Analyzer::UOper>(
254  left_type, left_expr->get_contains_agg(), optype, left_expr->decompress());
255  }
256  if (optype == kARRAY_AT) {
257  if (left_type.get_type() != kARRAY) {
258  throw std::runtime_error(left->to_string() + " is not of array type.");
259  }
260  auto right_expr = right->analyze(catalog, query, allow_tlist_ref);
261  const auto& right_type = right_expr->get_type_info();
262  if (!right_type.is_integer()) {
263  throw std::runtime_error(right->to_string() + " is not of integer type.");
264  }
265  return makeExpr<Analyzer::BinOper>(
266  left_type.get_elem_type(), false, kARRAY_AT, kONE, left_expr, right_expr);
267  }
268  auto right_expr = right->analyze(catalog, query, allow_tlist_ref);
269  return normalize(optype, opqualifier, left_expr, right_expr);
270 }
std::unique_ptr< Expr > right
Definition: ParserNode.h:316
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:272
SQLQualifier opqualifier
Definition: ParserNode.h:314
std::unique_ptr< Expr > left
Definition: ParserNode.h:315
Definition: sqldefs.h:69
const Expr* Parser::OperExpr::get_left ( ) const
inline

Definition at line 299 of file ParserNode.h.

References left.

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

Definition at line 298 of file ParserNode.h.

References optype.

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

Definition at line 300 of file ParserNode.h.

References right.

300 { return right.get(); }
std::unique_ptr< Expr > right
Definition: ParserNode.h:316
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 272 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().

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

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

1287  {
1288  std::string op_str[] = {
1289  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
1290  std::string str;
1291  if (optype == kUMINUS) {
1292  str = "-(" + left->to_string() + ")";
1293  } else if (optype == kNOT) {
1294  str = "NOT (" + left->to_string() + ")";
1295  } else if (optype == kARRAY_AT) {
1296  str = left->to_string() + "[" + right->to_string() + "]";
1297  } else if (optype == kUNNEST) {
1298  str = "UNNEST(" + left->to_string() + ")";
1299  } else if (optype == kIN) {
1300  str = "(" + left->to_string() + " IN " + right->to_string() + ")";
1301  } else {
1302  str = "(" + left->to_string() + op_str[optype] + right->to_string() + ")";
1303  }
1304  return str;
1305 }
std::unique_ptr< Expr > right
Definition: ParserNode.h:316
std::unique_ptr< Expr > left
Definition: ParserNode.h:315
Definition: sqldefs.h:53
Definition: sqldefs.h:39

Member Data Documentation

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

Definition at line 315 of file ParserNode.h.

Referenced by get_left().

SQLQualifier Parser::OperExpr::opqualifier
private

Definition at line 314 of file ParserNode.h.

SQLOps Parser::OperExpr::optype
private

Definition at line 313 of file ParserNode.h.

Referenced by get_optype().

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

Definition at line 316 of file ParserNode.h.

Referenced by get_right().


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