OmniSciDB  72180abbfe
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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)
 
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 885 of file RelAlgDagBuilder.h.

Member Typedef Documentation

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

Definition at line 888 of file RelAlgDagBuilder.h.

Definition at line 889 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 892 of file RelAlgDagBuilder.h.

References RelAlgNode::inputs_.

895  : ModifyManipulationTarget(false, false, false, nullptr)
896  , scalar_exprs_(std::move(scalar_exprs))
897  , fields_(fields)
898  , hint_applied_(false)
899  , hints_(std::make_unique<Hints>()) {
900  inputs_.push_back(input);
901  }
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_

Member Function Documentation

void RelProject::addHint ( const HintExplained hint_explained)
inline

Definition at line 970 of file RelAlgDagBuilder.h.

References HintExplained::getHintName().

970  {
971  if (!hint_applied_) {
972  hint_applied_ = true;
973  }
974  hints_->emplace(hint_explained.getHintName(), hint_explained);
975  }
const std::string & getHintName() const
std::unique_ptr< Hints > hints_

+ Here is the call graph for this function:

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

Definition at line 142 of file RelAlgDagBuilder.cpp.

References fields_, and scalar_exprs_.

143  {
144  fields_.emplace_back(std::move(new_field_name));
145  scalar_exprs_.emplace_back(std::move(new_input));
146 }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::shared_ptr< RelAlgNode > RelProject::deepCopy ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 334 of file RelAlgDagBuilder.cpp.

References fields_, hint_applied_, hints_, RelAlgNode::inputs_, scalar_exprs_, and RexVisitorBase< T >::visit().

334  {
335  RexDeepCopyVisitor copier;
336  std::vector<std::unique_ptr<const RexScalar>> exprs_copy;
337  for (auto& expr : scalar_exprs_) {
338  exprs_copy.push_back(copier.visit(expr.get()));
339  }
340  if (hint_applied_) {
341  auto copied = std::make_shared<RelProject>(exprs_copy, fields_, inputs_[0]);
342  for (auto& kv : *hints_) {
343  copied->addHint(kv.second);
344  }
345  return copied;
346  }
347  return std::make_shared<RelProject>(exprs_copy, fields_, inputs_[0]);
348 }
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_
std::unique_ptr< Hints > hints_
RelAlgInputs inputs_

+ Here is the call graph for this function:

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

Definition at line 935 of file RelAlgDagBuilder.h.

935  {
936  return std::move(scalar_exprs_);
937  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
const std::string RelProject::getFieldName ( const size_t  i) const
inline

Definition at line 942 of file RelAlgDagBuilder.h.

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

Definition at line 939 of file RelAlgDagBuilder.h.

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

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

+ Here is the caller graph for this function:

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

Definition at line 984 of file RelAlgDagBuilder.h.

References CHECK().

984  {
986  CHECK(!hints_->empty());
987  CHECK(hasHintEnabled(hint_name));
988  return hints_->at(hint_name);
989  }
CHECK(cgen_state)
const bool hasHintEnabled(const std::string &candidate_hint_name) const
std::unique_ptr< Hints > hints_

+ Here is the call graph for this function:

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

Definition at line 925 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(), and anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RelAlgPhysicalInputsVisitor::visitProject().

925  {
926  CHECK(idx < scalar_exprs_.size());
927  return scalar_exprs_[idx].get();
928  }
CHECK(cgen_state)
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:

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

Definition at line 930 of file RelAlgDagBuilder.h.

References CHECK().

930  {
931  CHECK(idx < scalar_exprs_.size());
932  return scalar_exprs_[idx].release();
933  }
CHECK(cgen_state)
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

+ Here is the call graph for this function:

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

Definition at line 977 of file RelAlgDagBuilder.h.

977  {
978  if (hint_applied_ && !hints_->empty()) {
979  return hints_->find(candidate_hint_name) != hints_->end();
980  }
981  return false;
982  }
std::unique_ptr< Hints > hints_
bool RelProject::hasWindowFunctionExpr ( ) const

Definition at line 2090 of file RelAlgDagBuilder.cpp.

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

2090  {
2091  for (const auto& expr : scalar_exprs_) {
2092  if (is_window_function_operator(expr.get())) {
2093  return true;
2094  }
2095  }
2096  return false;
2097 }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

+ Here is the call graph for this function:

void RelProject::injectOffsetInFragmentExpr ( ) const
inlineprivate

Definition at line 999 of file RelAlgDagBuilder.h.

References kINT.

999  {
1001  scalar_exprs_.emplace_back(std::make_unique<RexFunctionOperator const>(
1002  std::string("OFFSET_IN_FRAGMENT"), transient_vector, SQLTypeInfo(kINT, false)));
1003  fields_.emplace_back("EXPR$DELETE_OFFSET_IN_FRAGMENT");
1004  }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::vector< ConstRexScalarPtr > ConstRexScalarPtrVector
Definition: sqltypes.h:46
bool RelProject::isIdentity ( ) const

Definition at line 218 of file RelAlgDagBuilder.cpp.

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

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

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

291  {
292  if (!isSimple()) {
293  return false;
294  }
295  CHECK_EQ(scalar_exprs_.size(), fields_.size());
296  for (size_t i = 0; i < fields_.size(); ++i) {
297  auto rex_in = dynamic_cast<const RexInput*>(scalar_exprs_[i].get());
298  CHECK(rex_in);
299  if (isRenamedInput(rex_in->getSourceNode(), rex_in->getIndex(), fields_[i])) {
300  return true;
301  }
302  }
303  return false;
304 }
#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_
CHECK(cgen_state)
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
bool isSimple() const

+ Here is the call graph for this function:

bool RelProject::isSimple ( ) const
inline

Definition at line 910 of file RelAlgDagBuilder.h.

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

910  {
911  for (const auto& expr : scalar_exprs_) {
912  if (!dynamic_cast<const RexInput*>(expr.get())) {
913  return false;
914  }
915  }
916  return true;
917  }
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 944 of file RelAlgDagBuilder.h.

References RelAlgNode::replaceInput().

945  {
946  replaceInput(old_input, input, std::nullopt);
947  }
void replaceInput(std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input) override

+ Here is the call graph for this function:

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

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

126  {
127  RelAlgNode::replaceInput(old_input, input);
128  std::unique_ptr<RexRebindInputsVisitor> rebind_inputs;
129  if (old_to_new_index_map) {
130  rebind_inputs = std::make_unique<RexRebindReindexInputsVisitor>(
131  old_input.get(), input.get(), *old_to_new_index_map);
132  } else {
133  rebind_inputs =
134  std::make_unique<RexRebindInputsVisitor>(old_input.get(), input.get());
135  }
136  CHECK(rebind_inputs);
137  for (const auto& scalar_expr : scalar_exprs_) {
138  rebind_inputs->visit(scalar_expr.get());
139  }
140 }
CHECK(cgen_state)
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)

+ Here is the call graph for this function:

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

Definition at line 903 of file RelAlgDagBuilder.h.

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

Definition at line 940 of file RelAlgDagBuilder.h.

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

Implements RelAlgNode.

Definition at line 923 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(), and anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RelAlgPhysicalInputsVisitor::visitProject().

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

+ Here is the caller graph for this function:

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

Implements RelAlgNode.

Definition at line 957 of file RelAlgDagBuilder.h.

References run_benchmark_import::result, and to_string().

957  {
958  std::string result =
959  "(RelProject<" + std::to_string(reinterpret_cast<uint64_t>(this)) + ">";
960  for (const auto& scalar_expr : scalar_exprs_) {
961  result += " " + scalar_expr->toString();
962  }
963  return result + ")";
964  }
std::string to_string(char const *&&v)
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_

+ Here is the call graph for this function:

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

Definition at line 993 of file RelAlgDagBuilder.h.

Referenced by RelModify::applyUpdateModificationsToInputNode().

993  {
994  for (int i = 0; i < static_cast<int>(scalar_exprs_.size()); i++) {
995  visitor_functor(i);
996  }
997  }
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 887 of file RelAlgDagBuilder.h.

Member Data Documentation

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

Definition at line 1007 of file RelAlgDagBuilder.h.

Referenced by appendInput(), deepCopy(), and isRenaming().

bool RelProject::hint_applied_
private

Definition at line 1008 of file RelAlgDagBuilder.h.

Referenced by deepCopy().

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

Definition at line 1009 of file RelAlgDagBuilder.h.

Referenced by deepCopy().

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

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