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

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::TrimStringOper:
+ Collaboration diagram for Analyzer::TrimStringOper:

Public Member Functions

 TrimStringOper (const SqlStringOpKind trim_op_kind, const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &trim_chars)
 
 getMinArgs ()
 
 getExpectedTypeFamilies ()
 
 getArgNames ())
 
 TrimStringOper (const SqlStringOpKind trim_op_kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
 
 TrimStringOper (const std::shared_ptr< Analyzer::StringOper > &string_oper)
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
size_t getMinArgs () const override
 
std::vector< OperandTypeFamilygetExpectedTypeFamilies () const override
 
std::vector< std::string > getArgNames () const override
 
- Public Member Functions inherited from Analyzer::StringOper
 StringOper (const SqlStringOpKind kind, 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 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
 
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
 
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
 
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 (bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
 
- 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
 

Static Private Member Functions

static SqlStringOpKind validate_trim_op_kind (const SqlStringOpKind trim_op_kind)
 
static SqlStringOpKind get_and_validate_trim_op_kind (const SqlStringOpKind trim_op_kind_maybe, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
 
static std::vector
< std::shared_ptr
< Analyzer::Expr > > 
normalize_operands (const std::vector< std::shared_ptr< Analyzer::Expr >> &operands, const SqlStringOpKind string_op_kind)
 

Additional Inherited Members

- Public Types inherited from Analyzer::StringOper
enum  OperandTypeFamily { OperandTypeFamily::STRING_FAMILY, OperandTypeFamily::INT_FAMILY }
 
using LiteralArgMap = std::map< size_t, std::pair< SQLTypes, Datum >>
 
- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 1851 of file Analyzer.h.

Constructor & Destructor Documentation

Analyzer::TrimStringOper::TrimStringOper ( const SqlStringOpKind  trim_op_kind,
const std::shared_ptr< Analyzer::Expr > &  operand,
const std::shared_ptr< Analyzer::Expr > &  trim_chars 
)
inline

Definition at line 1853 of file Analyzer.h.

1857  {operand, trim_chars},
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1470
static SqlStringOpKind validate_trim_op_kind(const SqlStringOpKind trim_op_kind)
Definition: Analyzer.h:1885
Analyzer::TrimStringOper::TrimStringOper ( const SqlStringOpKind  trim_op_kind,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  operands 
)
inline

Definition at line 1862 of file Analyzer.h.

1865  TrimStringOper::normalize_operands(operands, trim_op_kind),
1866  getMinArgs(),
1868  getArgNames()) {}
static SqlStringOpKind get_and_validate_trim_op_kind(const SqlStringOpKind trim_op_kind_maybe, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.cpp:4172
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1470
static std::vector< std::shared_ptr< Analyzer::Expr > > normalize_operands(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands, const SqlStringOpKind string_op_kind)
Definition: Analyzer.cpp:4203
Analyzer::TrimStringOper::TrimStringOper ( const std::shared_ptr< Analyzer::StringOper > &  string_oper)
inline

Definition at line 1870 of file Analyzer.h.

1871  : StringOper(string_oper) {}
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1470

Member Function Documentation

std::shared_ptr< Analyzer::Expr > Analyzer::TrimStringOper::deep_copy ( ) const
overridevirtual

Reimplemented from Analyzer::StringOper.

Definition at line 3516 of file Analyzer.cpp.

References Analyzer::StringOper::deep_copy().

3516  {
3517  return makeExpr<Analyzer::TrimStringOper>(
3518  std::dynamic_pointer_cast<Analyzer::StringOper>(StringOper::deep_copy()));
3519 }
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3473
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1464

+ Here is the call graph for this function:

SqlStringOpKind Analyzer::TrimStringOper::get_and_validate_trim_op_kind ( const SqlStringOpKind  trim_op_kind_maybe,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args 
)
staticprivate

Definition at line 4172 of file Analyzer.cpp.

References run_benchmark_import::args, INVALID, LTRIM, RTRIM, to_upper(), TRIM, and validate_trim_op_kind().

4174  {
4175  auto get_trim_type_if_exists = [&args]() {
4176  if (args.empty()) {
4177  return SqlStringOpKind::INVALID;
4178  }
4179  const auto trim_type_arg = dynamic_cast<const Analyzer::Constant*>(args[0].get());
4180  if (!trim_type_arg) {
4181  return SqlStringOpKind::INVALID;
4182  }
4183  const auto trim_type_str = to_upper(*trim_type_arg->get_constval().stringval);
4184  if (trim_type_str == "BOTH") {
4185  return SqlStringOpKind::TRIM;
4186  }
4187  if (trim_type_str == "LEADING") {
4188  return SqlStringOpKind::LTRIM;
4189  }
4190  if (trim_type_str == "TRAILING") {
4191  return SqlStringOpKind::RTRIM;
4192  }
4193  return SqlStringOpKind::INVALID;
4194  };
4195 
4196  const auto trim_op_kind = trim_op_kind_maybe == SqlStringOpKind::TRIM
4197  ? get_trim_type_if_exists()
4198  : trim_op_kind_maybe;
4200  return trim_op_kind;
4201 }
static SqlStringOpKind validate_trim_op_kind(const SqlStringOpKind trim_op_kind)
Definition: Analyzer.h:1885
std::string to_upper(const std::string &str)

+ Here is the call graph for this function:

Analyzer::TrimStringOper::getArgNames ( )
inline

Definition at line 1860 of file Analyzer.h.

1860 {}
std::vector<std::string> Analyzer::TrimStringOper::getArgNames ( ) const
inlineoverridevirtual

Reimplemented from Analyzer::StringOper.

Definition at line 1880 of file Analyzer.h.

1880  {
1881  return {"operand", "trim_chars"};
1882  }
Analyzer::TrimStringOper::getExpectedTypeFamilies ( )
std::vector<OperandTypeFamily> Analyzer::TrimStringOper::getExpectedTypeFamilies ( ) const
inlineoverridevirtual
Analyzer::TrimStringOper::getMinArgs ( )
size_t Analyzer::TrimStringOper::getMinArgs ( ) const
inlineoverridevirtual

Reimplemented from Analyzer::StringOper.

Definition at line 1875 of file Analyzer.h.

1875 { return 2UL; }
std::vector< std::shared_ptr< Analyzer::Expr > > Analyzer::TrimStringOper::normalize_operands ( const std::vector< std::shared_ptr< Analyzer::Expr >> &  operands,
const SqlStringOpKind  string_op_kind 
)
staticprivate

Definition at line 4203 of file Analyzer.cpp.

References CHECK_EQ, LTRIM, and RTRIM.

4205  {
4206  if (operands.size() < 2UL) {
4207  throw std::runtime_error("Trim operator expects 2 arguments.");
4208  }
4209 
4210  // Calcite is returning LTRIM/RTRIM(string_literal1, string_literal2) with the
4211  // arguments in that order, but LTRIM/TRIM(string_var, string_literal) in the
4212  // reverse order that the main TRIM operator uses as well
4213  // Until we can look into that more, reverse order only if we have a const then
4214  // non-const input order
4215 
4216  if (string_op_kind == SqlStringOpKind::LTRIM ||
4217  string_op_kind == SqlStringOpKind::RTRIM) {
4218  CHECK_EQ(operands.size(), 2UL);
4219  if (dynamic_cast<const Analyzer::Constant*>(operands[0].get()) &&
4220  !dynamic_cast<const Analyzer::Constant*>(operands[1].get())) {
4221  return {operands[1], operands[0]};
4222  }
4223  return operands;
4224  }
4225  CHECK_EQ(operands.size(), 3UL);
4226  return {operands[2], operands[1]};
4227 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
static SqlStringOpKind Analyzer::TrimStringOper::validate_trim_op_kind ( const SqlStringOpKind  trim_op_kind)
inlinestaticprivate

Definition at line 1885 of file Analyzer.h.

References LTRIM, RTRIM, and TRIM.

Referenced by get_and_validate_trim_op_kind().

1885  {
1886  if (!(trim_op_kind == SqlStringOpKind::TRIM ||
1887  trim_op_kind == SqlStringOpKind::LTRIM ||
1888  trim_op_kind == SqlStringOpKind::RTRIM)) {
1889  // Arguably should CHECK here
1890  throw std::runtime_error("Invalid trim type supplied to TRIM operator");
1891  }
1892  return trim_op_kind;
1893  }

+ Here is the caller graph for this function:


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