OmniSciDB  06b3bd477c
 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 787 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().

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

1422  {
1423  std::string str = *name + "(";
1424  if (distinct) {
1425  str += "DISTINCT ";
1426  }
1427  if (arg == nullptr) {
1428  str += "*)";
1429  } else {
1430  str += arg->to_string() + ")";
1431  }
1432  return str;
1433 }
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().

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

Definition at line 632 of file ParserNode.h.

Referenced by get_name().


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