OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TextEncodingCastCountVisitor Class Reference
+ Inheritance diagram for TextEncodingCastCountVisitor:
+ Collaboration diagram for TextEncodingCastCountVisitor:

Public Member Functions

 TextEncodingCastCountVisitor (const bool default_disregard_casts_to_none_encoding)
 
- Public Member Functions inherited from ScalarExprVisitor< TextEncodingCastCounts >
TextEncodingCastCounts visit (const Analyzer::Expr *expr) const
 

Protected Member Functions

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

Private Attributes

bool disregard_casts_to_none_encoding_ = false
 
const bool default_disregard_casts_to_none_encoding_
 

Detailed Description

Definition at line 270 of file RelAlgExecutor.cpp.

Constructor & Destructor Documentation

TextEncodingCastCountVisitor::TextEncodingCastCountVisitor ( const bool  default_disregard_casts_to_none_encoding)
inline

Definition at line 272 of file RelAlgExecutor.cpp.

274  default_disregard_casts_to_none_encoding) {}
const bool default_disregard_casts_to_none_encoding_

Member Function Documentation

TextEncodingCastCounts TextEncodingCastCountVisitor::aggregateResult ( const TextEncodingCastCounts aggregate,
const TextEncodingCastCounts next_result 
) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< TextEncodingCastCounts >.

Definition at line 384 of file RelAlgExecutor.cpp.

References run_benchmark_import::result, TextEncodingCastCounts::text_decoding_casts, and TextEncodingCastCounts::text_encoding_casts.

Referenced by visitBinOper(), visitLikeExpr(), visitStringOper(), and visitUOper().

386  {
387  auto result = aggregate;
388  result.text_decoding_casts += next_result.text_decoding_casts;
389  result.text_encoding_casts += next_result.text_encoding_casts;
390  return result;
391  }

+ Here is the caller graph for this function:

TextEncodingCastCounts TextEncodingCastCountVisitor::defaultResult ( ) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< TextEncodingCastCounts >.

Definition at line 397 of file RelAlgExecutor.cpp.

Referenced by visitBinOper(), visitLikeExpr(), visitStringOper(), and visitUOper().

397  {
398  return TextEncodingCastCounts();
399  }

+ Here is the caller graph for this function:

void TextEncodingCastCountVisitor::visitBegin ( ) const
inlineoverrideprotectedvirtual
TextEncodingCastCounts TextEncodingCastCountVisitor::visitBinOper ( const Analyzer::BinOper bin_oper) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< TextEncodingCastCounts >.

Definition at line 324 of file RelAlgExecutor.cpp.

References aggregateResult(), defaultResult(), disregard_casts_to_none_encoding_, Analyzer::BinOper::get_left_operand(), Analyzer::BinOper::get_optype(), Analyzer::BinOper::get_right_operand(), kCAST, kEQ, kNE, run_benchmark_import::result, ScalarExprVisitor< TextEncodingCastCounts >::visit(), and visitUOper().

324  {
326  // Currently the join framework handles casts between string types, and
327  // casts to none-encoded strings should be considered spurious, except
328  // when the join predicate is not a =/<> operator, in which case
329  // for both join predicates and all other instances we have to decode
330  // to a none-encoded string to do the comparison. The logic below essentially
331  // overrides the logic such as to always count none-encoded casts on strings
332  // that are children of binary operators other than =/<>
333  if (bin_oper->get_optype() != kEQ && bin_oper->get_optype() != kNE) {
334  // Override the global override so that join opers don't skip
335  // the check when there is an actual cast to none-encoded string
336  const auto prev_disregard_casts_to_none_encoding_state =
338  const auto left_u_oper =
339  dynamic_cast<const Analyzer::UOper*>(bin_oper->get_left_operand());
340  if (left_u_oper && left_u_oper->get_optype() == kCAST) {
342  result = aggregateResult(result, visitUOper(left_u_oper));
343  } else {
344  disregard_casts_to_none_encoding_ = prev_disregard_casts_to_none_encoding_state;
345  result = aggregateResult(result, visit(bin_oper->get_left_operand()));
346  }
347 
348  const auto right_u_oper =
349  dynamic_cast<const Analyzer::UOper*>(bin_oper->get_left_operand());
350  if (right_u_oper && right_u_oper->get_optype() == kCAST) {
352  result = aggregateResult(result, visitUOper(right_u_oper));
353  } else {
354  disregard_casts_to_none_encoding_ = prev_disregard_casts_to_none_encoding_state;
355  result = aggregateResult(result, visit(bin_oper->get_right_operand()));
356  }
357  disregard_casts_to_none_encoding_ = prev_disregard_casts_to_none_encoding_state;
358  } else {
359  result = aggregateResult(result, visit(bin_oper->get_left_operand()));
360  result = aggregateResult(result, visit(bin_oper->get_right_operand()));
361  }
362  return result;
363  }
TextEncodingCastCounts visitUOper(const Analyzer::UOper *u_oper) const override
const Expr * get_right_operand() const
Definition: Analyzer.h:456
Definition: sqldefs.h:51
Definition: sqldefs.h:32
TextEncodingCastCounts visit(const Analyzer::Expr *expr) const
SQLOps get_optype() const
Definition: Analyzer.h:452
TextEncodingCastCounts aggregateResult(const TextEncodingCastCounts &aggregate, const TextEncodingCastCounts &next_result) const override
Definition: sqldefs.h:34
const Expr * get_left_operand() const
Definition: Analyzer.h:455
TextEncodingCastCounts defaultResult() const override

+ Here is the call graph for this function:

TextEncodingCastCounts TextEncodingCastCountVisitor::visitLikeExpr ( const Analyzer::LikeExpr like) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< TextEncodingCastCounts >.

Definition at line 365 of file RelAlgExecutor.cpp.

References aggregateResult(), defaultResult(), disregard_casts_to_none_encoding_, Analyzer::LikeExpr::get_arg(), Analyzer::LikeExpr::get_escape_expr(), Analyzer::LikeExpr::get_like_expr(), kCAST, run_benchmark_import::result, ScalarExprVisitor< TextEncodingCastCounts >::visit(), and visitUOper().

365  {
367  const auto u_oper = dynamic_cast<const Analyzer::UOper*>(like->get_arg());
368  const auto prev_disregard_casts_to_none_encoding_state =
370  if (u_oper && u_oper->get_optype() == kCAST) {
372  result = aggregateResult(result, visitUOper(u_oper));
373  disregard_casts_to_none_encoding_ = prev_disregard_casts_to_none_encoding_state;
374  } else {
375  result = aggregateResult(result, visit(like->get_arg()));
376  }
377  result = aggregateResult(result, visit(like->get_like_expr()));
378  if (like->get_escape_expr()) {
379  result = aggregateResult(result, visit(like->get_escape_expr()));
380  }
381  return result;
382  }
TextEncodingCastCounts visitUOper(const Analyzer::UOper *u_oper) const override
const Expr * get_escape_expr() const
Definition: Analyzer.h:1064
Definition: sqldefs.h:51
TextEncodingCastCounts visit(const Analyzer::Expr *expr) const
const Expr * get_arg() const
Definition: Analyzer.h:1061
TextEncodingCastCounts aggregateResult(const TextEncodingCastCounts &aggregate, const TextEncodingCastCounts &next_result) const override
const Expr * get_like_expr() const
Definition: Analyzer.h:1063
TextEncodingCastCounts defaultResult() const override

+ Here is the call graph for this function:

TextEncodingCastCounts TextEncodingCastCountVisitor::visitStringOper ( const Analyzer::StringOper string_oper) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< TextEncodingCastCounts >.

Definition at line 311 of file RelAlgExecutor.cpp.

References aggregateResult(), defaultResult(), Analyzer::StringOper::get_kind(), Analyzer::StringOper::getArg(), Analyzer::StringOper::getArity(), Analyzer::StringOper::hasNoneEncodedTextArg(), run_benchmark_import::result, string_op_returns_string(), and ScalarExprVisitor< TextEncodingCastCounts >::visit().

312  {
314  if (string_oper->getArity() > 0) {
315  result = aggregateResult(result, visit(string_oper->getArg(0)));
316  }
317  if (string_op_returns_string(string_oper->get_kind()) &&
318  string_oper->hasNoneEncodedTextArg()) {
319  result = aggregateResult(result, TextEncodingCastCounts(0UL, 1UL));
320  }
321  return result;
322  }
bool hasNoneEncodedTextArg() const
Definition: Analyzer.h:1743
size_t getArity() const
Definition: Analyzer.h:1674
TextEncodingCastCounts visit(const Analyzer::Expr *expr) const
TextEncodingCastCounts aggregateResult(const TextEncodingCastCounts &aggregate, const TextEncodingCastCounts &next_result) const override
bool string_op_returns_string(const SqlStringOpKind kind)
Definition: sqldefs.h:552
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1672
TextEncodingCastCounts defaultResult() const override
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1688

+ Here is the call graph for this function:

TextEncodingCastCounts TextEncodingCastCountVisitor::visitUOper ( const Analyzer::UOper u_oper) const
inlineoverrideprotectedvirtual

Reimplemented from ScalarExprVisitor< TextEncodingCastCounts >.

Definition at line 277 of file RelAlgExecutor.cpp.

References aggregateResult(), defaultResult(), disregard_casts_to_none_encoding_, Analyzer::Expr::get_num_column_vars(), Analyzer::UOper::get_operand(), Analyzer::UOper::get_optype(), Analyzer::Expr::get_type_info(), kCAST, run_benchmark_import::result, and ScalarExprVisitor< TextEncodingCastCounts >::visit().

Referenced by visitBinOper(), and visitLikeExpr().

277  {
279  // Save state of input disregard_casts_to_none_encoding_ as child node traversal
280  // will reset it
281  const bool disregard_casts_to_none_encoding = disregard_casts_to_none_encoding_;
282  result = aggregateResult(result, visit(u_oper->get_operand()));
283  if (u_oper->get_optype() != kCAST) {
284  return result;
285  }
286  const auto& operand_ti = u_oper->get_operand()->get_type_info();
287  const auto& casted_ti = u_oper->get_type_info();
288  if (!operand_ti.is_string() && casted_ti.is_dict_encoded_string()) {
289  return aggregateResult(result, TextEncodingCastCounts(0UL, 1UL));
290  }
291  if (!casted_ti.is_string()) {
292  return result;
293  }
294  const bool literals_only = u_oper->get_operand()->get_num_column_vars(true) == 0UL;
295  if (literals_only) {
296  return result;
297  }
298  if (operand_ti.is_none_encoded_string() && casted_ti.is_dict_encoded_string()) {
299  return aggregateResult(result, TextEncodingCastCounts(0UL, 1UL));
300  }
301  if (operand_ti.is_dict_encoded_string() && casted_ti.is_none_encoded_string()) {
302  if (!disregard_casts_to_none_encoding) {
303  return aggregateResult(result, TextEncodingCastCounts(1UL, 0UL));
304  } else {
305  return result;
306  }
307  }
308  return result;
309  }
Definition: sqldefs.h:51
TextEncodingCastCounts visit(const Analyzer::Expr *expr) const
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
TextEncodingCastCounts aggregateResult(const TextEncodingCastCounts &aggregate, const TextEncodingCastCounts &next_result) const override
const Expr * get_operand() const
Definition: Analyzer.h:384
TextEncodingCastCounts defaultResult() const override
virtual size_t get_num_column_vars(const bool include_agg) const
Definition: Analyzer.cpp:58
SQLOps get_optype() const
Definition: Analyzer.h:383

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

const bool TextEncodingCastCountVisitor::default_disregard_casts_to_none_encoding_
private

Definition at line 403 of file RelAlgExecutor.cpp.

Referenced by visitBegin().

bool TextEncodingCastCountVisitor::disregard_casts_to_none_encoding_ = false
mutableprivate

Definition at line 402 of file RelAlgExecutor.cpp.

Referenced by visitBegin(), visitBinOper(), visitLikeExpr(), and visitUOper().


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