OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransientStringLiteralsVisitor Class Reference

#include <TransientStringLiteralsVisitor.h>

+ Inheritance diagram for TransientStringLiteralsVisitor:
+ Collaboration diagram for TransientStringLiteralsVisitor:

Public Member Functions

 TransientStringLiteralsVisitor (StringDictionaryProxy *sdp, Executor *executor)
 
void * visitConstant (const Analyzer::Constant *constant) const override
 
void * visitUOper (const Analyzer::UOper *uoper) const override
 
void * visitStringOper (const Analyzer::StringOper *string_oper) const override
 
- Public Member Functions inherited from ScalarExprVisitor< void * >
void * visit (const Analyzer::Expr *expr) const
 

Protected Member Functions

void * defaultResult () const override
 
- Protected Member Functions inherited from ScalarExprVisitor< void * >
virtual void * visitVar (const Analyzer::Var *) const
 
virtual void * visitColumnVar (const Analyzer::ColumnVar *) const
 
virtual void * visitColumnVarTuple (const Analyzer::ExpressionTuple *) const
 
virtual void * visitBinOper (const Analyzer::BinOper *bin_oper) const
 
virtual void * visitGeoExpr (const Analyzer::GeoExpr *geo_expr) const
 
virtual void * visitInValues (const Analyzer::InValues *in_values) const
 
virtual void * visitInIntegerSet (const Analyzer::InIntegerSet *in_integer_set) const
 
virtual void * visitCharLength (const Analyzer::CharLengthExpr *char_length) const
 
virtual void * visitKeyForString (const Analyzer::KeyForStringExpr *key_for_string) const
 
virtual void * visitSampleRatio (const Analyzer::SampleRatioExpr *sample_ratio) const
 
virtual void * visitCardinality (const Analyzer::CardinalityExpr *cardinality) const
 
virtual void * visitLikeExpr (const Analyzer::LikeExpr *like) const
 
virtual void * visitRegexpExpr (const Analyzer::RegexpExpr *regexp) const
 
virtual void * visitWidthBucket (const Analyzer::WidthBucketExpr *width_bucket_expr) const
 
virtual void * visitCaseExpr (const Analyzer::CaseExpr *case_) const
 
virtual void * visitDatetruncExpr (const Analyzer::DatetruncExpr *datetrunc) const
 
virtual void * visitExtractExpr (const Analyzer::ExtractExpr *extract) const
 
virtual void * visitFunctionOperWithCustomTypeHandling (const Analyzer::FunctionOperWithCustomTypeHandling *func_oper) const
 
virtual void * visitArrayOper (Analyzer::ArrayExpr const *array_expr) const
 
virtual void * visitGeoUOper (const Analyzer::GeoUOper *geo_expr) const
 
virtual void * visitGeoBinOper (const Analyzer::GeoBinOper *geo_expr) const
 
virtual void * visitFunctionOper (const Analyzer::FunctionOper *func_oper) const
 
virtual void * visitWindowFunction (const Analyzer::WindowFunction *window_func) const
 
virtual void * visitDatediffExpr (const Analyzer::DatediffExpr *datediff) const
 
virtual void * visitDateaddExpr (const Analyzer::DateaddExpr *dateadd) const
 
virtual void * visitLikelihood (const Analyzer::LikelihoodExpr *likelihood) const
 
virtual void * visitOffsetInFragment (const Analyzer::OffsetInFragment *) const
 
virtual void * visitAggExpr (const Analyzer::AggExpr *agg) const
 
virtual void * visitRangeJoinOper (const Analyzer::RangeOper *range_oper) const
 
virtual void * aggregateResult (const void *&aggregate, const void *&next_result) const
 
virtual void visitBegin () const
 

Private Attributes

StringDictionaryProxysdp_
 
Executorexecutor_
 
bool parent_feeds_sdp_ {false}
 

Detailed Description

Definition at line 23 of file TransientStringLiteralsVisitor.h.

Constructor & Destructor Documentation

TransientStringLiteralsVisitor::TransientStringLiteralsVisitor ( StringDictionaryProxy sdp,
Executor executor 
)
inline

Definition at line 25 of file TransientStringLiteralsVisitor.h.

References CHECK.

26  : sdp_(sdp), executor_(executor) {
27  CHECK(sdp);
28  }
#define CHECK(condition)
Definition: Logger.h:222

Member Function Documentation

void* TransientStringLiteralsVisitor::defaultResult ( ) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< void * >.

Definition at line 151 of file TransientStringLiteralsVisitor.h.

Referenced by visitConstant(), visitStringOper(), and visitUOper().

151 { return nullptr; }

+ Here is the caller graph for this function:

void* TransientStringLiteralsVisitor::visitConstant ( const Analyzer::Constant constant) const
inlineoverridevirtual

Reimplemented from ScalarExprVisitor< void * >.

Definition at line 30 of file TransientStringLiteralsVisitor.h.

References CHECK, defaultResult(), Analyzer::Constant::get_constval(), Analyzer::Constant::get_is_null(), Analyzer::Expr::get_type_info(), StringDictionaryProxy::getOrAddTransient(), SQLTypeInfo::is_string(), sdp_, and Datum::stringval.

30  {
31  if (constant->get_type_info().is_string() && !constant->get_is_null()) {
32  CHECK(constant->get_constval().stringval);
34  }
35  return defaultResult();
36  }
bool get_is_null() const
Definition: Analyzer.h:341
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81
std::string * stringval
Definition: sqltypes.h:220
Datum get_constval() const
Definition: Analyzer.h:342
#define CHECK(condition)
Definition: Logger.h:222
int32_t getOrAddTransient(const std::string &str)
bool is_string() const
Definition: sqltypes.h:510

+ Here is the call graph for this function:

void* TransientStringLiteralsVisitor::visitStringOper ( const Analyzer::StringOper string_oper) const
inlineoverridevirtual

Reimplemented from ScalarExprVisitor< void * >.

Definition at line 88 of file TransientStringLiteralsVisitor.h.

References StringOps_Namespace::apply_string_op_to_literals(), CHECK, CHECK_EQ, CHECK_GE, defaultResult(), executor_, Analyzer::StringOper::get_kind(), Analyzer::Expr::get_type_info(), Analyzer::StringOper::getArg(), Analyzer::StringOper::getArity(), Analyzer::StringOper::getChainedStringOpExprs(), StringDictionaryProxy::getDictId(), Analyzer::StringOper::getLiteralArgs(), Analyzer::StringOper::getLiteralsArity(), StringDictionaryProxy::getOrAddTransient(), Executor::getRowSetMemoryOwner(), Executor::getStringProxyTranslationMap(), parent_feeds_sdp_, sdp_, RowSetMemoryOwner::SOURCE_UNION, and ScalarExprVisitor< void * >::visit().

88  {
89  CHECK_GE(string_oper->getArity(), 1UL);
90  const auto str_operand = string_oper->getArg(0);
91  const auto& string_oper_ti = string_oper->get_type_info();
92  const auto& str_operand_ti = str_operand->get_type_info();
93  const auto string_oper_kind = string_oper->get_kind();
94  if (!string_oper_ti.is_string() || !str_operand_ti.is_string()) {
95  return defaultResult();
96  }
97  const bool parent_feeds_sdp_already_set = parent_feeds_sdp_;
98  const bool outputs_target_sdp = string_oper_ti.get_comp_param() == sdp_->getDictId();
99  if (string_oper_ti.is_dict_encoded_string() &&
100  str_operand_ti.is_dict_encoded_string() &&
101  (parent_feeds_sdp_ || outputs_target_sdp)) {
102  parent_feeds_sdp_ = true;
103  visit(str_operand);
104  if (!parent_feeds_sdp_already_set) {
105  parent_feeds_sdp_ = false;
106  }
107  // Todo(todd): Dedup the code to get string_op_infos from the same
108  // in StringOpsIR.cpp (needs thought as Analyzer and StringOps
109  // deliberately are oblivious to each other)
110 
111  std::vector<StringOps_Namespace::StringOpInfo> string_op_infos;
112  const auto chained_string_op_exprs = string_oper->getChainedStringOpExprs();
113  for (const auto& chained_string_op_expr : chained_string_op_exprs) {
114  auto chained_string_op =
115  dynamic_cast<const Analyzer::StringOper*>(chained_string_op_expr.get());
116  CHECK(chained_string_op);
117  StringOps_Namespace::StringOpInfo string_op_info(
118  chained_string_op->get_kind(), chained_string_op->getLiteralArgs());
119  string_op_infos.emplace_back(string_op_info);
120  }
121 
123  str_operand_ti.get_comp_param(),
124  string_oper_ti.get_comp_param(),
126  string_op_infos,
128  true); // with_generation
129  } else if ((parent_feeds_sdp_ || outputs_target_sdp) &&
130  (string_oper->getLiteralsArity() == string_oper->getArity())) {
131  // This is likely dead code due to ExpressionRewrite of all-literal string ops
132  // (meaning when this visitor gets to a string op with all literal args it
133  // (would have already been rewritten as a literal string)
134  // Todo(todd): Verify and remove if so
135  const StringOps_Namespace::StringOpInfo string_op_info(
136  string_oper_kind, string_oper->getLiteralArgs());
137  CHECK_EQ(string_op_info.numLiterals(), string_oper->getArity());
138  const auto str_result_and_null_status =
140  if (!str_result_and_null_status.second &&
141  !str_result_and_null_status.first
142  .empty()) { // Todo(todd): Is there a central/non-magic function/constant
143  // to determine if a none-encoded string is null
144  sdp_->getOrAddTransient(str_result_and_null_status.first);
145  }
146  }
147  return defaultResult();
148  }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const std::shared_ptr< RowSetMemoryOwner > getRowSetMemoryOwner() const
Definition: Execute.cpp:651
#define CHECK_GE(x, y)
Definition: Logger.h:235
size_t getArity() const
Definition: Analyzer.h:1506
void * visit(const Analyzer::Expr *expr) const
size_t getLiteralsArity() const
Definition: Analyzer.h:1508
const StringDictionaryProxy::IdMap * getStringProxyTranslationMap(const int source_dict_id, const int dest_dict_id, const RowSetMemoryOwner::StringTranslationType translation_type, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const bool with_generation) const
Definition: Execute.cpp:558
LiteralArgMap getLiteralArgs() const
Definition: Analyzer.cpp:3960
std::pair< std::string, bool > apply_string_op_to_literals(const StringOpInfo &string_op_info)
Definition: StringOps.cpp:617
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1463
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1504
int32_t getDictId() const noexcept
#define CHECK(condition)
Definition: Logger.h:222
int32_t getOrAddTransient(const std::string &str)
std::vector< std::shared_ptr< Analyzer::Expr > > getChainedStringOpExprs() const
Definition: Analyzer.h:1530
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1518

+ Here is the call graph for this function:

void* TransientStringLiteralsVisitor::visitUOper ( const Analyzer::UOper uoper) const
inlineoverridevirtual

Reimplemented from ScalarExprVisitor< void * >.

Definition at line 49 of file TransientStringLiteralsVisitor.h.

References defaultResult(), executor_, Analyzer::UOper::get_operand(), Analyzer::UOper::get_optype(), Analyzer::Expr::get_type_info(), StringDictionaryProxy::getDictId(), Executor::getRowSetMemoryOwner(), Executor::getStringProxyTranslationMap(), kCAST, parent_feeds_sdp_, sdp_, RowSetMemoryOwner::SOURCE_UNION, and ScalarExprVisitor< void * >::visit().

49  {
50  const auto& uoper_ti = uoper->get_type_info();
51  const auto& operand_ti = uoper->get_operand()->get_type_info();
52  if (!(uoper->get_optype() == kCAST && uoper_ti.is_dict_encoded_string())) {
53  return defaultResult();
54  }
55  const bool outputs_target_sdp = uoper_ti.get_comp_param() == sdp_->getDictId();
56 
57  if (!parent_feeds_sdp_ && !outputs_target_sdp) {
58  // If we are not casting to our dictionary (sdp_)
59  return defaultResult();
60  }
61  if (uoper_ti.is_dict_intersection()) {
62  // Intersection translations don't add transients to the dest proxy,
63  // and hence can be ignored for the purposes of populating transients
64  return defaultResult();
65  }
66  const bool parent_feeds_sdp_already_set = parent_feeds_sdp_;
67  parent_feeds_sdp_ = true;
68 
69  visit(uoper->get_operand());
70 
71  if (!parent_feeds_sdp_already_set) {
72  parent_feeds_sdp_ = false;
73  }
74 
75  if (operand_ti.is_dict_encoded_string() &&
76  uoper_ti.get_comp_param() != operand_ti.get_comp_param()) {
78  operand_ti.get_comp_param(),
79  uoper_ti.get_comp_param(),
81  {},
83  true); // with_generation
84  }
85  return defaultResult();
86  }
const std::shared_ptr< RowSetMemoryOwner > getRowSetMemoryOwner() const
Definition: Execute.cpp:651
Definition: sqldefs.h:48
void * visit(const Analyzer::Expr *expr) const
const StringDictionaryProxy::IdMap * getStringProxyTranslationMap(const int source_dict_id, const int dest_dict_id, const RowSetMemoryOwner::StringTranslationType translation_type, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const bool with_generation) const
Definition: Execute.cpp:558
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81
const Expr * get_operand() const
Definition: Analyzer.h:378
int32_t getDictId() const noexcept
SQLOps get_optype() const
Definition: Analyzer.h:377

+ Here is the call graph for this function:

Member Data Documentation

Executor* TransientStringLiteralsVisitor::executor_
mutableprivate

Definition at line 155 of file TransientStringLiteralsVisitor.h.

Referenced by visitStringOper(), and visitUOper().

bool TransientStringLiteralsVisitor::parent_feeds_sdp_ {false}
mutableprivate

Definition at line 156 of file TransientStringLiteralsVisitor.h.

Referenced by visitStringOper(), and visitUOper().

StringDictionaryProxy* TransientStringLiteralsVisitor::sdp_
mutableprivate

Definition at line 154 of file TransientStringLiteralsVisitor.h.

Referenced by visitConstant(), visitStringOper(), and visitUOper().


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