OmniSciDB  a5dc49c757
 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 965 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().

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

2303  {
2304  std::string str = *name_ + "(";
2305  if (distinct_) {
2306  str += "DISTINCT ";
2307  }
2308  if (arg_ == nullptr) {
2309  str += "*)";
2310  } else {
2311  str += arg_->to_string() + ")";
2312  }
2313  return str;
2314 }
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: