OmniSciDB  72c90bc290
 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 649 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 651 of file ParserNode.h.

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

Definition at line 652 of file ParserNode.h.

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

Definition at line 653 of file ParserNode.h.

653 : name_(n), distinct_(d), arg_(a) {}
std::unique_ptr< std::string > name_
Definition: ParserNode.h:664
constexpr double a
Definition: Utm.h:32
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:666
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 964 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().

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

References arg_.

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

Definition at line 655 of file ParserNode.h.

References distinct_.

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

Definition at line 654 of file ParserNode.h.

References name_.

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

Implements Parser::Expr.

Definition at line 2293 of file ParserNode.cpp.

2293  {
2294  std::string str = *name_ + "(";
2295  if (distinct_) {
2296  str += "DISTINCT ";
2297  }
2298  if (arg_ == nullptr) {
2299  str += "*)";
2300  } else {
2301  str += arg_->to_string() + ")";
2302  }
2303  return str;
2304 }
std::unique_ptr< std::string > name_
Definition: ParserNode.h:664
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:666

Member Data Documentation

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

Definition at line 666 of file ParserNode.h.

Referenced by get_arg().

bool Parser::FunctionRef::distinct_
private

Definition at line 665 of file ParserNode.h.

Referenced by get_distinct().

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

Definition at line 664 of file ParserNode.h.

Referenced by get_name().


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