OmniSciDB  b24e664e58
 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 633 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 635 of file ParserNode.h.

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

Definition at line 636 of file ParserNode.h.

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

Definition at line 637 of file ParserNode.h.

637 : name(n), distinct(d), arg(a) {}
std::unique_ptr< Expr > arg
Definition: ParserNode.h:650
std::unique_ptr< std::string > name
Definition: ParserNode.h:648

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 770 of file ParserNode.cpp.

References SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), Analyzer::Query::get_num_aggs(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_integer(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), kARRAY, kAVG, kBIGINT, kCOUNT, kDOUBLE, kENCODING_DICT, kMAX, kMIN, kSUM, kUNNEST, and Analyzer::Query::set_num_aggs().

773  {
774  SQLTypeInfo result_type;
775  SQLAgg agg_type;
776  std::shared_ptr<Analyzer::Expr> arg_expr;
777  bool is_distinct = false;
778  if (boost::iequals(*name, "count")) {
779  result_type = SQLTypeInfo(kBIGINT, false);
780  agg_type = kCOUNT;
781  if (arg) {
782  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
783  const SQLTypeInfo& ti = arg_expr->get_type_info();
784  if (ti.is_string() && (ti.get_compression() != kENCODING_DICT || !distinct)) {
785  throw std::runtime_error(
786  "Strings must be dictionary-encoded in COUNT(DISTINCT).");
787  }
788  if (ti.get_type() == kARRAY && !distinct) {
789  throw std::runtime_error("Only COUNT(DISTINCT) is supported on arrays.");
790  }
791  }
792  is_distinct = distinct;
793  } else {
794  if (!arg) {
795  throw std::runtime_error("Cannot compute " + *name + " with argument '*'.");
796  }
797  if (boost::iequals(*name, "min")) {
798  agg_type = kMIN;
799  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
800  arg_expr = arg_expr->decompress();
801  result_type = arg_expr->get_type_info();
802  } else if (boost::iequals(*name, "max")) {
803  agg_type = kMAX;
804  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
805  arg_expr = arg_expr->decompress();
806  result_type = arg_expr->get_type_info();
807  } else if (boost::iequals(*name, "avg")) {
808  agg_type = kAVG;
809  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
810  if (!arg_expr->get_type_info().is_number()) {
811  throw std::runtime_error("Cannot compute AVG on non-number-type arguments.");
812  }
813  arg_expr = arg_expr->decompress();
814  result_type = SQLTypeInfo(kDOUBLE, false);
815  } else if (boost::iequals(*name, "sum")) {
816  agg_type = kSUM;
817  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
818  if (!arg_expr->get_type_info().is_number()) {
819  throw std::runtime_error("Cannot compute SUM on non-number-type arguments.");
820  }
821  arg_expr = arg_expr->decompress();
822  result_type = arg_expr->get_type_info().is_integer() ? SQLTypeInfo(kBIGINT, false)
823  : arg_expr->get_type_info();
824  } else if (boost::iequals(*name, "unnest")) {
825  arg_expr = arg->analyze(catalog, query, allow_tlist_ref);
826  const SQLTypeInfo& arg_ti = arg_expr->get_type_info();
827  if (arg_ti.get_type() != kARRAY) {
828  throw std::runtime_error(arg->to_string() + " is not of array type.");
829  }
830  return makeExpr<Analyzer::UOper>(arg_ti.get_elem_type(), false, kUNNEST, arg_expr);
831  } else {
832  throw std::runtime_error("invalid function name: " + *name);
833  }
834  if (arg_expr->get_type_info().is_string() ||
835  arg_expr->get_type_info().get_type() == kARRAY) {
836  throw std::runtime_error(
837  "Only COUNT(DISTINCT ) aggregate is supported on strings and arrays.");
838  }
839  }
840  int naggs = query.get_num_aggs();
841  query.set_num_aggs(naggs + 1);
842  return makeExpr<Analyzer::AggExpr>(
843  result_type, agg_type, arg_expr, is_distinct, nullptr);
844 }
SQLAgg
Definition: sqldefs.h:71
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
int get_num_aggs() const
Definition: Analyzer.h:1525
Definition: sqldefs.h:71
std::unique_ptr< Expr > arg
Definition: ParserNode.h:650
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
Definition: sqldefs.h:71
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
void set_num_aggs(int a)
Definition: Analyzer.h:1554
bool is_integer() const
Definition: sqltypes.h:479
Definition: sqldefs.h:71
std::unique_ptr< std::string > name
Definition: ParserNode.h:648
bool is_string() const
Definition: sqltypes.h:477
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:659
Definition: sqldefs.h:71
Definition: sqldefs.h:71
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 640 of file ParserNode.h.

References arg.

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

Definition at line 639 of file ParserNode.h.

References distinct.

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

Definition at line 638 of file ParserNode.h.

References name.

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

Implements Parser::Expr.

Definition at line 1478 of file ParserNode.cpp.

1478  {
1479  std::string str = *name + "(";
1480  if (distinct) {
1481  str += "DISTINCT ";
1482  }
1483  if (arg == nullptr) {
1484  str += "*)";
1485  } else {
1486  str += arg->to_string() + ")";
1487  }
1488  return str;
1489 }
std::unique_ptr< Expr > arg
Definition: ParserNode.h:650
std::unique_ptr< std::string > name
Definition: ParserNode.h:648

Member Data Documentation

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

Definition at line 650 of file ParserNode.h.

Referenced by get_arg().

bool Parser::FunctionRef::distinct
private

Definition at line 649 of file ParserNode.h.

Referenced by get_distinct().

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

Definition at line 648 of file ParserNode.h.

Referenced by get_name().


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