OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::FunctionRef Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::FunctionRef:
+ Collaboration diagram for Parser::FunctionRef:

Public Member Functions

 FunctionRef (std::string *n)
 
 FunctionRef (std::string *n, Expr *a)
 
 FunctionRef (std::string *n, bool d, Expr *a)
 
const std::string * get_name () const
 
bool get_distinct () const
 
Exprget_arg () 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 ()
 

Private Attributes

std::unique_ptr< std::string > name_
 
bool distinct_
 
std::unique_ptr< Exprarg_
 

Additional Inherited Members

- Public Types inherited from Parser::Expr
enum  TlistRefType { TLIST_NONE, TLIST_REF, TLIST_COPY }
 

Detailed Description

Definition at line 648 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::FunctionRef::FunctionRef ( std::string *  n)
inlineexplicit

Definition at line 650 of file ParserNode.h.

650 : name_(n), distinct_(false), arg_(nullptr) {}
std::unique_ptr< std::string > name_
Definition: ParserNode.h:663
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:665
constexpr double n
Definition: Utm.h:38
Parser::FunctionRef::FunctionRef ( std::string *  n,
Expr a 
)
inline

Definition at line 651 of file ParserNode.h.

651 : name_(n), distinct_(false), arg_(a) {}
std::unique_ptr< std::string > name_
Definition: ParserNode.h:663
constexpr double a
Definition: Utm.h:32
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:665
constexpr double n
Definition: Utm.h:38
Parser::FunctionRef::FunctionRef ( std::string *  n,
bool  d,
Expr a 
)
inline

Definition at line 652 of file ParserNode.h.

652 : name_(n), distinct_(d), arg_(a) {}
std::unique_ptr< std::string > name_
Definition: ParserNode.h:663
constexpr double a
Definition: Utm.h:32
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:665
constexpr double n
Definition: Utm.h:38

Member Function Documentation

std::shared_ptr< Analyzer::Expr > Parser::FunctionRef::analyze ( const Catalog_Namespace::Catalog catalog,
Analyzer::Query query,
TlistRefType  allow_tlist_ref = TLIST_NONE 
) const
overridevirtual

Implements Parser::Expr.

Definition at line 959 of file ParserNode.cpp.

References SQLTypeInfo::get_compression(), SQLTypeInfo::get_elem_type(), Analyzer::Query::get_num_aggs(), SQLTypeInfo::get_type(), anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_string(), kARRAY, kAVG, kBIGINT, kCOUNT, kDOUBLE, kENCODING_DICT, kMAX, kMIN, kSUM, kUNNEST, and Analyzer::Query::set_num_aggs().

962  {
963  SQLTypeInfo result_type;
964  SQLAgg agg_type;
965  std::shared_ptr<Analyzer::Expr> arg_expr;
966  bool is_distinct = false;
967  if (boost::iequals(*name_, "count")) {
968  result_type = SQLTypeInfo(kBIGINT, false);
969  agg_type = kCOUNT;
970  if (arg_) {
971  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
972  const SQLTypeInfo& ti = arg_expr->get_type_info();
973  if (ti.is_string() && (ti.get_compression() != kENCODING_DICT || !distinct_)) {
974  throw std::runtime_error(
975  "Strings must be dictionary-encoded in COUNT(DISTINCT).");
976  }
977  if (ti.get_type() == kARRAY && !distinct_) {
978  throw std::runtime_error("Only COUNT(DISTINCT) is supported on arrays.");
979  }
980  }
981  is_distinct = distinct_;
982  } else {
983  if (!arg_) {
984  throw std::runtime_error("Cannot compute " + *name_ + " with argument '*'.");
985  }
986  if (boost::iequals(*name_, "min")) {
987  agg_type = kMIN;
988  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
989  arg_expr = arg_expr->decompress();
990  result_type = arg_expr->get_type_info();
991  } else if (boost::iequals(*name_, "max")) {
992  agg_type = kMAX;
993  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
994  arg_expr = arg_expr->decompress();
995  result_type = arg_expr->get_type_info();
996  } else if (boost::iequals(*name_, "avg")) {
997  agg_type = kAVG;
998  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
999  if (!arg_expr->get_type_info().is_number()) {
1000  throw std::runtime_error("Cannot compute AVG on non-number-type arguments.");
1001  }
1002  arg_expr = arg_expr->decompress();
1003  result_type = SQLTypeInfo(kDOUBLE, false);
1004  } else if (boost::iequals(*name_, "sum")) {
1005  agg_type = kSUM;
1006  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
1007  if (!arg_expr->get_type_info().is_number()) {
1008  throw std::runtime_error("Cannot compute SUM on non-number-type arguments.");
1009  }
1010  arg_expr = arg_expr->decompress();
1011  result_type = arg_expr->get_type_info().is_integer() ? SQLTypeInfo(kBIGINT, false)
1012  : arg_expr->get_type_info();
1013  } else if (boost::iequals(*name_, "unnest")) {
1014  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
1015  const SQLTypeInfo& arg_ti = arg_expr->get_type_info();
1016  if (arg_ti.get_type() != kARRAY) {
1017  throw std::runtime_error(arg_->to_string() + " is not of array type.");
1018  }
1019  return makeExpr<Analyzer::UOper>(arg_ti.get_elem_type(), false, kUNNEST, arg_expr);
1020  } else {
1021  throw std::runtime_error("invalid function name: " + *name_);
1022  }
1023  if (arg_expr->get_type_info().is_string() ||
1024  arg_expr->get_type_info().get_type() == kARRAY) {
1025  throw std::runtime_error(
1026  "Only COUNT(DISTINCT ) aggregate is supported on strings and arrays.");
1027  }
1028  }
1029  int naggs = query.get_num_aggs();
1030  query.set_num_aggs(naggs + 1);
1031  return makeExpr<Analyzer::AggExpr>(
1032  result_type, agg_type, arg_expr, is_distinct, nullptr);
1033 }
SQLAgg
Definition: sqldefs.h:73
int get_num_aggs() const
Definition: Analyzer.h:2794
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
std::unique_ptr< std::string > name_
Definition: ParserNode.h:663
Definition: sqldefs.h:75
bool is_integer() const
Definition: sqltypes.h:582
Definition: sqldefs.h:77
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:665
void set_num_aggs(int a)
Definition: Analyzer.h:2829
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
Definition: sqldefs.h:78
bool is_string() const
Definition: sqltypes.h:580
Definition: sqldefs.h:76
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:963
Definition: sqldefs.h:74
bool is_distinct(const size_t input_idx, const RelAlgNode *node)

+ Here is the call graph for this function:

Expr* Parser::FunctionRef::get_arg ( ) const
inline

Definition at line 655 of file ParserNode.h.

References arg_.

655 { return arg_.get(); }
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:665
bool Parser::FunctionRef::get_distinct ( ) const
inline

Definition at line 654 of file ParserNode.h.

References distinct_.

654 { return distinct_; }
const std::string* Parser::FunctionRef::get_name ( ) const
inline

Definition at line 653 of file ParserNode.h.

References name_.

653 { return name_.get(); }
std::unique_ptr< std::string > name_
Definition: ParserNode.h:663
std::string Parser::FunctionRef::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 2271 of file ParserNode.cpp.

2271  {
2272  std::string str = *name_ + "(";
2273  if (distinct_) {
2274  str += "DISTINCT ";
2275  }
2276  if (arg_ == nullptr) {
2277  str += "*)";
2278  } else {
2279  str += arg_->to_string() + ")";
2280  }
2281  return str;
2282 }
std::unique_ptr< std::string > name_
Definition: ParserNode.h:663
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:665

Member Data Documentation

std::unique_ptr<Expr> Parser::FunctionRef::arg_
private

Definition at line 665 of file ParserNode.h.

Referenced by get_arg().

bool Parser::FunctionRef::distinct_
private

Definition at line 664 of file ParserNode.h.

Referenced by get_distinct().

std::unique_ptr<std::string> Parser::FunctionRef::name_
private

Definition at line 663 of file ParserNode.h.

Referenced by get_name().


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