OmniSciDB  4201147b46
 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 952 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().

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

2249  {
2250  std::string str = *name_ + "(";
2251  if (distinct_) {
2252  str += "DISTINCT ";
2253  }
2254  if (arg_ == nullptr) {
2255  str += "*)";
2256  } else {
2257  str += arg_->to_string() + ")";
2258  }
2259  return str;
2260 }
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: