OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 617 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 619 of file ParserNode.h.

619 : name(n), distinct(false), arg(nullptr) {}
std::unique_ptr< Expr > arg
Definition: ParserNode.h:634
std::unique_ptr< std::string > name
Definition: ParserNode.h:632
Parser::FunctionRef::FunctionRef ( std::string *  n,
Expr a 
)
inline

Definition at line 620 of file ParserNode.h.

620 : name(n), distinct(false), arg(a) {}
std::unique_ptr< Expr > arg
Definition: ParserNode.h:634
std::unique_ptr< std::string > name
Definition: ParserNode.h:632
Parser::FunctionRef::FunctionRef ( std::string *  n,
bool  d,
Expr a 
)
inline

Definition at line 621 of file ParserNode.h.

621 : name(n), distinct(d), arg(a) {}
std::unique_ptr< Expr > arg
Definition: ParserNode.h:634
std::unique_ptr< std::string > name
Definition: ParserNode.h:632

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 785 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, setup::name, and Analyzer::Query::set_num_aggs().

788  {
789  SQLTypeInfo result_type;
790  SQLAgg agg_type;
791  std::shared_ptr<Analyzer::Expr> arg_expr;
792  bool is_distinct = false;
793  if (boost::iequals(*name, "count")) {
794  result_type = SQLTypeInfo(kBIGINT, false);
795  agg_type = kCOUNT;
796  if (arg) {
797  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
798  const SQLTypeInfo& ti = arg_expr->get_type_info();
799  if (ti.is_string() && (ti.get_compression() != kENCODING_DICT || !distinct)) {
800  throw std::runtime_error(
801  "Strings must be dictionary-encoded in COUNT(DISTINCT).");
802  }
803  if (ti.get_type() == kARRAY && !distinct) {
804  throw std::runtime_error("Only COUNT(DISTINCT) is supported on arrays.");
805  }
806  }
807  is_distinct = distinct;
808  } else {
809  if (!arg) {
810  throw std::runtime_error("Cannot compute " + *name + " with argument '*'.");
811  }
812  if (boost::iequals(*name, "min")) {
813  agg_type = kMIN;
814  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
815  arg_expr = arg_expr->decompress();
816  result_type = arg_expr->get_type_info();
817  } else if (boost::iequals(*name, "max")) {
818  agg_type = kMAX;
819  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
820  arg_expr = arg_expr->decompress();
821  result_type = arg_expr->get_type_info();
822  } else if (boost::iequals(*name, "avg")) {
823  agg_type = kAVG;
824  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
825  if (!arg_expr->get_type_info().is_number()) {
826  throw std::runtime_error("Cannot compute AVG on non-number-type arguments.");
827  }
828  arg_expr = arg_expr->decompress();
829  result_type = SQLTypeInfo(kDOUBLE, false);
830  } else if (boost::iequals(*name, "sum")) {
831  agg_type = kSUM;
832  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
833  if (!arg_expr->get_type_info().is_number()) {
834  throw std::runtime_error("Cannot compute SUM on non-number-type arguments.");
835  }
836  arg_expr = arg_expr->decompress();
837  result_type = arg_expr->get_type_info().is_integer() ? SQLTypeInfo(kBIGINT, false)
838  : arg_expr->get_type_info();
839  } else if (boost::iequals(*name, "unnest")) {
840  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
841  const SQLTypeInfo& arg_ti = arg_expr->get_type_info();
842  if (arg_ti.get_type() != kARRAY) {
843  throw std::runtime_error(arg->to_string() + " is not of array type.");
844  }
845  return makeExpr<Analyzer::UOper>(arg_ti.get_elem_type(), false, kUNNEST, arg_expr);
846  } else {
847  throw std::runtime_error("invalid function name: " + *name);
848  }
849  if (arg_expr->get_type_info().is_string() ||
850  arg_expr->get_type_info().get_type() == kARRAY) {
851  throw std::runtime_error(
852  "Only COUNT(DISTINCT ) aggregate is supported on strings and arrays.");
853  }
854  }
855  int naggs = query.get_num_aggs();
856  query.set_num_aggs(naggs + 1);
857  return makeExpr<Analyzer::AggExpr>(
858  result_type, agg_type, arg_expr, is_distinct, nullptr);
859 }
SQLAgg
Definition: sqldefs.h:71
int get_num_aggs() const
Definition: Analyzer.h:1609
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
Definition: sqldefs.h:73
std::unique_ptr< Expr > arg
Definition: ParserNode.h:634
bool is_integer() const
Definition: sqltypes.h:419
Definition: sqldefs.h:75
void set_num_aggs(int a)
Definition: Analyzer.h:1638
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
Definition: sqldefs.h:76
std::unique_ptr< std::string > name
Definition: ParserNode.h:632
bool is_string() const
Definition: sqltypes.h:417
Definition: sqldefs.h:74
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:624
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 624 of file ParserNode.h.

References arg.

624 { return arg.get(); }
std::unique_ptr< Expr > arg
Definition: ParserNode.h:634
bool Parser::FunctionRef::get_distinct ( ) const
inline

Definition at line 623 of file ParserNode.h.

References distinct.

623 { return distinct; }
const std::string* Parser::FunctionRef::get_name ( ) const
inline

Definition at line 622 of file ParserNode.h.

References name.

622 { return name.get(); }
std::unique_ptr< std::string > name
Definition: ParserNode.h:632
std::string Parser::FunctionRef::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 1420 of file ParserNode.cpp.

References setup::name.

1420  {
1421  std::string str = *name + "(";
1422  if (distinct) {
1423  str += "DISTINCT ";
1424  }
1425  if (arg == nullptr) {
1426  str += "*)";
1427  } else {
1428  str += arg->to_string() + ")";
1429  }
1430  return str;
1431 }
std::unique_ptr< Expr > arg
Definition: ParserNode.h:634
std::unique_ptr< std::string > name
Definition: ParserNode.h:632

Member Data Documentation

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

Definition at line 634 of file ParserNode.h.

Referenced by get_arg().

bool Parser::FunctionRef::distinct
private

Definition at line 633 of file ParserNode.h.

Referenced by get_distinct().


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