OmniSciDB  c1a53651b2
 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 24 of file TransientStringLiteralsVisitor.h.

Constructor & Destructor Documentation

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

Definition at line 26 of file TransientStringLiteralsVisitor.h.

References CHECK.

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

Member Function Documentation

void* TransientStringLiteralsVisitor::defaultResult ( ) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< void * >.

Definition at line 159 of file TransientStringLiteralsVisitor.h.

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

159 { 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 31 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.

31  {
32  if (constant->get_type_info().is_string() && !constant->get_is_null()) {
33  CHECK(constant->get_constval().stringval);
35  }
36  return defaultResult();
37  }
bool get_is_null() const
Definition: Analyzer.h:347
int32_t getOrAddTransient(const std::string &)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
std::string * stringval
Definition: Datum.h:77
Datum get_constval() const
Definition: Analyzer.h:348
#define CHECK(condition)
Definition: Logger.h:291
bool is_string() const
Definition: sqltypes.h:580

+ 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 89 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::getDictKey(), Analyzer::StringOper::getLiteralArgs(), Analyzer::StringOper::getLiteralsArity(), Analyzer::StringOper::getNonLiteralsArity(), StringDictionaryProxy::getOrAddTransient(), Executor::getRowSetMemoryOwner(), Executor::getStringProxyTranslationMap(), SQLTypeInfo::is_string(), parent_feeds_sdp_, sdp_, RowSetMemoryOwner::SOURCE_UNION, and ScalarExprVisitor< void * >::visit().

89  {
90  CHECK_GE(string_oper->getArity(), 1UL);
91  const auto str_operand = string_oper->getArg(0);
92  const auto& string_oper_ti = string_oper->get_type_info();
93  const auto& str_operand_ti = str_operand->get_type_info();
94  const auto string_oper_kind = string_oper->get_kind();
95  if (!string_oper_ti.is_string() || !str_operand_ti.is_string()) {
96  return defaultResult();
97  }
98  if (string_oper->getNonLiteralsArity() >= 2UL) {
99  return defaultResult();
100  }
101  const bool parent_feeds_sdp_already_set = parent_feeds_sdp_;
102  const bool outputs_target_sdp =
103  string_oper_ti.getStringDictKey() == sdp_->getDictKey();
104  if (string_oper_ti.is_dict_encoded_string() &&
105  str_operand_ti.is_dict_encoded_string() &&
106  (parent_feeds_sdp_ || outputs_target_sdp)) {
107  parent_feeds_sdp_ = true;
108  visit(str_operand);
109  if (!parent_feeds_sdp_already_set) {
110  parent_feeds_sdp_ = false;
111  }
112  // Todo(todd): Dedup the code to get string_op_infos from the same
113  // in StringOpsIR.cpp (needs thought as Analyzer and StringOps
114  // deliberately are oblivious to each other)
115 
116  std::vector<StringOps_Namespace::StringOpInfo> string_op_infos;
117  const auto chained_string_op_exprs = string_oper->getChainedStringOpExprs();
118  for (const auto& chained_string_op_expr : chained_string_op_exprs) {
119  auto chained_string_op =
120  dynamic_cast<const Analyzer::StringOper*>(chained_string_op_expr.get());
121  CHECK(chained_string_op);
122  StringOps_Namespace::StringOpInfo string_op_info(
123  chained_string_op->get_kind(),
124  chained_string_op->get_type_info(),
125  chained_string_op->getLiteralArgs());
126  string_op_infos.emplace_back(string_op_info);
127  }
128 
130  str_operand_ti.getStringDictKey(),
131  string_oper_ti.getStringDictKey(),
133  string_op_infos,
135  true); // with_generation
136  } else if ((parent_feeds_sdp_ || outputs_target_sdp) &&
137  (string_oper->getLiteralsArity() == string_oper->getArity())) {
138  // This is likely dead code due to ExpressionRewrite of all-literal string ops
139  // (meaning when this visitor gets to a string op with all literal args it
140  // (would have already been rewritten as a literal string)
141  // Todo(todd): Verify and remove if so
142  const StringOps_Namespace::StringOpInfo string_op_info(
143  string_oper_kind, string_oper->get_type_info(), string_oper->getLiteralArgs());
144  CHECK_EQ(string_op_info.numLiterals(), string_oper->getArity());
145  const auto str_result_and_null_status =
147  if (string_oper->get_type_info().is_string() &&
148  !str_result_and_null_status.second &&
149  !str_result_and_null_status.first
150  .empty()) { // Todo(todd): Is there a central/non-magic function/constant
151  // to determine if a none-encoded string is null
152  sdp_->getOrAddTransient(str_result_and_null_status.first);
153  }
154  }
155  return defaultResult();
156  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const std::shared_ptr< RowSetMemoryOwner > getRowSetMemoryOwner() const
Definition: Execute.cpp:668
#define CHECK_GE(x, y)
Definition: Logger.h:306
const StringDictionaryProxy::IdMap * getStringProxyTranslationMap(const shared::StringDictKey &source_dict_key, const shared::StringDictKey &dest_dict_key, 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:567
size_t getArity() const
Definition: Analyzer.h:1548
void * visit(const Analyzer::Expr *expr) const
size_t getLiteralsArity() const
Definition: Analyzer.h:1550
LiteralArgMap getLiteralArgs() const
Definition: Analyzer.cpp:4077
std::pair< std::string, bool > apply_string_op_to_literals(const StringOpInfo &string_op_info)
Definition: StringOps.cpp:905
int32_t getOrAddTransient(const std::string &)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1479
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1546
#define CHECK(condition)
Definition: Logger.h:291
bool is_string() const
Definition: sqltypes.h:580
const shared::StringDictKey & getDictKey() const noexcept
size_t getNonLiteralsArity() const
Definition: Analyzer.h:1560
std::vector< std::shared_ptr< Analyzer::Expr > > getChainedStringOpExprs() const
Definition: Analyzer.h:1574
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1562

+ Here is the call graph for this function:

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

Reimplemented from ScalarExprVisitor< void * >.

Definition at line 50 of file TransientStringLiteralsVisitor.h.

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

50  {
51  const auto& uoper_ti = uoper->get_type_info();
52  const auto& operand_ti = uoper->get_operand()->get_type_info();
53  if (!(uoper->get_optype() == kCAST && uoper_ti.is_dict_encoded_string())) {
54  return defaultResult();
55  }
56  const bool outputs_target_sdp = uoper_ti.getStringDictKey() == sdp_->getDictKey();
57 
58  if (!parent_feeds_sdp_ && !outputs_target_sdp) {
59  // If we are not casting to our dictionary (sdp_)
60  return defaultResult();
61  }
62  if (uoper_ti.is_dict_intersection()) {
63  // Intersection translations don't add transients to the dest proxy,
64  // and hence can be ignored for the purposes of populating transients
65  return defaultResult();
66  }
67  const bool parent_feeds_sdp_already_set = parent_feeds_sdp_;
68  parent_feeds_sdp_ = true;
69 
70  visit(uoper->get_operand());
71 
72  if (!parent_feeds_sdp_already_set) {
73  parent_feeds_sdp_ = false;
74  }
75 
76  if (operand_ti.is_dict_encoded_string() &&
77  uoper_ti.getStringDictKey() != operand_ti.getStringDictKey()) {
79  operand_ti.getStringDictKey(),
80  uoper_ti.getStringDictKey(),
82  {},
84  true); // with_generation
85  }
86  return defaultResult();
87  }
const std::shared_ptr< RowSetMemoryOwner > getRowSetMemoryOwner() const
Definition: Execute.cpp:668
Definition: sqldefs.h:48
const StringDictionaryProxy::IdMap * getStringProxyTranslationMap(const shared::StringDictKey &source_dict_key, const shared::StringDictKey &dest_dict_key, 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:567
void * visit(const Analyzer::Expr *expr) const
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
const Expr * get_operand() const
Definition: Analyzer.h:384
const shared::StringDictKey & getDictKey() const noexcept
SQLOps get_optype() const
Definition: Analyzer.h:383

+ Here is the call graph for this function:

Member Data Documentation

Executor* TransientStringLiteralsVisitor::executor_
mutableprivate

Definition at line 163 of file TransientStringLiteralsVisitor.h.

Referenced by visitStringOper(), and visitUOper().

bool TransientStringLiteralsVisitor::parent_feeds_sdp_ {false}
mutableprivate

Definition at line 164 of file TransientStringLiteralsVisitor.h.

Referenced by visitStringOper(), and visitUOper().

StringDictionaryProxy* TransientStringLiteralsVisitor::sdp_
mutableprivate

Definition at line 162 of file TransientStringLiteralsVisitor.h.

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


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