OmniSciDB  8fa3bf436f
 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)
 
 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 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 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 ()
 
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
 
TableDescriptor constgetModifiedTableDescriptor () 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 constgetTargetColumns () 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 827 of file RelAlgDagBuilder.h.

Member Typedef Documentation

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

Definition at line 830 of file RelAlgDagBuilder.h.

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

References RelAlgNode::inputs_.

837  : ModifyManipulationTarget(false, false, false, nullptr)
838  , scalar_exprs_(std::move(scalar_exprs))
839  , fields_(fields)
840  , hint_applied_(false)
841  , hints_(std::make_unique<Hints>()) {
842  inputs_.push_back(input);
843  }
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::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_
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 912 of file RelAlgDagBuilder.h.

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

Referenced by RelProject().

912  {
913  if (!hint_applied_) {
914  hint_applied_ = true;
915  }
916  hints_->emplace(hint_explained.getHint(), hint_explained);
917  }
std::unique_ptr< Hints > hints_
const QueryHint getHint() const
Definition: QueryHint.h:104

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

References fields_, and scalar_exprs_.

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_
std::shared_ptr<RelAlgNode> RelProject::deepCopy ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 906 of file RelAlgDagBuilder.h.

906  {
907  return std::make_shared<RelProject>(*this);
908  }
Hints* RelProject::getDeliveredHints ( )
inline

Definition at line 935 of file RelAlgDagBuilder.h.

References hints_.

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

935 { 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 879 of file RelAlgDagBuilder.h.

References scalar_exprs_.

879  {
880  return std::move(scalar_exprs_);
881  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
const std::string RelProject::getFieldName ( const size_t  i) const
inline

Definition at line 886 of file RelAlgDagBuilder.h.

References fields_, and i.

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

Definition at line 883 of file RelAlgDagBuilder.h.

References fields_.

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

883 { 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 926 of file RelAlgDagBuilder.h.

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

926  {
928  CHECK(!hints_->empty());
929  CHECK(hasHintEnabled(hint));
930  return hints_->at(hint);
931  }
std::unique_ptr< Hints > hints_
#define CHECK(condition)
Definition: Logger.h:203
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 869 of file RelAlgDagBuilder.h.

References CHECK, and scalar_exprs_.

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

869  {
870  CHECK(idx < scalar_exprs_.size());
871  return scalar_exprs_[idx].get();
872  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
#define CHECK(condition)
Definition: Logger.h:203

+ Here is the caller graph for this function:

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

Definition at line 874 of file RelAlgDagBuilder.h.

References CHECK, and scalar_exprs_.

874  {
875  CHECK(idx < scalar_exprs_.size());
876  return scalar_exprs_[idx].release();
877  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
#define CHECK(condition)
Definition: Logger.h:203
bool RelProject::hasDeliveredHint ( )
inline

Definition at line 933 of file RelAlgDagBuilder.h.

References hints_.

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

Definition at line 919 of file RelAlgDagBuilder.h.

References hint_applied_, and hints_.

Referenced by getHintInfo().

919  {
920  if (hint_applied_ && !hints_->empty()) {
921  return hints_->find(candidate_hint) != hints_->end();
922  }
923  return false;
924  }
std::unique_ptr< Hints > hints_

+ Here is the caller graph for this function:

bool RelProject::hasWindowFunctionExpr ( ) const

Definition at line 2137 of file RelAlgDagBuilder.cpp.

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

2137  {
2138  for (const auto& expr : scalar_exprs_) {
2139  if (is_window_function_operator(expr.get())) {
2140  return true;
2141  }
2142  }
2143  return false;
2144 }
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 945 of file RelAlgDagBuilder.h.

References fields_, kBIGINT, and scalar_exprs_.

945  {
947  scalar_exprs_.emplace_back(
948  std::make_unique<RexFunctionOperator const>(std::string("OFFSET_IN_FRAGMENT"),
949  transient_vector,
950  SQLTypeInfo(kBIGINT, false)));
951  fields_.emplace_back("EXPR$DELETE_OFFSET_IN_FRAGMENT");
952  }
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 221 of file RelAlgDagBuilder.cpp.

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

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:211
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:203
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 294 of file RelAlgDagBuilder.cpp.

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

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:211
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:203

+ Here is the call graph for this function:

bool RelProject::isSimple ( ) const
inline

Definition at line 854 of file RelAlgDagBuilder.h.

References scalar_exprs_.

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

854  {
855  for (const auto& expr : scalar_exprs_) {
856  if (!dynamic_cast<const RexInput*>(expr.get())) {
857  return false;
858  }
859  }
860  return true;
861  }
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 888 of file RelAlgDagBuilder.h.

889  {
890  replaceInput(old_input, input, std::nullopt);
891  }
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 127 of file RelAlgDagBuilder.cpp.

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

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:203

+ Here is the call graph for this function:

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

Definition at line 847 of file RelAlgDagBuilder.h.

References scalar_exprs_.

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

Definition at line 884 of file RelAlgDagBuilder.h.

References fields_.

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

Implements RelAlgNode.

Definition at line 867 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().

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

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

901  {
902  return cat(
903  ::typeName(this), "(", ::toString(scalar_exprs_), ", ", ::toString(fields_), ")");
904  }
std::string cat(Ts &&...args)
std::vector< std::string > fields_
std::string toString() const override
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
std::string typeName(const T *v)
Definition: toString.h:82

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

References i, and scalar_exprs_.

Referenced by RelModify::applyUpdateModificationsToInputNode().

939  {
940  for (int i = 0; i < static_cast<int>(scalar_exprs_.size()); i++) {
941  visitor_functor(i);
942  }
943  }
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 829 of file RelAlgDagBuilder.h.

Member Data Documentation

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

Definition at line 956 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: