OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer::StringOper Class Reference

Expression class for string functions The "arg" constructor parameter must be an expression that resolves to a string datatype (e.g. TEXT). More...

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::StringOper:
+ Collaboration diagram for Analyzer::StringOper:

Public Types

enum  OperandTypeFamily { OperandTypeFamily::STRING_FAMILY, OperandTypeFamily::INT_FAMILY }
 
using LiteralArgMap = std::map< size_t, std::pair< SQLTypes, Datum >>
 

Public Member Functions

 StringOper (const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
 
 StringOper (const SqlStringOpKind kind, const SQLTypeInfo &return_ti, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
 
 StringOper (const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names)
 
 StringOper (const SqlStringOpKind kind, const SQLTypeInfo &return_ti, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names)
 
 StringOper (const SqlStringOpKind kind, const SQLTypeInfo &return_ti, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const std::vector< std::shared_ptr< Analyzer::Expr >> &chained_string_op_exprs)
 
 StringOper (const StringOper &other_string_oper)
 
 StringOper (const std::shared_ptr< StringOper > &other_string_oper)
 
SqlStringOpKind get_kind () const
 
size_t getArity () const
 
size_t getLiteralsArity () const
 
size_t getNonLiteralsArity () const
 
const ExprgetArg (const size_t i) const
 
std::shared_ptr< Analyzer::ExprgetOwnArg (const size_t i) const
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
getOwnArgs () const
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
getChainedStringOpExprs () const
 
bool requiresPerRowTranslation () const
 
void collect_rte_idx (std::set< int > &rte_idx_set) const override
 
void collect_column_var (std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
 
bool hasNoneEncodedTextArg () const
 
bool hasSingleDictEncodedColInput () const
 returns whether we have one and only one column involved in this StringOper and all its descendents, and that that column is a dictionary-encoded text type More...
 
std::vector< size_t > getLiteralArgIndexes () const
 
LiteralArgMap getLiteralArgs () const
 
std::shared_ptr< Analyzer::Exprrewrite_with_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_with_child_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_agg_to_var (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
void group_predicates (std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
 
bool operator== (const Expr &rhs) const override
 
std::string toString () const override
 
void find_expr (std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
 
virtual size_t getMinArgs () const
 
virtual std::vector
< OperandTypeFamily
getExpectedTypeFamilies () const
 
virtual std::vector< std::string > getArgNames () const
 
- Public Member Functions inherited from Analyzer::Expr
 Expr (SQLTypes t, bool notnull)
 
 Expr (SQLTypes t, int d, bool notnull)
 
 Expr (SQLTypes t, int d, int s, bool notnull)
 
 Expr (const SQLTypeInfo &ti, bool has_agg=false)
 
virtual ~Expr ()
 
std::shared_ptr< Analyzer::Exprget_shared_ptr ()
 
const SQLTypeInfoget_type_info () const
 
void set_type_info (const SQLTypeInfo &ti)
 
bool get_contains_agg () const
 
void set_contains_agg (bool a)
 
virtual std::shared_ptr
< Analyzer::Expr
add_cast (const SQLTypeInfo &new_type_info)
 
virtual void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
 
virtual std::shared_ptr
< Analyzer::Expr
normalize_simple_predicate (int &rte_idx) const
 
virtual size_t get_num_column_vars (const bool include_agg) const
 
virtual void print () const
 
virtual void add_unique (std::list< const Expr * > &expr_list) const
 
std::shared_ptr< Analyzer::Exprdecompress ()
 
virtual void get_domain (DomainSet &domain_set) const
 

Private Member Functions

void check_operand_types (const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names, const bool dict_encoded_cols_only=false, const bool cols_first_arg_only=true) const
 

Static Private Member Functions

static SQLTypeInfo get_return_type (const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
 

Private Attributes

SqlStringOpKind kind_
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
args_
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
chained_string_op_exprs_
 

Additional Inherited Members

- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Expression class for string functions The "arg" constructor parameter must be an expression that resolves to a string datatype (e.g. TEXT).

Definition at line 1475 of file Analyzer.h.

Member Typedef Documentation

using Analyzer::StringOper::LiteralArgMap = std::map<size_t, std::pair<SQLTypes, Datum>>

Definition at line 1639 of file Analyzer.h.

Member Enumeration Documentation

Enumerator
STRING_FAMILY 
INT_FAMILY 

Definition at line 1479 of file Analyzer.h.

1479 { STRING_FAMILY, INT_FAMILY };

Constructor & Destructor Documentation

Analyzer::StringOper::StringOper ( const SqlStringOpKind  kind,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args 
)
inline

Definition at line 1481 of file Analyzer.h.

1483  : Expr(StringOper::get_return_type(kind, args)), kind_(kind), args_(args) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
static SQLTypeInfo get_return_type(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.cpp:4077
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
Analyzer::StringOper::StringOper ( const SqlStringOpKind  kind,
const SQLTypeInfo return_ti,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args 
)
inline

Definition at line 1485 of file Analyzer.h.

1488  : Expr(return_ti), kind_(kind), args_(args) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
Analyzer::StringOper::StringOper ( const SqlStringOpKind  kind,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args,
const size_t  min_args,
const std::vector< OperandTypeFamily > &  expected_type_families,
const std::vector< std::string > &  arg_names 
)
inline

Definition at line 1490 of file Analyzer.h.

References check_operand_types(), CONCAT, and RCONCAT.

1495  : Expr(StringOper::get_return_type(kind, args)), kind_(kind), args_(args) {
1496  check_operand_types(min_args,
1497  expected_type_families,
1498  arg_names,
1499  false /* dict_encoded_cols_only */,
1500  !(kind == SqlStringOpKind::CONCAT ||
1501  kind == SqlStringOpKind::RCONCAT) /* cols_first_arg_only */);
1502  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
void check_operand_types(const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names, const bool dict_encoded_cols_only=false, const bool cols_first_arg_only=true) const
Definition: Analyzer.cpp:4113
static SQLTypeInfo get_return_type(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.cpp:4077
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689

+ Here is the call graph for this function:

Analyzer::StringOper::StringOper ( const SqlStringOpKind  kind,
const SQLTypeInfo return_ti,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args,
const size_t  min_args,
const std::vector< OperandTypeFamily > &  expected_type_families,
const std::vector< std::string > &  arg_names 
)
inline

Definition at line 1504 of file Analyzer.h.

References check_operand_types(), CONCAT, and RCONCAT.

1510  : Expr(return_ti), kind_(kind), args_(args) {
1511  check_operand_types(min_args,
1512  expected_type_families,
1513  arg_names,
1514  false /* dict_encoded_cols_only */,
1515  !(kind == SqlStringOpKind::CONCAT ||
1516  kind == SqlStringOpKind::RCONCAT) /* cols_first_arg_only */);
1517  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
void check_operand_types(const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names, const bool dict_encoded_cols_only=false, const bool cols_first_arg_only=true) const
Definition: Analyzer.cpp:4113
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689

+ Here is the call graph for this function:

Analyzer::StringOper::StringOper ( const SqlStringOpKind  kind,
const SQLTypeInfo return_ti,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  chained_string_op_exprs 
)
inline

Definition at line 1519 of file Analyzer.h.

1523  : Expr(return_ti)
1524  , kind_(kind)
1525  , args_(args)
1526  , chained_string_op_exprs_(chained_string_op_exprs) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1691
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
Analyzer::StringOper::StringOper ( const StringOper other_string_oper)
inline

Definition at line 1528 of file Analyzer.h.

References args_, chained_string_op_exprs_, and kind_.

1529  : Expr(other_string_oper.get_type_info()) {
1530  kind_ = other_string_oper.kind_;
1531  args_ = other_string_oper.args_;
1532  chained_string_op_exprs_ = other_string_oper.chained_string_op_exprs_;
1533  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1691
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
Analyzer::StringOper::StringOper ( const std::shared_ptr< StringOper > &  other_string_oper)
inline

Definition at line 1535 of file Analyzer.h.

References args_, chained_string_op_exprs_, and kind_.

1536  : Expr(other_string_oper->get_type_info()) {
1537  kind_ = other_string_oper->kind_;
1538  args_ = other_string_oper->args_;
1539  chained_string_op_exprs_ = other_string_oper->chained_string_op_exprs_;
1540  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1691
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689

Member Function Documentation

void Analyzer::StringOper::check_operand_types ( const size_t  min_args,
const std::vector< OperandTypeFamily > &  expected_type_families,
const std::vector< std::string > &  arg_names,
const bool  dict_encoded_cols_only = false,
const bool  cols_first_arg_only = true 
) const
private

Definition at line 4113 of file Analyzer.cpp.

References args_, CHECK_EQ, g_enable_string_functions, get_kind(), Analyzer::Expr::get_type_info(), INT_FAMILY, IS_INTEGER, remove_cast(), STRING_FAMILY, and toString().

Referenced by StringOper().

4118  {
4119  std::ostringstream oss;
4121  oss << "Function " << ::toString(get_kind()) << " not supported.";
4122  throw std::runtime_error(oss.str());
4123  }
4124  const size_t num_args = args_.size();
4125  CHECK_EQ(expected_type_families.size(), arg_names.size());
4126  if (num_args < min_args || num_args > expected_type_families.size()) {
4127  oss << "Error instantiating " << ::toString(get_kind()) << " operator. ";
4128  oss << "Expected " << expected_type_families.size() << " arguments, but received "
4129  << num_args << ".";
4130  }
4131  for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
4132  const auto& expected_type_family = expected_type_families[arg_idx];
4133  // We need to remove any casts that Calcite may add to try the right operand type,
4134  // even if we don't support them. Need to check how this works with casts we do
4135  // support.
4136  auto arg_ti = args_[arg_idx]->get_type_info();
4137  const auto decasted_arg = remove_cast(args_[arg_idx]);
4138  const bool is_arg_case =
4139  dynamic_cast<const Analyzer::CaseExpr*>(decasted_arg.get()) != nullptr;
4140  if (is_arg_case) {
4141  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4142  << "Currently string operations cannot be run on output of a case "
4143  << "statement.";
4144  throw std::runtime_error(oss.str());
4145  }
4146  const bool is_arg_constant =
4147  dynamic_cast<const Analyzer::Constant*>(decasted_arg.get()) != nullptr;
4148  auto decasted_arg_ti = decasted_arg->get_type_info();
4149  // We need to prevent any non-string type from being casted to a string, but can
4150  // permit non-integer types being casted to integers Todo: Find a cleaner way to
4151  // handle this (we haven't validated any of the casts that calcite has given us at
4152  // the point of RelAlgTranslation)
4153  if (arg_ti != decasted_arg_ti &&
4154  (arg_ti.is_integer() && decasted_arg_ti.is_string())) {
4155  arg_ti = decasted_arg_ti;
4156  }
4157 
4158  if (cols_first_arg_only && !is_arg_constant && arg_idx >= 1UL) {
4159  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4160  << "Currently only column inputs are allowed for argument '" << arg_names[0]
4161  << "', but a column input was received for argument '" << arg_names[arg_idx]
4162  << "'.";
4163  throw std::runtime_error(oss.str());
4164  }
4165  switch (expected_type_family) {
4167  if (!arg_ti.is_string()) {
4168  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4169  << "Expected text type for argument '" << arg_names[arg_idx] << "'";
4170  throw std::runtime_error(oss.str());
4171  break;
4172  }
4173  if (dict_encoded_cols_only &&
4174  (!is_arg_constant && !arg_ti.is_dict_encoded_string())) {
4175  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4176  << "Currently only text-encoded dictionary-encoded column inputs are "
4177  << "allowed, but a none-encoded text column argument was received.";
4178  throw std::runtime_error(oss.str());
4179  break;
4180  }
4181  break;
4182  }
4184  if (!IS_INTEGER(arg_ti.get_type())) {
4185  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4186  << "Expected integer type for argument " << arg_idx + 1 << " ('"
4187  << arg_names[arg_idx] << "').";
4188  throw std::runtime_error(oss.str());
4189  break;
4190  }
4191  if (!is_arg_constant) {
4192  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4193  << "Currently only text-encoded dictionary column inputs are "
4194  << "allowed, but an integer-type column was provided.";
4195  throw std::runtime_error(oss.str());
4196  break;
4197  }
4198  break;
4199  }
4200  }
4201  }
4202 }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4325
bool g_enable_string_functions
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:83
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1542
#define IS_INTEGER(T)
Definition: sqltypes.h:292
std::string toString() const override
Definition: Analyzer.cpp:3687

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Analyzer::StringOper::collect_column_var ( std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &  colvar_set,
bool  include_agg 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3406 of file Analyzer.cpp.

References args_.

Referenced by hasSingleDictEncodedColInput().

3408  {
3409  for (const auto& arg : args_) {
3410  arg->collect_column_var(colvar_set, include_agg);
3411  }
3412 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690

+ Here is the caller graph for this function:

void Analyzer::StringOper::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3346 of file Analyzer.cpp.

References args_.

3346  {
3347  for (const auto& arg : args_) {
3348  arg->collect_rte_idx(rte_idx_set);
3349  }
3350 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
std::shared_ptr< Analyzer::Expr > Analyzer::StringOper::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Reimplemented in Analyzer::PositionStringOper, Analyzer::TryStringCastOper, Analyzer::Base64DecodeStringOper, Analyzer::Base64EncodeStringOper, Analyzer::JsonValueStringOper, Analyzer::RegexpSubstrStringOper, Analyzer::RegexpReplaceStringOper, Analyzer::SplitPartStringOper, Analyzer::ReplaceStringOper, Analyzer::OverlayStringOper, Analyzer::SubstringStringOper, Analyzer::TrimStringOper, Analyzer::PadStringOper, Analyzer::ConcatStringOper, Analyzer::RepeatStringOper, Analyzer::ReverseStringOper, Analyzer::InitCapStringOper, Analyzer::UpperStringOper, and Analyzer::LowerStringOper.

Definition at line 3515 of file Analyzer.cpp.

References args_, chained_string_op_exprs_, Analyzer::Expr::get_type_info(), and kind_.

Referenced by Analyzer::LowerStringOper::deep_copy(), Analyzer::UpperStringOper::deep_copy(), Analyzer::InitCapStringOper::deep_copy(), Analyzer::ReverseStringOper::deep_copy(), Analyzer::RepeatStringOper::deep_copy(), Analyzer::ConcatStringOper::deep_copy(), Analyzer::PadStringOper::deep_copy(), Analyzer::TrimStringOper::deep_copy(), Analyzer::SubstringStringOper::deep_copy(), Analyzer::OverlayStringOper::deep_copy(), Analyzer::ReplaceStringOper::deep_copy(), Analyzer::SplitPartStringOper::deep_copy(), Analyzer::RegexpReplaceStringOper::deep_copy(), Analyzer::RegexpSubstrStringOper::deep_copy(), Analyzer::JsonValueStringOper::deep_copy(), Analyzer::Base64EncodeStringOper::deep_copy(), Analyzer::Base64DecodeStringOper::deep_copy(), Analyzer::TryStringCastOper::deep_copy(), Analyzer::PositionStringOper::deep_copy(), and DeepCopyVisitor::visitStringOper().

3515  {
3516  std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3517  for (const auto& arg : args_) {
3518  args_copy.emplace_back(arg->deep_copy());
3519  }
3520  std::vector<std::shared_ptr<Analyzer::Expr>> chained_string_op_exprs_copy;
3521  for (const auto& chained_string_op_expr : chained_string_op_exprs_) {
3522  chained_string_op_exprs_copy.emplace_back(chained_string_op_expr->deep_copy());
3523  }
3524  return makeExpr<Analyzer::StringOper>(kind_,
3525  get_type_info(),
3526  std::move(args_copy),
3527  std::move(chained_string_op_exprs_copy));
3528 }
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1691
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:83
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Analyzer::StringOper::find_expr ( std::function< bool(const Expr *)>  f,
std::list< const Expr * > &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3169 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), args_, and anonymous_namespace{Utm.h}::f.

3170  {
3171  if (f(this)) {
3172  add_unique(expr_list);
3173  return;
3174  }
3175  for (const auto& arg : args_) {
3176  arg->find_expr(f, expr_list);
3177  }
3178 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3101
constexpr double f
Definition: Utm.h:31
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690

+ Here is the call graph for this function:

SqlStringOpKind Analyzer::StringOper::get_kind ( ) const
inline

Definition at line 1542 of file Analyzer.h.

References kind_.

Referenced by check_operand_types(), CodeGenerator::codegenPerRowStringOper(), operator==(), TransientStringLiteralsVisitor::visitStringOper(), anonymous_namespace{RelAlgExecutor.cpp}::TextEncodingCastCountVisitor::visitStringOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

1542 { return kind_; }
SqlStringOpKind kind_
Definition: Analyzer.h:1689

+ Here is the caller graph for this function:

SQLTypeInfo Analyzer::StringOper::get_return_type ( const SqlStringOpKind  kind,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args 
)
staticprivate

Definition at line 4077 of file Analyzer.cpp.

References run_benchmark_import::args, CHECK_NE, kENCODING_DICT, kNULLT, kTEXT, remove_cast(), TRANSIENT_DICT_ID, and TRY_STRING_CAST.

4079  {
4081  << "get_return_type for TRY_STRING_CAST disallowed.";
4082  SQLTypeInfo return_ti(kNULLT);
4083  size_t num_var_string_inputs{0};
4084  for (const auto& arg : args) {
4085  const auto raw_arg = arg.get();
4086  const auto& arg_ti = arg->get_type_info();
4087  if (dynamic_cast<const Analyzer::CaseExpr*>(remove_cast(raw_arg))) {
4088  // Currently we disallow case statement inputs to string functions
4089  // pending a full resolution to QE-359, but the error is thrown
4090  // downstream in StringOper::check_operand_types
4091  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4092  } else if (arg_ti.is_string() && dynamic_cast<const Analyzer::Constant*>(raw_arg)) {
4093  if (return_ti == SQLTypeInfo(kNULLT)) {
4094  return_ti = arg_ti;
4095  }
4096  } else if (arg_ti.is_none_encoded_string()) {
4097  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4098  } else if (arg_ti.is_dict_encoded_string()) {
4099  if (arg_ti.get_comp_param() == TRANSIENT_DICT_ID) {
4100  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4101  } else {
4102  num_var_string_inputs++;
4103  return_ti = arg_ti;
4104  }
4105  }
4106  }
4107  if (num_var_string_inputs > 1UL) {
4108  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4109  }
4110  return return_ti;
4111 }
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4325
#define CHECK_NE(x, y)
Definition: Logger.h:298
Definition: sqltypes.h:67
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:310

+ Here is the call graph for this function:

const Expr* Analyzer::StringOper::getArg ( const size_t  i) const
inline

Definition at line 1558 of file Analyzer.h.

References args_, and CHECK_LT.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenStringFetchAndEncode(), getLiteralArgs(), operator==(), pre_translate_string_ops(), translate_dict_strings(), TransientStringLiteralsVisitor::visitStringOper(), and anonymous_namespace{RelAlgExecutor.cpp}::TextEncodingCastCountVisitor::visitStringOper().

1558  {
1559  CHECK_LT(i, args_.size());
1560  return args_[i].get();
1561  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
#define CHECK_LT(x, y)
Definition: Logger.h:299

+ Here is the caller graph for this function:

size_t Analyzer::StringOper::getArity ( ) const
inline

Definition at line 1544 of file Analyzer.h.

References args_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenPerRowStringOper(), CodeGenerator::codegenStringFetchAndEncode(), getLiteralArgs(), getNonLiteralsArity(), operator==(), pre_translate_string_ops(), TransientStringLiteralsVisitor::visitStringOper(), anonymous_namespace{RelAlgExecutor.cpp}::TextEncodingCastCountVisitor::visitStringOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

1544 { return args_.size(); }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690

+ Here is the caller graph for this function:

std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::StringOper::getChainedStringOpExprs ( ) const
inline

Definition at line 1570 of file Analyzer.h.

References chained_string_op_exprs_.

Referenced by getExpressionRange(), getStringOpInfos(), and TransientStringLiteralsVisitor::visitStringOper().

1570  {
1571  return chained_string_op_exprs_;
1572  }
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1691

+ Here is the caller graph for this function:

std::vector< size_t > Analyzer::StringOper::getLiteralArgIndexes ( ) const

Definition at line 4049 of file Analyzer.cpp.

References args_.

4049  {
4050  std::vector<size_t> literal_arg_indexes;
4051  const auto num_args = args_.size();
4052  for (size_t idx = 0; idx < num_args; ++idx) {
4053  if (dynamic_cast<const Constant*>(args_[idx].get())) {
4054  literal_arg_indexes.emplace_back(idx);
4055  }
4056  }
4057  return literal_arg_indexes;
4058 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
LiteralArgMap Analyzer::StringOper::getLiteralArgs ( ) const

Definition at line 4062 of file Analyzer.cpp.

References getArg(), and getArity().

Referenced by TransientStringLiteralsVisitor::visitStringOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

4062  {
4063  LiteralArgMap literal_arg_map;
4064  const auto num_args = getArity();
4065  for (size_t idx = 0; idx < num_args; ++idx) {
4066  const auto constant_arg_expr = dynamic_cast<const Analyzer::Constant*>(getArg(idx));
4067  if (constant_arg_expr) {
4068  literal_arg_map.emplace(
4069  std::make_pair(idx,
4070  std::make_pair(constant_arg_expr->get_type_info().get_type(),
4071  constant_arg_expr->get_constval())));
4072  }
4073  }
4074  return literal_arg_map;
4075 }
std::map< size_t, std::pair< SQLTypes, Datum >> LiteralArgMap
Definition: Analyzer.h:1639
size_t getArity() const
Definition: Analyzer.h:1544
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1558

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t Analyzer::StringOper::getLiteralsArity ( ) const
inline

Definition at line 1546 of file Analyzer.h.

References args_.

Referenced by getNonLiteralsArity(), and TransientStringLiteralsVisitor::visitStringOper().

1546  {
1547  size_t num_literals{0UL};
1548  for (const auto& arg : args_) {
1549  if (dynamic_cast<const Constant*>(arg.get())) {
1550  num_literals++;
1551  }
1552  }
1553  return num_literals;
1554  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690

+ Here is the caller graph for this function:

size_t Analyzer::StringOper::getNonLiteralsArity ( ) const
inline

Definition at line 1556 of file Analyzer.h.

References getArity(), and getLiteralsArity().

Referenced by CodeGenerator::codegenPerRowStringOper(), TransientStringLiteralsVisitor::visitStringOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

1556 { return getArity() - getLiteralsArity(); }
size_t getArity() const
Definition: Analyzer.h:1544
size_t getLiteralsArity() const
Definition: Analyzer.h:1546

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::Expr> Analyzer::StringOper::getOwnArg ( const size_t  i) const
inline

Definition at line 1563 of file Analyzer.h.

References args_, and CHECK_LT.

1563  {
1564  CHECK_LT(i, args_.size());
1565  return args_[i];
1566  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
#define CHECK_LT(x, y)
Definition: Logger.h:299
std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::StringOper::getOwnArgs ( ) const
inline

Definition at line 1568 of file Analyzer.h.

References args_.

Referenced by ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitStringOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

1568 { return args_; }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690

+ Here is the caller graph for this function:

void Analyzer::StringOper::group_predicates ( std::list< const Expr * > &  scan_predicates,
std::list< const Expr * > &  join_predicates,
std::list< const Expr * > &  const_predicates 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1710 of file Analyzer.cpp.

References args_.

1712  {
1713  std::set<int> rte_idx_set;
1714  for (const auto& arg : args_) {
1715  arg->collect_rte_idx(rte_idx_set);
1716  }
1717  if (rte_idx_set.size() > 1) {
1718  join_predicates.push_back(this);
1719  } else if (rte_idx_set.size() == 1) {
1720  scan_predicates.push_back(this);
1721  } else {
1722  const_predicates.push_back(this);
1723  }
1724 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
bool Analyzer::StringOper::hasNoneEncodedTextArg ( ) const
inline

Definition at line 1613 of file Analyzer.h.

References args_, CHECK, and TRANSIENT_DICT_ID.

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::TextEncodingCastCountVisitor::visitStringOper().

1613  {
1614  if (args_.empty()) {
1615  return false;
1616  }
1617  const auto& arg0_ti = args_[0]->get_type_info();
1618  if (!arg0_ti.is_string()) {
1619  return false;
1620  }
1621  if (arg0_ti.is_none_encoded_string()) {
1622  return true;
1623  }
1624  CHECK(arg0_ti.is_dict_encoded_string());
1625  return arg0_ti.get_comp_param() == TRANSIENT_DICT_ID;
1626  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:310
#define CHECK(condition)
Definition: Logger.h:289

+ Here is the caller graph for this function:

bool Analyzer::StringOper::hasSingleDictEncodedColInput ( ) const

returns whether we have one and only one column involved in this StringOper and all its descendents, and that that column is a dictionary-encoded text type

Returns
std::vector<SqlTypeInfo>

Definition at line 4035 of file Analyzer.cpp.

References CHECK, collect_column_var(), and Analyzer::ColumnVar::colvar_comp().

4035  {
4036  auto comparator = Analyzer::ColumnVar::colvar_comp;
4037  std::set<const Analyzer::ColumnVar*,
4038  bool (*)(const Analyzer::ColumnVar*, const Analyzer::ColumnVar*)>
4039  colvar_set(comparator);
4040  collect_column_var(colvar_set, true);
4041  if (colvar_set.size() != 1UL) {
4042  return false;
4043  }
4044  auto col_expr_ptr = *colvar_set.begin();
4045  CHECK(col_expr_ptr);
4046  return col_expr_ptr->get_type_info().is_dict_encoded_string();
4047 }
static bool colvar_comp(const ColumnVar *l, const ColumnVar *r)
Definition: Analyzer.h:217
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3406
#define CHECK(condition)
Definition: Logger.h:289

+ Here is the call graph for this function:

bool Analyzer::StringOper::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 3633 of file Analyzer.cpp.

References chained_string_op_exprs_, get_kind(), getArg(), and getArity().

3633  {
3634  const auto rhs_string_oper = dynamic_cast<const StringOper*>(&rhs);
3635 
3636  if (!rhs_string_oper) {
3637  return false;
3638  }
3639 
3640  if (get_kind() != rhs_string_oper->get_kind()) {
3641  return false;
3642  }
3643  if (getArity() != rhs_string_oper->getArity()) {
3644  return false;
3645  }
3646 
3647  for (size_t i = 0; i < getArity(); ++i) {
3648  if (!(*getArg(i) == *(rhs_string_oper->getArg(i)))) {
3649  return false;
3650  }
3651  }
3652  if (chained_string_op_exprs_.size() !=
3653  rhs_string_oper->chained_string_op_exprs_.size()) {
3654  return false;
3655  }
3656  for (size_t i = 0; i < chained_string_op_exprs_.size(); ++i) {
3657  if (!(*(chained_string_op_exprs_[i]) ==
3658  *(rhs_string_oper->chained_string_op_exprs_[i]))) {
3659  return false;
3660  }
3661  }
3662  return true;
3663 }
size_t getArity() const
Definition: Analyzer.h:1544
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1691
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1481
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1542
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1558

+ Here is the call graph for this function:

bool Analyzer::StringOper::requiresPerRowTranslation ( ) const
inline

Definition at line 1574 of file Analyzer.h.

References args_, Analyzer::Expr::get_type_info(), and TRANSIENT_DICT_ID.

Referenced by CodeGenerator::codegen(), and getExpressionRange().

1574  {
1575  const auto& return_ti = get_type_info();
1576  if (return_ti.is_none_encoded_string() ||
1577  (return_ti.is_dict_encoded_string() &&
1578  return_ti.get_comp_param() == TRANSIENT_DICT_ID)) {
1579  return true;
1580  }
1581 
1582  // Anything that returns the transient dictionary by definition
1583  // (see StringOper::get_return_type) requires per-row translation,
1584  // but there is also a path with string->numeric functions (the output is
1585  // not a string) where we need to see if any of the inputs are none-encoded
1586  // or transient dictionary encoded, in which case we also need to do per-row
1587  // translation. The handling of that condition follows below.
1588 
1589  size_t num_var_str_args{0};
1590  for (const auto& arg : args_) {
1591  const auto arg_is_const = dynamic_cast<const Analyzer::Constant*>(arg.get());
1592  if (arg_is_const) {
1593  continue;
1594  }
1595  const auto& arg_ti = arg->get_type_info();
1596  if (arg_ti.is_none_encoded_string() ||
1597  (arg_ti.is_dict_encoded_string() &&
1598  arg_ti.get_comp_param() == TRANSIENT_DICT_ID)) {
1599  return true;
1600  }
1601  num_var_str_args++;
1602  }
1603  return num_var_str_args > 1UL;
1604  }
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:83
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:310

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< Analyzer::Expr > Analyzer::StringOper::rewrite_agg_to_var ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1985 of file Analyzer.cpp.

References args_, and kind_.

1986  {
1987  std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1988  for (const auto& arg : args_) {
1989  rewritten_args.emplace_back(arg->rewrite_agg_to_var(tlist));
1990  }
1991  return makeExpr<StringOper>(kind_, rewritten_args);
1992 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
std::shared_ptr< Analyzer::Expr > Analyzer::StringOper::rewrite_with_child_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1976 of file Analyzer.cpp.

References args_, and kind_.

1977  {
1978  std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1979  for (const auto& arg : args_) {
1980  rewritten_args.emplace_back(arg->rewrite_with_child_targetlist(tlist));
1981  }
1982  return makeExpr<StringOper>(kind_, rewritten_args);
1983 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
std::shared_ptr< Analyzer::Expr > Analyzer::StringOper::rewrite_with_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1967 of file Analyzer.cpp.

References args_, and kind_.

1968  {
1969  std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
1970  for (const auto& arg : args_) {
1971  rewritten_args.emplace_back(arg->rewrite_with_targetlist(tlist));
1972  }
1973  return makeExpr<StringOper>(kind_, rewritten_args);
1974 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
std::string Analyzer::StringOper::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 3687 of file Analyzer.cpp.

References args_, and kind_.

Referenced by check_operand_types().

3687  {
3688  std::string str{"(" + ::toString(kind_) + " "};
3689  for (const auto& arg : args_) {
3690  str += arg->toString();
3691  }
3692  str += ")";
3693  return str;
3694 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1690
SqlStringOpKind kind_
Definition: Analyzer.h:1689
std::string toString() const override
Definition: Analyzer.cpp:3687

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::StringOper::chained_string_op_exprs_
private

Definition at line 1691 of file Analyzer.h.

Referenced by deep_copy(), getChainedStringOpExprs(), operator==(), and StringOper().

SqlStringOpKind Analyzer::StringOper::kind_
private

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