OmniSciDB  a5dc49c757
 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 1601 of file Analyzer.h.

Member Typedef Documentation

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

Definition at line 1769 of file Analyzer.h.

Member Enumeration Documentation

Enumerator
STRING_FAMILY 
INT_FAMILY 

Definition at line 1605 of file Analyzer.h.

1605 { 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 1607 of file Analyzer.h.

1609  : Expr(StringOper::get_return_type(kind, args)), kind_(kind), args_(args) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
static SQLTypeInfo get_return_type(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.cpp:4325
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
Analyzer::StringOper::StringOper ( const SqlStringOpKind  kind,
const SQLTypeInfo return_ti,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args 
)
inline

Definition at line 1611 of file Analyzer.h.

1614  : Expr(return_ti), kind_(kind), args_(args) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
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 1616 of file Analyzer.h.

References check_operand_types(), CONCAT, JAROWINKLER_SIMILARITY, LEVENSHTEIN_DISTANCE, and RCONCAT.

1621  : Expr(StringOper::get_return_type(kind, args)), kind_(kind), args_(args) {
1623  min_args,
1624  expected_type_families,
1625  arg_names,
1626  false /* dict_encoded_cols_only */,
1627  !(kind == SqlStringOpKind::CONCAT || kind == SqlStringOpKind::RCONCAT ||
1629  kind == SqlStringOpKind::LEVENSHTEIN_DISTANCE) /* cols_first_arg_only */);
1630  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
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:4361
static SQLTypeInfo get_return_type(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.cpp:4325
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819

+ 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 1632 of file Analyzer.h.

References check_operand_types(), CONCAT, JAROWINKLER_SIMILARITY, LEVENSHTEIN_DISTANCE, and RCONCAT.

1638  : Expr(return_ti), kind_(kind), args_(args) {
1640  min_args,
1641  expected_type_families,
1642  arg_names,
1643  false /* dict_encoded_cols_only */,
1644  !(kind == SqlStringOpKind::CONCAT || kind == SqlStringOpKind::RCONCAT ||
1646  kind == SqlStringOpKind::LEVENSHTEIN_DISTANCE) /* cols_first_arg_only */);
1647  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
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:4361
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819

+ 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 1649 of file Analyzer.h.

1653  : Expr(return_ti)
1654  , kind_(kind)
1655  , args_(args)
1656  , chained_string_op_exprs_(chained_string_op_exprs) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1821
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
Analyzer::StringOper::StringOper ( const StringOper other_string_oper)
inline

Definition at line 1658 of file Analyzer.h.

References args_, chained_string_op_exprs_, and kind_.

1659  : Expr(other_string_oper.get_type_info()) {
1660  kind_ = other_string_oper.kind_;
1661  args_ = other_string_oper.args_;
1662  chained_string_op_exprs_ = other_string_oper.chained_string_op_exprs_;
1663  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1821
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
Analyzer::StringOper::StringOper ( const std::shared_ptr< StringOper > &  other_string_oper)
inline

Definition at line 1665 of file Analyzer.h.

References args_, chained_string_op_exprs_, and kind_.

1666  : Expr(other_string_oper->get_type_info()) {
1667  kind_ = other_string_oper->kind_;
1668  args_ = other_string_oper->args_;
1669  chained_string_op_exprs_ = other_string_oper->chained_string_op_exprs_;
1670  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1821
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819

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

4366  {
4367  std::ostringstream oss;
4369  oss << "Function " << ::toString(get_kind()) << " not supported.";
4370  throw std::runtime_error(oss.str());
4371  }
4372  const size_t num_args = args_.size();
4373  CHECK_EQ(expected_type_families.size(), arg_names.size());
4374  if (num_args < min_args || num_args > expected_type_families.size()) {
4375  oss << "Error instantiating " << ::toString(get_kind()) << " operator. ";
4376  oss << "Expected " << expected_type_families.size() << " arguments, but received "
4377  << num_args << ".";
4378  }
4379  for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
4380  const auto& expected_type_family = expected_type_families[arg_idx];
4381  // We need to remove any casts that Calcite may add to try the right operand type,
4382  // even if we don't support them. Need to check how this works with casts we do
4383  // support.
4384  auto arg_ti = args_[arg_idx]->get_type_info();
4385  const auto decasted_arg = remove_cast(args_[arg_idx]);
4386  const bool is_arg_case =
4387  dynamic_cast<const Analyzer::CaseExpr*>(decasted_arg.get()) != nullptr;
4388  if (is_arg_case) {
4389  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4390  << "Currently string operations cannot be run on output of a case "
4391  << "statement.";
4392  throw std::runtime_error(oss.str());
4393  }
4394  const bool is_arg_constant =
4395  dynamic_cast<const Analyzer::Constant*>(decasted_arg.get()) != nullptr;
4396  auto decasted_arg_ti = decasted_arg->get_type_info();
4397  // We need to prevent any non-string type from being casted to a string, but can
4398  // permit non-integer types being casted to integers Todo: Find a cleaner way to
4399  // handle this (we haven't validated any of the casts that calcite has given us at
4400  // the point of RelAlgTranslation)
4401  if (arg_ti != decasted_arg_ti &&
4402  (arg_ti.is_integer() && decasted_arg_ti.is_string())) {
4403  arg_ti = decasted_arg_ti;
4404  }
4405 
4406  if (cols_first_arg_only && !is_arg_constant && arg_idx >= 1UL) {
4407  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4408  << "Currently only column inputs are allowed for argument '" << arg_names[0]
4409  << "', but a column input was received for argument '" << arg_names[arg_idx]
4410  << "'.";
4411  throw std::runtime_error(oss.str());
4412  }
4413  switch (expected_type_family) {
4415  if (!arg_ti.is_string()) {
4416  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4417  << "Expected text type for argument '" << arg_names[arg_idx] << "'";
4418  throw std::runtime_error(oss.str());
4419  break;
4420  }
4421  if (dict_encoded_cols_only &&
4422  (!is_arg_constant && !arg_ti.is_dict_encoded_string())) {
4423  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4424  << "Currently only text-encoded dictionary-encoded column inputs are "
4425  << "allowed, but a none-encoded text column argument was received.";
4426  throw std::runtime_error(oss.str());
4427  break;
4428  }
4429  break;
4430  }
4432  if (!IS_INTEGER(arg_ti.get_type())) {
4433  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4434  << "Expected integer type for argument " << arg_idx + 1 << " ('"
4435  << arg_names[arg_idx] << "').";
4436  throw std::runtime_error(oss.str());
4437  break;
4438  }
4439  if (!is_arg_constant) {
4440  oss << "Error instantiating " << ::toString(get_kind()) << " operator. "
4441  << "Currently only text-encoded dictionary column inputs are "
4442  << "allowed, but an integer-type column was provided.";
4443  throw std::runtime_error(oss.str());
4444  break;
4445  }
4446  break;
4447  }
4448  }
4449  }
4450 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4611
bool g_enable_string_functions
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1672
#define IS_INTEGER(T)
Definition: sqltypes.h:304
std::string toString() const override
Definition: Analyzer.cpp:3886

+ 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 3575 of file Analyzer.cpp.

References args_.

Referenced by hasSingleDictEncodedColInput().

3577  {
3578  for (const auto& arg : args_) {
3579  arg->collect_column_var(colvar_set, include_agg);
3580  }
3581 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820

+ 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 3515 of file Analyzer.cpp.

References args_.

3515  {
3516  for (const auto& arg : args_) {
3517  arg->collect_rte_idx(rte_idx_set);
3518  }
3519 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
std::shared_ptr< Analyzer::Expr > Analyzer::StringOper::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Reimplemented in Analyzer::HashStringOper, Analyzer::LevenshteinDistanceStringOper, Analyzer::JarowinklerSimilarityStringOper, Analyzer::PositionStringOper, Analyzer::TryStringCastOper, Analyzer::UrlDecodeStringOper, Analyzer::UrlEncodeStringOper, Analyzer::Base64DecodeStringOper, Analyzer::Base64EncodeStringOper, Analyzer::JsonValueStringOper, Analyzer::RegexpCountStringOper, 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 3684 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::RegexpCountStringOper::deep_copy(), Analyzer::JsonValueStringOper::deep_copy(), Analyzer::Base64EncodeStringOper::deep_copy(), Analyzer::Base64DecodeStringOper::deep_copy(), Analyzer::UrlEncodeStringOper::deep_copy(), Analyzer::UrlDecodeStringOper::deep_copy(), Analyzer::TryStringCastOper::deep_copy(), Analyzer::PositionStringOper::deep_copy(), Analyzer::JarowinklerSimilarityStringOper::deep_copy(), Analyzer::LevenshteinDistanceStringOper::deep_copy(), Analyzer::HashStringOper::deep_copy(), and DeepCopyVisitor::visitStringOper().

3684  {
3685  std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3686  for (const auto& arg : args_) {
3687  args_copy.emplace_back(arg->deep_copy());
3688  }
3689  std::vector<std::shared_ptr<Analyzer::Expr>> chained_string_op_exprs_copy;
3690  for (const auto& chained_string_op_expr : chained_string_op_exprs_) {
3691  chained_string_op_exprs_copy.emplace_back(chained_string_op_expr->deep_copy());
3692  }
3693  return makeExpr<Analyzer::StringOper>(kind_,
3694  get_type_info(),
3695  std::move(args_copy),
3696  std::move(chained_string_op_exprs_copy));
3697 }
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1821
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819

+ 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 3338 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), args_, and f().

3339  {
3340  if (f(this)) {
3341  add_unique(expr_list);
3342  return;
3343  }
3344  for (const auto& arg : args_) {
3345  arg->find_expr(f, expr_list);
3346  }
3347 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3248
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)

+ Here is the call graph for this function:

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

Definition at line 1672 of file Analyzer.h.

References kind_.

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

1672 { return kind_; }
SqlStringOpKind kind_
Definition: Analyzer.h:1819

+ 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 4325 of file Analyzer.cpp.

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

4327  {
4329  << "get_return_type for TRY_STRING_CAST disallowed.";
4330  SQLTypeInfo return_ti(kNULLT);
4331  size_t num_var_string_inputs{0};
4332  for (const auto& arg : args) {
4333  const auto raw_arg = arg.get();
4334  const auto& arg_ti = arg->get_type_info();
4335  if (dynamic_cast<const Analyzer::CaseExpr*>(remove_cast(raw_arg))) {
4336  // Currently we disallow case statement inputs to string functions
4337  // pending a full resolution to QE-359, but the error is thrown
4338  // downstream in StringOper::check_operand_types
4339  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4340  } else if (arg_ti.is_string() && dynamic_cast<const Analyzer::Constant*>(raw_arg)) {
4341  if (return_ti == SQLTypeInfo(kNULLT)) {
4342  return_ti = arg_ti;
4343  }
4344  } else if (arg_ti.is_none_encoded_string()) {
4345  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4346  } else if (arg_ti.is_dict_encoded_string()) {
4347  if (arg_ti.getStringDictKey().isTransientDict()) {
4348  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4349  } else {
4350  num_var_string_inputs++;
4351  return_ti = arg_ti;
4352  }
4353  }
4354  }
4355  if (num_var_string_inputs > 1UL) {
4356  return SQLTypeInfo(kTEXT, kENCODING_DICT, 0, kNULLT);
4357  }
4358  return return_ti;
4359 }
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4611
#define CHECK_NE(x, y)
Definition: Logger.h:302
Definition: sqltypes.h:79

+ Here is the call graph for this function:

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

Definition at line 1688 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 TextEncodingCastCountVisitor::visitStringOper().

1688  {
1689  CHECK_LT(i, args_.size());
1690  return args_[i].get();
1691  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
#define CHECK_LT(x, y)
Definition: Logger.h:303

+ Here is the caller graph for this function:

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

Definition at line 1674 of file Analyzer.h.

References args_.

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

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

+ Here is the caller graph for this function:

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

Definition at line 1700 of file Analyzer.h.

References chained_string_op_exprs_.

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

1700  {
1701  return chained_string_op_exprs_;
1702  }
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1821

+ Here is the caller graph for this function:

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

Definition at line 4297 of file Analyzer.cpp.

References args_.

4297  {
4298  std::vector<size_t> literal_arg_indexes;
4299  const auto num_args = args_.size();
4300  for (size_t idx = 0; idx < num_args; ++idx) {
4301  if (dynamic_cast<const Constant*>(args_[idx].get())) {
4302  literal_arg_indexes.emplace_back(idx);
4303  }
4304  }
4305  return literal_arg_indexes;
4306 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
LiteralArgMap Analyzer::StringOper::getLiteralArgs ( ) const

Definition at line 4310 of file Analyzer.cpp.

References getArg(), and getArity().

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

4310  {
4311  LiteralArgMap literal_arg_map;
4312  const auto num_args = getArity();
4313  for (size_t idx = 0; idx < num_args; ++idx) {
4314  const auto constant_arg_expr = dynamic_cast<const Analyzer::Constant*>(getArg(idx));
4315  if (constant_arg_expr) {
4316  literal_arg_map.emplace(
4317  std::make_pair(idx,
4318  std::make_pair(constant_arg_expr->get_type_info().get_type(),
4319  constant_arg_expr->get_constval())));
4320  }
4321  }
4322  return literal_arg_map;
4323 }
std::map< size_t, std::pair< SQLTypes, Datum >> LiteralArgMap
Definition: Analyzer.h:1769
size_t getArity() const
Definition: Analyzer.h:1674
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1688

+ 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 1676 of file Analyzer.h.

References args_.

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

1676  {
1677  size_t num_literals{0UL};
1678  for (const auto& arg : args_) {
1679  if (dynamic_cast<const Constant*>(arg.get())) {
1680  num_literals++;
1681  }
1682  }
1683  return num_literals;
1684  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820

+ Here is the caller graph for this function:

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

Definition at line 1686 of file Analyzer.h.

References getArity(), and getLiteralsArity().

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

1686 { return getArity() - getLiteralsArity(); }
size_t getArity() const
Definition: Analyzer.h:1674
size_t getLiteralsArity() const
Definition: Analyzer.h:1676

+ 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 1693 of file Analyzer.h.

References args_, and CHECK_LT.

1693  {
1694  CHECK_LT(i, args_.size());
1695  return args_[i];
1696  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
#define CHECK_LT(x, y)
Definition: Logger.h:303
std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::StringOper::getOwnArgs ( ) const
inline

Definition at line 1698 of file Analyzer.h.

References args_.

Referenced by ScalarExprVisitor< std::set< shared::TableKey > >::visitStringOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

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

+ 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 1785 of file Analyzer.cpp.

References args_.

1787  {
1788  std::set<int> rte_idx_set;
1789  for (const auto& arg : args_) {
1790  arg->collect_rte_idx(rte_idx_set);
1791  }
1792  if (rte_idx_set.size() > 1) {
1793  join_predicates.push_back(this);
1794  } else if (rte_idx_set.size() == 1) {
1795  scan_predicates.push_back(this);
1796  } else {
1797  const_predicates.push_back(this);
1798  }
1799 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
bool Analyzer::StringOper::hasNoneEncodedTextArg ( ) const
inline

Definition at line 1743 of file Analyzer.h.

References args_, and CHECK.

Referenced by TextEncodingCastCountVisitor::visitStringOper().

1743  {
1744  if (args_.empty()) {
1745  return false;
1746  }
1747  const auto& arg0_ti = args_[0]->get_type_info();
1748  if (!arg0_ti.is_string()) {
1749  return false;
1750  }
1751  if (arg0_ti.is_none_encoded_string()) {
1752  return true;
1753  }
1754  CHECK(arg0_ti.is_dict_encoded_string());
1755  return arg0_ti.getStringDictKey().isTransientDict();
1756  }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
#define CHECK(condition)
Definition: Logger.h:291

+ 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 4283 of file Analyzer.cpp.

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

4283  {
4284  auto comparator = Analyzer::ColumnVar::colvar_comp;
4285  std::set<const Analyzer::ColumnVar*,
4286  bool (*)(const Analyzer::ColumnVar*, const Analyzer::ColumnVar*)>
4287  colvar_set(comparator);
4288  collect_column_var(colvar_set, true);
4289  if (colvar_set.size() != 1UL) {
4290  return false;
4291  }
4292  auto col_expr_ptr = *colvar_set.begin();
4293  CHECK(col_expr_ptr);
4294  return col_expr_ptr->get_type_info().is_dict_encoded_string();
4295 }
static bool colvar_comp(const ColumnVar *l, const ColumnVar *r)
Definition: Analyzer.h:215
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3575
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 3832 of file Analyzer.cpp.

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

3832  {
3833  const auto rhs_string_oper = dynamic_cast<const StringOper*>(&rhs);
3834 
3835  if (!rhs_string_oper) {
3836  return false;
3837  }
3838 
3839  if (get_kind() != rhs_string_oper->get_kind()) {
3840  return false;
3841  }
3842  if (getArity() != rhs_string_oper->getArity()) {
3843  return false;
3844  }
3845 
3846  for (size_t i = 0; i < getArity(); ++i) {
3847  if (!(*getArg(i) == *(rhs_string_oper->getArg(i)))) {
3848  return false;
3849  }
3850  }
3851  if (chained_string_op_exprs_.size() !=
3852  rhs_string_oper->chained_string_op_exprs_.size()) {
3853  return false;
3854  }
3855  for (size_t i = 0; i < chained_string_op_exprs_.size(); ++i) {
3856  if (!(*(chained_string_op_exprs_[i]) ==
3857  *(rhs_string_oper->chained_string_op_exprs_[i]))) {
3858  return false;
3859  }
3860  }
3861  return true;
3862 }
size_t getArity() const
Definition: Analyzer.h:1674
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1821
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1607
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1672
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1688

+ Here is the call graph for this function:

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

Definition at line 1704 of file Analyzer.h.

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

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

1704  {
1705  const auto& return_ti = get_type_info();
1706  if (return_ti.is_none_encoded_string() ||
1707  (return_ti.is_dict_encoded_string() &&
1708  return_ti.getStringDictKey().isTransientDict())) {
1709  return true;
1710  }
1711 
1712  // Anything that returns the transient dictionary by definition
1713  // (see StringOper::get_return_type) requires per-row translation,
1714  // but there is also a path with string->numeric functions (the output is
1715  // not a string) where we need to see if any of the inputs are none-encoded
1716  // or transient dictionary encoded, in which case we also need to do per-row
1717  // translation. The handling of that condition follows below.
1718 
1719  size_t num_var_str_args{0};
1720  for (const auto& arg : args_) {
1721  const auto arg_is_const = dynamic_cast<const Analyzer::Constant*>(arg.get());
1722  if (arg_is_const) {
1723  continue;
1724  }
1725  const auto& arg_ti = arg->get_type_info();
1726  if (arg_ti.is_none_encoded_string() ||
1727  (arg_ti.is_dict_encoded_string() &&
1728  arg_ti.getStringDictKey().isTransientDict())) {
1729  return true;
1730  }
1731  num_var_str_args++;
1732  }
1733  return num_var_str_args > 1UL;
1734  }
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820

+ 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 2058 of file Analyzer.cpp.

References args_, and kind_.

2059  {
2060  std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
2061  for (const auto& arg : args_) {
2062  rewritten_args.emplace_back(arg->rewrite_agg_to_var(tlist));
2063  }
2064  return makeExpr<StringOper>(kind_, rewritten_args);
2065 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
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 2049 of file Analyzer.cpp.

References args_, and kind_.

2050  {
2051  std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
2052  for (const auto& arg : args_) {
2053  rewritten_args.emplace_back(arg->rewrite_with_child_targetlist(tlist));
2054  }
2055  return makeExpr<StringOper>(kind_, rewritten_args);
2056 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
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 2040 of file Analyzer.cpp.

References args_, and kind_.

2041  {
2042  std::vector<std::shared_ptr<Analyzer::Expr>> rewritten_args;
2043  for (const auto& arg : args_) {
2044  rewritten_args.emplace_back(arg->rewrite_with_targetlist(tlist));
2045  }
2046  return makeExpr<StringOper>(kind_, rewritten_args);
2047 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
std::string Analyzer::StringOper::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 3886 of file Analyzer.cpp.

References args_, and kind_.

Referenced by check_operand_types().

3886  {
3887  std::string str{"(" + ::toString(kind_) + " "};
3888  for (const auto& arg : args_) {
3889  str += arg->toString();
3890  }
3891  str += ")";
3892  return str;
3893 }
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1820
SqlStringOpKind kind_
Definition: Analyzer.h:1819
std::string toString() const override
Definition: Analyzer.cpp:3886

+ 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 1821 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: