OmniSciDB  d2f719934e
 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 647 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 649 of file ParserNode.h.

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

Definition at line 650 of file ParserNode.h.

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

Definition at line 651 of file ParserNode.h.

651 : name_(n), distinct_(d), arg_(a) {}
std::unique_ptr< std::string > name_
Definition: ParserNode.h:662
constexpr double a
Definition: Utm.h:33
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:664
constexpr double n
Definition: Utm.h:39

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 827 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().

830  {
831  SQLTypeInfo result_type;
832  SQLAgg agg_type;
833  std::shared_ptr<Analyzer::Expr> arg_expr;
834  bool is_distinct = false;
835  if (boost::iequals(*name_, "count")) {
836  result_type = SQLTypeInfo(kBIGINT, false);
837  agg_type = kCOUNT;
838  if (arg_) {
839  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
840  const SQLTypeInfo& ti = arg_expr->get_type_info();
841  if (ti.is_string() && (ti.get_compression() != kENCODING_DICT || !distinct_)) {
842  throw std::runtime_error(
843  "Strings must be dictionary-encoded in COUNT(DISTINCT).");
844  }
845  if (ti.get_type() == kARRAY && !distinct_) {
846  throw std::runtime_error("Only COUNT(DISTINCT) is supported on arrays.");
847  }
848  }
849  is_distinct = distinct_;
850  } else {
851  if (!arg_) {
852  throw std::runtime_error("Cannot compute " + *name_ + " with argument '*'.");
853  }
854  if (boost::iequals(*name_, "min")) {
855  agg_type = kMIN;
856  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
857  arg_expr = arg_expr->decompress();
858  result_type = arg_expr->get_type_info();
859  } else if (boost::iequals(*name_, "max")) {
860  agg_type = kMAX;
861  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
862  arg_expr = arg_expr->decompress();
863  result_type = arg_expr->get_type_info();
864  } else if (boost::iequals(*name_, "avg")) {
865  agg_type = kAVG;
866  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
867  if (!arg_expr->get_type_info().is_number()) {
868  throw std::runtime_error("Cannot compute AVG on non-number-type arguments.");
869  }
870  arg_expr = arg_expr->decompress();
871  result_type = SQLTypeInfo(kDOUBLE, false);
872  } else if (boost::iequals(*name_, "sum")) {
873  agg_type = kSUM;
874  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
875  if (!arg_expr->get_type_info().is_number()) {
876  throw std::runtime_error("Cannot compute SUM on non-number-type arguments.");
877  }
878  arg_expr = arg_expr->decompress();
879  result_type = arg_expr->get_type_info().is_integer() ? SQLTypeInfo(kBIGINT, false)
880  : arg_expr->get_type_info();
881  } else if (boost::iequals(*name_, "unnest")) {
882  arg_expr = arg_->analyze(catalog, query, allow_tlist_ref);
883  const SQLTypeInfo& arg_ti = arg_expr->get_type_info();
884  if (arg_ti.get_type() != kARRAY) {
885  throw std::runtime_error(arg_->to_string() + " is not of array type.");
886  }
887  return makeExpr<Analyzer::UOper>(arg_ti.get_elem_type(), false, kUNNEST, arg_expr);
888  } else {
889  throw std::runtime_error("invalid function name: " + *name_);
890  }
891  if (arg_expr->get_type_info().is_string() ||
892  arg_expr->get_type_info().get_type() == kARRAY) {
893  throw std::runtime_error(
894  "Only COUNT(DISTINCT ) aggregate is supported on strings and arrays.");
895  }
896  }
897  int naggs = query.get_num_aggs();
898  query.set_num_aggs(naggs + 1);
899  return makeExpr<Analyzer::AggExpr>(
900  result_type, agg_type, arg_expr, is_distinct, nullptr);
901 }
SQLAgg
Definition: sqldefs.h:71
int get_num_aggs() const
Definition: Analyzer.h:1775
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
std::unique_ptr< std::string > name_
Definition: ParserNode.h:662
Definition: sqldefs.h:73
bool is_integer() const
Definition: sqltypes.h:521
Definition: sqldefs.h:75
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:664
void set_num_aggs(int a)
Definition: Analyzer.h:1804
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
Definition: sqldefs.h:76
bool is_string() const
Definition: sqltypes.h:519
Definition: sqldefs.h:74
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:861
Definition: sqldefs.h:72
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 654 of file ParserNode.h.

References arg_.

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

Definition at line 653 of file ParserNode.h.

References distinct_.

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

Definition at line 652 of file ParserNode.h.

References name_.

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

Implements Parser::Expr.

Definition at line 1582 of file ParserNode.cpp.

1582  {
1583  std::string str = *name_ + "(";
1584  if (distinct_) {
1585  str += "DISTINCT ";
1586  }
1587  if (arg_ == nullptr) {
1588  str += "*)";
1589  } else {
1590  str += arg_->to_string() + ")";
1591  }
1592  return str;
1593 }
std::unique_ptr< std::string > name_
Definition: ParserNode.h:662
std::unique_ptr< Expr > arg_
Definition: ParserNode.h:664

Member Data Documentation

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

Definition at line 664 of file ParserNode.h.

Referenced by get_arg().

bool Parser::FunctionRef::distinct_
private

Definition at line 663 of file ParserNode.h.

Referenced by get_distinct().

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

Definition at line 662 of file ParserNode.h.

Referenced by get_name().


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