OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RelProject Class Reference

#include <RelAlgDagBuilder.h>

+ Inheritance diagram for RelProject:
+ Collaboration diagram for RelProject:

Public Types

using ConstRexScalarPtr = std::unique_ptr< const RexScalar >
 
using ConstRexScalarPtrVector = std::vector< ConstRexScalarPtr >
 

Public Member Functions

 RelProject (std::vector< std::unique_ptr< const RexScalar >> &scalar_exprs, const std::vector< std::string > &fields, std::shared_ptr< const RelAlgNode > input)
 
 RelProject (RelProject const &)
 
void setExpressions (std::vector< std::unique_ptr< const RexScalar >> &exprs) const
 
bool isSimple () const
 
bool isIdentity () const
 
bool isRenaming () const
 
size_t size () const override
 
const RexScalargetProjectAt (const size_t idx) const
 
const RexScalargetProjectAtAndRelease (const size_t idx) const
 
std::vector< std::unique_ptr
< const RexScalar > > 
getExpressionsAndRelease ()
 
const std::vector< std::string > & getFields () const
 
void setFields (std::vector< std::string > &&fields)
 
const std::string getFieldName (const size_t i) const
 
void replaceInput (std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input) override
 
void replaceInput (std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input, std::optional< std::unordered_map< unsigned, unsigned >> old_to_new_index_map)
 
void appendInput (std::string new_field_name, std::unique_ptr< const RexScalar > new_input)
 
std::string toString (RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
 
size_t toHash () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
bool hasWindowFunctionExpr () const
 
void addHint (const ExplainedQueryHint &hint_explained)
 
const bool hasHintEnabled (QueryHint candidate_hint) const
 
const ExplainedQueryHintgetHintInfo (QueryHint hint) const
 
bool hasDeliveredHint ()
 
HintsgetDeliveredHints ()
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode (RelAlgInputs inputs={})
 
virtual ~RelAlgNode ()
 
void resetQueryExecutionState ()
 
void setContextData (const RaExecutionDesc *context_data) const
 
void setOutputMetainfo (const std::vector< TargetMetaInfo > &targets_metainfo) const
 
void setQueryPlanDag (const std::string &extracted_query_plan_dag) const
 
std::string getQueryPlanDag () const
 
size_t getQueryPlanDagHash () const
 
const std::vector
< TargetMetaInfo > & 
getOutputMetainfo () const
 
unsigned getId () const
 
void setIdInPlanTree (size_t id) const
 
std::optional< size_t > getIdInPlanTree () const
 
bool hasContextData () const
 
const RaExecutionDescgetContextData () const
 
const size_t inputCount () const
 
const RelAlgNodegetInput (const size_t idx) const
 
std::shared_ptr< const RelAlgNodegetAndOwnInput (const size_t idx) const
 
void addManagedInput (std::shared_ptr< const RelAlgNode > input)
 
bool hasInput (const RelAlgNode *needle) const
 
void setRelNodeDagId (const size_t id) const
 
size_t getRelNodeDagId () const
 
bool isNop () const
 
void markAsNop ()
 
void clearContextData () const
 
- Public Member Functions inherited from ModifyManipulationTarget
 ModifyManipulationTarget (bool const update_via_select=false, bool const delete_via_select=false, bool const varlen_update_required=false, TableDescriptor const *table_descriptor=nullptr, ColumnNameList target_columns=ColumnNameList())
 
void setUpdateViaSelectFlag () const
 
void setDeleteViaSelectFlag () const
 
void setVarlenUpdateRequired (bool required) const
 
void forceRowwiseOutput () const
 
TableDescriptor const * getModifiedTableDescriptor () const
 
void setModifiedTableDescriptor (TableDescriptor const *td) const
 
auto const isUpdateViaSelect () const
 
auto const isDeleteViaSelect () const
 
auto const isVarlenUpdateRequired () const
 
auto const isRowwiseOutputForced () const
 
void setTargetColumns (ColumnNameList const &target_columns) const
 
ColumnNameList const & getTargetColumns () const
 
template<typename VALIDATION_FUNCTOR >
bool validateTargetColumns (VALIDATION_FUNCTOR validator) const
 

Private Member Functions

template<typename EXPR_VISITOR_FUNCTOR >
void visitScalarExprs (EXPR_VISITOR_FUNCTOR visitor_functor) const
 
void injectOffsetInFragmentExpr () const
 

Private Attributes

std::vector< std::unique_ptr
< const RexScalar > > 
scalar_exprs_
 
std::vector< std::string > fields_
 
bool hint_applied_
 
std::unique_ptr< Hintshints_
 

Friends

class RelModify
 

Additional Inherited Members

- Static Public Member Functions inherited from RelAlgNode
static void resetRelAlgFirstId () noexcept
 
- Protected Attributes inherited from RelAlgNode
RelAlgInputs inputs_
 
const unsigned id_
 
std::optional< size_t > id_in_plan_tree_
 
std::optional< size_t > hash_
 

Detailed Description

Definition at line 1014 of file RelAlgDagBuilder.h.

Member Typedef Documentation

using RelProject::ConstRexScalarPtr = std::unique_ptr<const RexScalar>

Definition at line 1017 of file RelAlgDagBuilder.h.

Definition at line 1018 of file RelAlgDagBuilder.h.

Constructor & Destructor Documentation

RelProject::RelProject ( std::vector< std::unique_ptr< const RexScalar >> &  scalar_exprs,
const std::vector< std::string > &  fields,
std::shared_ptr< const RelAlgNode input 
)
inline

Definition at line 1021 of file RelAlgDagBuilder.h.

References RelAlgNode::inputs_.

Referenced by toHash().

1024  : ModifyManipulationTarget(false, false, false, nullptr)
1025  , scalar_exprs_(std::move(scalar_exprs))
1026  , fields_(fields)
1027  , hint_applied_(false)
1028  , hints_(std::make_unique<Hints>()) {
1029  inputs_.push_back(input);
1030  }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::unique_ptr< Hints > hints_
ModifyManipulationTarget(bool const update_via_select=false, bool const delete_via_select=false, bool const varlen_update_required=false, TableDescriptor const *table_descriptor=nullptr, ColumnNameList target_columns=ColumnNameList())
RelAlgInputs inputs_

+ Here is the caller graph for this function:

RelProject::RelProject ( RelProject const &  rhs)

Definition at line 556 of file RelAlgDagBuilder.cpp.

References addHint(), hint_applied_, hints_, scalar_exprs_, and RexVisitorBase< T >::visit().

557  : RelAlgNode(rhs)
559  , fields_(rhs.fields_)
560  , hint_applied_(false)
561  , hints_(std::make_unique<Hints>()) {
562  RexDeepCopyVisitor copier;
563  for (auto const& expr : rhs.scalar_exprs_) {
564  scalar_exprs_.push_back(copier.visit(expr.get()));
565  }
566  if (rhs.hint_applied_) {
567  for (auto const& kv : *rhs.hints_) {
568  addHint(kv.second);
569  }
570  }
571 }
RelAlgNode(RelAlgInputs inputs={})
std::vector< std::string > fields_
virtual T visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
void addHint(const ExplainedQueryHint &hint_explained)
std::unique_ptr< Hints > hints_
ModifyManipulationTarget(bool const update_via_select=false, bool const delete_via_select=false, bool const varlen_update_required=false, TableDescriptor const *table_descriptor=nullptr, ColumnNameList target_columns=ColumnNameList())

+ Here is the call graph for this function:

Member Function Documentation

void RelProject::addHint ( const ExplainedQueryHint hint_explained)
inline

Definition at line 1114 of file RelAlgDagBuilder.h.

References ExplainedQueryHint::getHint(), hint_applied_, and hints_.

Referenced by RelProject().

1114  {
1115  if (!hint_applied_) {
1116  hint_applied_ = true;
1117  }
1118  hints_->emplace(hint_explained.getHint(), hint_explained);
1119  }
std::unique_ptr< Hints > hints_
const QueryHint getHint() const
Definition: QueryHint.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelProject::appendInput ( std::string  new_field_name,
std::unique_ptr< const RexScalar new_input 
)

Definition at line 365 of file RelAlgDagBuilder.cpp.

References fields_, and scalar_exprs_.

366  {
367  fields_.emplace_back(std::move(new_field_name));
368  scalar_exprs_.emplace_back(std::move(new_input));
369 }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::shared_ptr<RelAlgNode> RelProject::deepCopy ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1108 of file RelAlgDagBuilder.h.

1108  {
1109  return std::make_shared<RelProject>(*this);
1110  }
Hints* RelProject::getDeliveredHints ( )
inline

Definition at line 1137 of file RelAlgDagBuilder.h.

References hints_.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::handle_query_hint().

1137 { return hints_.get(); }
std::unique_ptr< Hints > hints_

+ Here is the caller graph for this function:

std::vector<std::unique_ptr<const RexScalar> > RelProject::getExpressionsAndRelease ( )
inline

Definition at line 1066 of file RelAlgDagBuilder.h.

References scalar_exprs_.

1066  {
1067  return std::move(scalar_exprs_);
1068  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
const std::string RelProject::getFieldName ( const size_t  i) const
inline

Definition at line 1073 of file RelAlgDagBuilder.h.

References fields_.

1073 { return fields_[i]; }
std::vector< std::string > fields_
const std::vector<std::string>& RelProject::getFields ( ) const
inline

Definition at line 1070 of file RelAlgDagBuilder.h.

References fields_.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::create_compound().

1070 { return fields_; }
std::vector< std::string > fields_

+ Here is the caller graph for this function:

const ExplainedQueryHint& RelProject::getHintInfo ( QueryHint  hint) const
inline

Definition at line 1128 of file RelAlgDagBuilder.h.

References CHECK, hasHintEnabled(), hint_applied_, and hints_.

1128  {
1130  CHECK(!hints_->empty());
1131  CHECK(hasHintEnabled(hint));
1132  return hints_->at(hint);
1133  }
std::unique_ptr< Hints > hints_
#define CHECK(condition)
Definition: Logger.h:223
const bool hasHintEnabled(QueryHint candidate_hint) const

+ Here is the call graph for this function:

const RexScalar* RelProject::getProjectAt ( const size_t  idx) const
inline

Definition at line 1056 of file RelAlgDagBuilder.h.

References CHECK, and scalar_exprs_.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::add_window_function_pre_project(), anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs(), anonymous_namespace{RelAlgOptimizer.cpp}::is_identical_copy(), anonymous_namespace{RelAlgExecutor.cpp}::scalar_at(), RelRexDagVisitor::visit(), and anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RelAlgPhysicalInputsVisitor::visitProject().

1056  {
1057  CHECK(idx < scalar_exprs_.size());
1058  return scalar_exprs_[idx].get();
1059  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the caller graph for this function:

const RexScalar* RelProject::getProjectAtAndRelease ( const size_t  idx) const
inline

Definition at line 1061 of file RelAlgDagBuilder.h.

References CHECK, and scalar_exprs_.

1061  {
1062  CHECK(idx < scalar_exprs_.size());
1063  return scalar_exprs_[idx].release();
1064  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
#define CHECK(condition)
Definition: Logger.h:223
bool RelProject::hasDeliveredHint ( )
inline

Definition at line 1135 of file RelAlgDagBuilder.h.

References hints_.

1135 { return !hints_->empty(); }
std::unique_ptr< Hints > hints_
const bool RelProject::hasHintEnabled ( QueryHint  candidate_hint) const
inline

Definition at line 1121 of file RelAlgDagBuilder.h.

References hint_applied_, and hints_.

Referenced by getHintInfo().

1121  {
1122  if (hint_applied_ && !hints_->empty()) {
1123  return hints_->find(candidate_hint) != hints_->end();
1124  }
1125  return false;
1126  }
std::unique_ptr< Hints > hints_

+ Here is the caller graph for this function:

bool RelProject::hasWindowFunctionExpr ( ) const

Definition at line 2621 of file RelAlgDagBuilder.cpp.

References anonymous_namespace{RelAlgDagBuilder.cpp}::anonymous_namespace{RelAlgDagBuilder.cpp}::is_window_function_operator(), and scalar_exprs_.

Referenced by RelModify::applyUpdateModificationsToInputNode().

2621  {
2622  for (const auto& expr : scalar_exprs_) {
2623  if (is_window_function_operator(expr.get())) {
2624  return true;
2625  }
2626  }
2627  return false;
2628 }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelProject::injectOffsetInFragmentExpr ( ) const
inlineprivate

Definition at line 1147 of file RelAlgDagBuilder.h.

References fields_, kBIGINT, and scalar_exprs_.

1147  {
1149  scalar_exprs_.emplace_back(
1150  std::make_unique<RexFunctionOperator const>(std::string("OFFSET_IN_FRAGMENT"),
1151  transient_vector,
1152  SQLTypeInfo(kBIGINT, false)));
1153  fields_.emplace_back("EXPR$DELETE_OFFSET_IN_FRAGMENT");
1154  }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::vector< ConstRexScalarPtr > ConstRexScalarPtrVector
bool RelProject::isIdentity ( ) const

Definition at line 440 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, get_node_output(), RelAlgNode::getInput(), RelAlgNode::inputCount(), isSimple(), and scalar_exprs_.

440  {
441  if (!isSimple()) {
442  return false;
443  }
444  CHECK_EQ(size_t(1), inputCount());
445  const auto source = getInput(0);
446  if (dynamic_cast<const RelJoin*>(source)) {
447  return false;
448  }
449  const auto source_shape = get_node_output(source);
450  if (source_shape.size() != scalar_exprs_.size()) {
451  return false;
452  }
453  for (size_t i = 0; i < scalar_exprs_.size(); ++i) {
454  const auto& scalar_expr = scalar_exprs_[i];
455  const auto input = dynamic_cast<const RexInput*>(scalar_expr.get());
456  CHECK(input);
457  CHECK_EQ(source, input->getSourceNode());
458  // We should add the additional check that input->getIndex() !=
459  // source_shape[i].getIndex(), but Calcite doesn't generate the right
460  // Sort-Project-Sort sequence when joins are involved.
461  if (input->getSourceNode() != source_shape[i].getSourceNode()) {
462  return false;
463  }
464  }
465  return true;
466 }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
const RelAlgNode * getInput(const size_t idx) const
bool isSimple() const
#define CHECK(condition)
Definition: Logger.h:223
RANodeOutput get_node_output(const RelAlgNode *ra_node)
const size_t inputCount() const

+ Here is the call graph for this function:

bool RelProject::isRenaming ( ) const

Definition at line 513 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, fields_, anonymous_namespace{RelAlgDagBuilder.cpp}::isRenamedInput(), isSimple(), and scalar_exprs_.

513  {
514  if (!isSimple()) {
515  return false;
516  }
517  CHECK_EQ(scalar_exprs_.size(), fields_.size());
518  for (size_t i = 0; i < fields_.size(); ++i) {
519  auto rex_in = dynamic_cast<const RexInput*>(scalar_exprs_[i].get());
520  CHECK(rex_in);
521  if (isRenamedInput(rex_in->getSourceNode(), rex_in->getIndex(), fields_[i])) {
522  return true;
523  }
524  }
525  return false;
526 }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
bool isRenamedInput(const RelAlgNode *node, const size_t index, const std::string &new_name)
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
bool isSimple() const
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the call graph for this function:

bool RelProject::isSimple ( ) const
inline

Definition at line 1041 of file RelAlgDagBuilder.h.

References scalar_exprs_.

Referenced by RelAlgExecutor::executeProject(), isIdentity(), isRenaming(), and anonymous_namespace{RelAlgOptimizer.cpp}::safe_to_redirect().

1041  {
1042  for (const auto& expr : scalar_exprs_) {
1043  if (!dynamic_cast<const RexInput*>(expr.get())) {
1044  return false;
1045  }
1046  }
1047  return true;
1048  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

+ Here is the caller graph for this function:

void RelProject::replaceInput ( std::shared_ptr< const RelAlgNode old_input,
std::shared_ptr< const RelAlgNode input 
)
inlineoverridevirtual

Reimplemented from RelAlgNode.

Definition at line 1075 of file RelAlgDagBuilder.h.

1076  {
1077  replaceInput(old_input, input, std::nullopt);
1078  }
void replaceInput(std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input) override
void RelProject::replaceInput ( std::shared_ptr< const RelAlgNode old_input,
std::shared_ptr< const RelAlgNode input,
std::optional< std::unordered_map< unsigned, unsigned >>  old_to_new_index_map 
)

Definition at line 346 of file RelAlgDagBuilder.cpp.

References CHECK, RelAlgNode::replaceInput(), and scalar_exprs_.

349  {
350  RelAlgNode::replaceInput(old_input, input);
351  std::unique_ptr<RexRebindInputsVisitor> rebind_inputs;
352  if (old_to_new_index_map) {
353  rebind_inputs = std::make_unique<RexRebindReindexInputsVisitor>(
354  old_input.get(), input.get(), *old_to_new_index_map);
355  } else {
356  rebind_inputs =
357  std::make_unique<RexRebindInputsVisitor>(old_input.get(), input.get());
358  }
359  CHECK(rebind_inputs);
360  for (const auto& scalar_expr : scalar_exprs_) {
361  rebind_inputs->visit(scalar_expr.get());
362  }
363 }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
virtual void replaceInput(std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input)
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the call graph for this function:

void RelProject::setExpressions ( std::vector< std::unique_ptr< const RexScalar >> &  exprs) const
inline

Definition at line 1034 of file RelAlgDagBuilder.h.

References scalar_exprs_.

1034  {
1035  scalar_exprs_ = std::move(exprs);
1036  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
void RelProject::setFields ( std::vector< std::string > &&  fields)
inline

Definition at line 1071 of file RelAlgDagBuilder.h.

References fields_.

1071 { fields_ = std::move(fields); }
std::vector< std::string > fields_
size_t RelProject::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1054 of file RelAlgDagBuilder.h.

References scalar_exprs_.

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::get_scalar_sources_size(), anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs(), anonymous_namespace{RelAlgOptimizer.cpp}::is_identical_copy(), RelRexDagVisitor::visit(), and anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RelAlgPhysicalInputsVisitor::visitProject().

1054 { return scalar_exprs_.size(); }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

+ Here is the caller graph for this function:

size_t RelProject::toHash ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1097 of file RelAlgDagBuilder.h.

References fields_, RelAlgNode::hash_, RelProject(), scalar_exprs_, and toString().

1097  {
1098  if (!hash_) {
1099  hash_ = typeid(RelProject).hash_code();
1100  for (auto& target_expr : scalar_exprs_) {
1101  boost::hash_combine(*hash_, target_expr->toHash());
1102  }
1103  boost::hash_combine(*hash_, ::toString(fields_));
1104  }
1105  return *hash_;
1106  }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::optional< size_t > hash_
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
RelProject(std::vector< std::unique_ptr< const RexScalar >> &scalar_exprs, const std::vector< std::string > &fields, std::shared_ptr< const RelAlgNode > input)

+ Here is the call graph for this function:

std::string RelProject::toString ( RelRexToStringConfig  config = RelRexToStringConfig::defaults()) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1088 of file RelAlgDagBuilder.h.

References cat(), fields_, scalar_exprs_, and typeName().

Referenced by toHash().

1089  {
1090  auto ret = cat(::typeName(this), "(");
1091  for (auto& expr : scalar_exprs_) {
1092  ret += expr->toString(config) + " ";
1093  }
1094  return cat(ret, ", ", ::toString(fields_), ")");
1095  }
std::string cat(Ts &&...args)
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::string typeName(const T *v)
Definition: toString.h:102
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename EXPR_VISITOR_FUNCTOR >
void RelProject::visitScalarExprs ( EXPR_VISITOR_FUNCTOR  visitor_functor) const
inlineprivate

Definition at line 1141 of file RelAlgDagBuilder.h.

References scalar_exprs_.

Referenced by RelModify::applyUpdateModificationsToInputNode().

1141  {
1142  for (int i = 0; i < static_cast<int>(scalar_exprs_.size()); i++) {
1143  visitor_functor(i);
1144  }
1145  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class RelModify
friend

Definition at line 1016 of file RelAlgDagBuilder.h.

Member Data Documentation

std::vector<std::string> RelProject::fields_
mutableprivate
bool RelProject::hint_applied_
private

Definition at line 1158 of file RelAlgDagBuilder.h.

Referenced by addHint(), getHintInfo(), hasHintEnabled(), and RelProject().

std::unique_ptr<Hints> RelProject::hints_
private

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