OmniSciDB  c07336695a
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 622 of file ParserNode.h.

Constructor & Destructor Documentation

◆ FunctionRef() [1/3]

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

Definition at line 624 of file ParserNode.h.

624 : name(n), distinct(false), arg(nullptr) {}
std::unique_ptr< Expr > arg
Definition: ParserNode.h:639
std::unique_ptr< std::string > name
Definition: ParserNode.h:637

◆ FunctionRef() [2/3]

Parser::FunctionRef::FunctionRef ( std::string *  n,
Expr a 
)
inline

Definition at line 625 of file ParserNode.h.

625 : name(n), distinct(false), arg(a) {}
std::unique_ptr< Expr > arg
Definition: ParserNode.h:639
std::unique_ptr< std::string > name
Definition: ParserNode.h:637

◆ FunctionRef() [3/3]

Parser::FunctionRef::FunctionRef ( std::string *  n,
bool  d,
Expr a 
)
inline

Definition at line 626 of file ParserNode.h.

626 : name(n), distinct(d), arg(a) {}
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
std::unique_ptr< Expr > arg
Definition: ParserNode.h:639
std::unique_ptr< std::string > name
Definition: ParserNode.h:637

Member Function Documentation

◆ analyze()

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

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

◆ get_arg()

Expr* Parser::FunctionRef::get_arg ( ) const
inline

Definition at line 629 of file ParserNode.h.

References anonymous_namespace{UpdateMetadataTest.cpp}::query, and to_string().

629 { return arg.get(); }
std::unique_ptr< Expr > arg
Definition: ParserNode.h:639
+ Here is the call graph for this function:

◆ get_distinct()

bool Parser::FunctionRef::get_distinct ( ) const
inline

Definition at line 628 of file ParserNode.h.

628 { return distinct; }

◆ get_name()

const std::string* Parser::FunctionRef::get_name ( ) const
inline

Definition at line 627 of file ParserNode.h.

627 { return name.get(); }
std::unique_ptr< std::string > name
Definition: ParserNode.h:637

◆ to_string()

std::string Parser::FunctionRef::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 1463 of file ParserNode.cpp.

1463  {
1464  std::string str = *name + "(";
1465  if (distinct) {
1466  str += "DISTINCT ";
1467  }
1468  if (arg == nullptr) {
1469  str += "*)";
1470  } else {
1471  str += arg->to_string() + ")";
1472  }
1473  return str;
1474 }
std::unique_ptr< Expr > arg
Definition: ParserNode.h:639
std::unique_ptr< std::string > name
Definition: ParserNode.h:637

Member Data Documentation

◆ arg

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

Definition at line 639 of file ParserNode.h.

◆ distinct

bool Parser::FunctionRef::distinct
private

Definition at line 638 of file ParserNode.h.

◆ name

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

Definition at line 637 of file ParserNode.h.


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