OmniSciDB  8a228a1076
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 () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
bool hasWindowFunctionExpr () const
 
void addHint (const HintExplained &hint_explained)
 
const bool hasHintEnabled (const std::string &candidate_hint_name) const
 
const HintExplainedgetHintInfo (const std::string &hint_name) const
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode (RelAlgInputs inputs={})
 
virtual ~RelAlgNode ()
 
void resetQueryExecutionState ()
 
void setContextData (const void *context_data) const
 
void setOutputMetainfo (const std::vector< TargetMetaInfo > &targets_metainfo) const
 
const std::vector< TargetMetaInfo > & getOutputMetainfo () const
 
unsigned getId () const
 
bool hasContextData () const
 
const void * getContextData () 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
 
bool isNop () const
 
void markAsNop ()
 
- 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
 
TableDescriptor const * getModifiedTableDescriptor () const
 
void setModifiedTableDescriptor (TableDescriptor const *td) const
 
auto const isUpdateViaSelect () const
 
auto const isDeleteViaSelect () const
 
auto const isVarlenUpdateRequired () 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_
 

Detailed Description

Definition at line 894 of file RelAlgDagBuilder.h.

Member Typedef Documentation

◆ ConstRexScalarPtr

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

Definition at line 897 of file RelAlgDagBuilder.h.

◆ ConstRexScalarPtrVector

Definition at line 898 of file RelAlgDagBuilder.h.

Constructor & Destructor Documentation

◆ RelProject() [1/2]

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 901 of file RelAlgDagBuilder.h.

References RelAlgNode::inputs_.

904  : ModifyManipulationTarget(false, false, false, nullptr)
905  , scalar_exprs_(std::move(scalar_exprs))
906  , fields_(fields)
907  , hint_applied_(false)
908  , hints_(std::make_unique<Hints>()) {
909  inputs_.push_back(input);
910  }
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_

◆ RelProject() [2/2]

RelProject::RelProject ( RelProject const &  rhs)

Definition at line 337 of file RelAlgDagBuilder.cpp.

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

338  : RelAlgNode(rhs)
340  , fields_(rhs.fields_)
341  , hint_applied_(false)
342  , hints_(std::make_unique<Hints>()) {
343  RexDeepCopyVisitor copier;
344  for (auto const& expr : rhs.scalar_exprs_) {
345  scalar_exprs_.push_back(copier.visit(expr.get()));
346  }
347  if (rhs.hint_applied_) {
348  for (auto const& kv : *rhs.hints_) {
349  addHint(kv.second);
350  }
351  }
352 }
RelAlgNode(RelAlgInputs inputs={})
std::vector< std::string > fields_
void addHint(const HintExplained &hint_explained)
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
virtual T visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
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

◆ addHint()

void RelProject::addHint ( const HintExplained hint_explained)
inline

Definition at line 983 of file RelAlgDagBuilder.h.

References HintExplained::getHintName().

Referenced by RelProject().

983  {
984  if (!hint_applied_) {
985  hint_applied_ = true;
986  }
987  hints_->emplace(hint_explained.getHintName(), hint_explained);
988  }
const std::string & getHintName() const
std::unique_ptr< Hints > hints_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendInput()

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

Definition at line 146 of file RelAlgDagBuilder.cpp.

147  {
148  fields_.emplace_back(std::move(new_field_name));
149  scalar_exprs_.emplace_back(std::move(new_input));
150 }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

◆ deepCopy()

std::shared_ptr<RelAlgNode> RelProject::deepCopy ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 977 of file RelAlgDagBuilder.h.

977  {
978  return std::make_shared<RelProject>(*this);
979  }

◆ getExpressionsAndRelease()

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

Definition at line 946 of file RelAlgDagBuilder.h.

946  {
947  return std::move(scalar_exprs_);
948  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

◆ getFieldName()

const std::string RelProject::getFieldName ( const size_t  i) const
inline

Definition at line 953 of file RelAlgDagBuilder.h.

953 { return fields_[i]; }
std::vector< std::string > fields_

◆ getFields()

const std::vector<std::string>& RelProject::getFields ( ) const
inline

Definition at line 950 of file RelAlgDagBuilder.h.

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

950 { return fields_; }
std::vector< std::string > fields_
+ Here is the caller graph for this function:

◆ getHintInfo()

const HintExplained& RelProject::getHintInfo ( const std::string &  hint_name) const
inline

Definition at line 997 of file RelAlgDagBuilder.h.

References CHECK.

997  {
999  CHECK(!hints_->empty());
1000  CHECK(hasHintEnabled(hint_name));
1001  return hints_->at(hint_name);
1002  }
const bool hasHintEnabled(const std::string &candidate_hint_name) const
std::unique_ptr< Hints > hints_
#define CHECK(condition)
Definition: Logger.h:197

◆ getProjectAt()

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

Definition at line 936 of file RelAlgDagBuilder.h.

References CHECK.

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

936  {
937  CHECK(idx < scalar_exprs_.size());
938  return scalar_exprs_[idx].get();
939  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ getProjectAtAndRelease()

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

Definition at line 941 of file RelAlgDagBuilder.h.

References CHECK.

941  {
942  CHECK(idx < scalar_exprs_.size());
943  return scalar_exprs_[idx].release();
944  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
#define CHECK(condition)
Definition: Logger.h:197

◆ hasHintEnabled()

const bool RelProject::hasHintEnabled ( const std::string &  candidate_hint_name) const
inline

Definition at line 990 of file RelAlgDagBuilder.h.

990  {
991  if (hint_applied_ && !hints_->empty()) {
992  return hints_->find(candidate_hint_name) != hints_->end();
993  }
994  return false;
995  }
std::unique_ptr< Hints > hints_

◆ hasWindowFunctionExpr()

bool RelProject::hasWindowFunctionExpr ( ) const

Definition at line 2111 of file RelAlgDagBuilder.cpp.

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

2111  {
2112  for (const auto& expr : scalar_exprs_) {
2113  if (is_window_function_operator(expr.get())) {
2114  return true;
2115  }
2116  }
2117  return false;
2118 }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
+ Here is the call graph for this function:

◆ injectOffsetInFragmentExpr()

void RelProject::injectOffsetInFragmentExpr ( ) const
inlineprivate

Definition at line 1012 of file RelAlgDagBuilder.h.

References kINT.

1012  {
1014  scalar_exprs_.emplace_back(std::make_unique<RexFunctionOperator const>(
1015  std::string("OFFSET_IN_FRAGMENT"), transient_vector, SQLTypeInfo(kINT, false)));
1016  fields_.emplace_back("EXPR$DELETE_OFFSET_IN_FRAGMENT");
1017  }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::vector< ConstRexScalarPtr > ConstRexScalarPtrVector
Definition: sqltypes.h:47

◆ isIdentity()

bool RelProject::isIdentity ( ) const

Definition at line 221 of file RelAlgDagBuilder.cpp.

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

221  {
222  if (!isSimple()) {
223  return false;
224  }
225  CHECK_EQ(size_t(1), inputCount());
226  const auto source = getInput(0);
227  if (dynamic_cast<const RelJoin*>(source)) {
228  return false;
229  }
230  const auto source_shape = get_node_output(source);
231  if (source_shape.size() != scalar_exprs_.size()) {
232  return false;
233  }
234  for (size_t i = 0; i < scalar_exprs_.size(); ++i) {
235  const auto& scalar_expr = scalar_exprs_[i];
236  const auto input = dynamic_cast<const RexInput*>(scalar_expr.get());
237  CHECK(input);
238  CHECK_EQ(source, input->getSourceNode());
239  // We should add the additional check that input->getIndex() !=
240  // source_shape[i].getIndex(), but Calcite doesn't generate the right
241  // Sort-Project-Sort sequence when joins are involved.
242  if (input->getSourceNode() != source_shape[i].getSourceNode()) {
243  return false;
244  }
245  }
246  return true;
247 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
bool isSimple() const
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
const size_t inputCount() const
#define CHECK(condition)
Definition: Logger.h:197
RANodeOutput get_node_output(const RelAlgNode *ra_node)
const RelAlgNode * getInput(const size_t idx) const
+ Here is the call graph for this function:

◆ isRenaming()

bool RelProject::isRenaming ( ) const

Definition at line 294 of file RelAlgDagBuilder.cpp.

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

294  {
295  if (!isSimple()) {
296  return false;
297  }
298  CHECK_EQ(scalar_exprs_.size(), fields_.size());
299  for (size_t i = 0; i < fields_.size(); ++i) {
300  auto rex_in = dynamic_cast<const RexInput*>(scalar_exprs_[i].get());
301  CHECK(rex_in);
302  if (isRenamedInput(rex_in->getSourceNode(), rex_in->getIndex(), fields_[i])) {
303  return true;
304  }
305  }
306  return false;
307 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
bool isRenamedInput(const RelAlgNode *node, const size_t index, const std::string &new_name)
std::vector< std::string > fields_
bool isSimple() const
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:

◆ isSimple()

bool RelProject::isSimple ( ) const
inline

Definition at line 921 of file RelAlgDagBuilder.h.

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

921  {
922  for (const auto& expr : scalar_exprs_) {
923  if (!dynamic_cast<const RexInput*>(expr.get())) {
924  return false;
925  }
926  }
927  return true;
928  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
+ Here is the caller graph for this function:

◆ replaceInput() [1/2]

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

Reimplemented from RelAlgNode.

Definition at line 955 of file RelAlgDagBuilder.h.

References run_benchmark_import::optional, and RelAlgNode::replaceInput().

956  {
957  replaceInput(old_input, input, std::nullopt);
958  }
void replaceInput(std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input) override
+ Here is the call graph for this function:

◆ replaceInput() [2/2]

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 127 of file RelAlgDagBuilder.cpp.

References CHECK, and RelAlgNode::replaceInput().

130  {
131  RelAlgNode::replaceInput(old_input, input);
132  std::unique_ptr<RexRebindInputsVisitor> rebind_inputs;
133  if (old_to_new_index_map) {
134  rebind_inputs = std::make_unique<RexRebindReindexInputsVisitor>(
135  old_input.get(), input.get(), *old_to_new_index_map);
136  } else {
137  rebind_inputs =
138  std::make_unique<RexRebindInputsVisitor>(old_input.get(), input.get());
139  }
140  CHECK(rebind_inputs);
141  for (const auto& scalar_expr : scalar_exprs_) {
142  rebind_inputs->visit(scalar_expr.get());
143  }
144 }
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:197
+ Here is the call graph for this function:

◆ setExpressions()

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

Definition at line 914 of file RelAlgDagBuilder.h.

914  {
915  scalar_exprs_ = std::move(exprs);
916  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

◆ setFields()

void RelProject::setFields ( std::vector< std::string > &  fields)
inline

Definition at line 951 of file RelAlgDagBuilder.h.

951 { fields_ = std::move(fields); }
std::vector< std::string > fields_

◆ size()

size_t RelProject::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 934 of file RelAlgDagBuilder.h.

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().

934 { return scalar_exprs_.size(); }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
+ Here is the caller graph for this function:

◆ toString()

std::string RelProject::toString ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 968 of file RelAlgDagBuilder.h.

References run_benchmark_import::result, and to_string().

968  {
969  std::string result =
970  "(RelProject<" + std::to_string(reinterpret_cast<uint64_t>(this)) + ">";
971  for (const auto& scalar_expr : scalar_exprs_) {
972  result += " " + scalar_expr->toString();
973  }
974  return result + ")";
975  }
std::string to_string(char const *&&v)
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
+ Here is the call graph for this function:

◆ visitScalarExprs()

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

Definition at line 1006 of file RelAlgDagBuilder.h.

Referenced by RelModify::applyUpdateModificationsToInputNode().

1006  {
1007  for (int i = 0; i < static_cast<int>(scalar_exprs_.size()); i++) {
1008  visitor_functor(i);
1009  }
1010  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ RelModify

friend class RelModify
friend

Definition at line 896 of file RelAlgDagBuilder.h.

Member Data Documentation

◆ fields_

std::vector<std::string> RelProject::fields_
mutableprivate

Definition at line 1020 of file RelAlgDagBuilder.h.

◆ hint_applied_

bool RelProject::hint_applied_
private

Definition at line 1021 of file RelAlgDagBuilder.h.

Referenced by RelProject().

◆ hints_

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

Definition at line 1022 of file RelAlgDagBuilder.h.

Referenced by RelProject().

◆ scalar_exprs_

std::vector<std::unique_ptr<const RexScalar> > RelProject::scalar_exprs_
mutableprivate

Definition at line 1019 of file RelAlgDagBuilder.h.

Referenced by RelProject().


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