OmniSciDB  95562058bd
 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 244 of file ParserNode.cpp.

References kARRAY, kARRAY_AT, and kONE.

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

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

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

1285  {
1286  std::string op_str[] = {
1287  "=", "===", "<>", "<", ">", "<=", ">=", " AND ", " OR ", "NOT", "-", "+", "*", "/"};
1288  std::string str;
1289  if (optype == kUMINUS) {
1290  str = "-(" + left->to_string() + ")";
1291  } else if (optype == kNOT) {
1292  str = "NOT (" + left->to_string() + ")";
1293  } else if (optype == kARRAY_AT) {
1294  str = left->to_string() + "[" + right->to_string() + "]";
1295  } else if (optype == kUNNEST) {
1296  str = "UNNEST(" + left->to_string() + ")";
1297  } else if (optype == kIN) {
1298  str = "(" + left->to_string() + " IN " + right->to_string() + ")";
1299  } else {
1300  str = "(" + left->to_string() + op_str[optype] + right->to_string() + ")";
1301  }
1302  return str;
1303 }
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: