OmniSciDB  e465130ba1
 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 appendInput (std::string new_field_name, std::unique_ptr< const RexScalar > new_input)
 
std::string toString () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode ()
 
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
 
int getTargetColumnCount () 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_
 

Friends

class RelModify
 

Additional Inherited Members

- Static Public Member Functions inherited from RelAlgNode
static void resetRelAlgFirstId () noexcept
 
- Protected Attributes inherited from RelAlgNode
std::vector< std::shared_ptr
< const RelAlgNode > > 
inputs_
 
const unsigned id_
 

Detailed Description

Definition at line 776 of file RelAlgDagBuilder.h.

Member Typedef Documentation

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

Definition at line 779 of file RelAlgDagBuilder.h.

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

References RelAlgNode::inputs_.

786  : ModifyManipulationTarget(false, false, false, nullptr)
787  , scalar_exprs_(std::move(scalar_exprs))
788  , fields_(fields) {
789  inputs_.push_back(input);
790  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
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())

Member Function Documentation

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

Definition at line 106 of file RelAlgDagBuilder.cpp.

References fields_, and scalar_exprs_.

107  {
108  fields_.emplace_back(std::move(new_field_name));
109  scalar_exprs_.emplace_back(std::move(new_input));
110 }
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 294 of file RelAlgDagBuilder.cpp.

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

294  {
295  RexDeepCopyVisitor copier;
296  std::vector<std::unique_ptr<const RexScalar>> exprs_copy;
297  for (auto& expr : scalar_exprs_) {
298  exprs_copy.push_back(copier.visit(expr.get()));
299  }
300  return std::make_shared<RelProject>(exprs_copy, fields_, inputs_[0]);
301 }
std::vector< std::shared_ptr< const RelAlgNode > > 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_

+ Here is the call graph for this function:

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

Definition at line 824 of file RelAlgDagBuilder.h.

824  {
825  return std::move(scalar_exprs_);
826  }
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
const std::string RelProject::getFieldName ( const size_t  i) const
inline

Definition at line 831 of file RelAlgDagBuilder.h.

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

Definition at line 828 of file RelAlgDagBuilder.h.

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

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

+ Here is the caller graph for this function:

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

Definition at line 814 of file RelAlgDagBuilder.h.

References CHECK().

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

814  {
815  CHECK(idx < scalar_exprs_.size());
816  return scalar_exprs_[idx].get();
817  }
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 819 of file RelAlgDagBuilder.h.

References CHECK().

819  {
820  CHECK(idx < scalar_exprs_.size());
821  return scalar_exprs_[idx].release();
822  }
CHECK(cgen_state)
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 858 of file RelAlgDagBuilder.h.

References kINT.

Referenced by RelModify::applyDeleteModificationsToInputNode().

858  {
860  scalar_exprs_.emplace_back(std::make_unique<RexFunctionOperator const>(
861  std::string("OFFSET_IN_FRAGMENT"), transient_vector, SQLTypeInfo(kINT, false)));
862  fields_.emplace_back("EXPR$DELETE_OFFSET_IN_FRAGMENT");
863  }
std::vector< std::string > fields_
std::vector< std::unique_ptr< const RexScalar > > scalar_exprs_
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:867
std::vector< ConstRexScalarPtr > ConstRexScalarPtrVector
Definition: sqltypes.h:48

+ Here is the caller graph for this function:

bool RelProject::isIdentity ( ) const

Definition at line 179 of file RelAlgDagBuilder.cpp.

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

179  {
180  if (!isSimple()) {
181  return false;
182  }
183  CHECK_EQ(size_t(1), inputCount());
184  const auto source = getInput(0);
185  if (dynamic_cast<const RelJoin*>(source)) {
186  return false;
187  }
188  const auto source_shape = get_node_output(source);
189  if (source_shape.size() != scalar_exprs_.size()) {
190  return false;
191  }
192  for (size_t i = 0; i < scalar_exprs_.size(); ++i) {
193  const auto& scalar_expr = scalar_exprs_[i];
194  const auto input = dynamic_cast<const RexInput*>(scalar_expr.get());
195  CHECK(input);
196  CHECK_EQ(source, input->getSourceNode());
197  // We should add the additional check that input->getIndex() !=
198  // source_shape[i].getIndex(), but Calcite doesn't generate the right
199  // Sort-Project-Sort sequence when joins are involved.
200  if (input->getSourceNode() != source_shape[i].getSourceNode()) {
201  return false;
202  }
203  }
204  return true;
205 }
#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 251 of file RelAlgDagBuilder.cpp.

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

251  {
252  if (!isSimple()) {
253  return false;
254  }
255  CHECK_EQ(scalar_exprs_.size(), fields_.size());
256  for (size_t i = 0; i < fields_.size(); ++i) {
257  auto rex_in = dynamic_cast<const RexInput*>(scalar_exprs_[i].get());
258  CHECK(rex_in);
259  if (isRenamedInput(rex_in->getSourceNode(), rex_in->getIndex(), fields_[i])) {
260  return true;
261  }
262  }
263  return false;
264 }
#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 799 of file RelAlgDagBuilder.h.

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

799  {
800  for (const auto& expr : scalar_exprs_) {
801  if (!dynamic_cast<const RexInput*>(expr.get())) {
802  return false;
803  }
804  }
805  return true;
806  }
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 
)
overridevirtual

Reimplemented from RelAlgNode.

Definition at line 97 of file RelAlgDagBuilder.cpp.

References RelAlgNode::replaceInput(), and scalar_exprs_.

98  {
99  RelAlgNode::replaceInput(old_input, input);
100  RexRebindInputsVisitor rebind_inputs(old_input.get(), input.get());
101  for (const auto& scalar_expr : scalar_exprs_) {
102  rebind_inputs.visit(scalar_expr.get());
103  }
104 }
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 792 of file RelAlgDagBuilder.h.

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

Definition at line 829 of file RelAlgDagBuilder.h.

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

Implements RelAlgNode.

Definition at line 839 of file RelAlgDagBuilder.h.

References run_benchmark_import::result, and to_string().

839  {
840  std::string result =
841  "(RelProject<" + std::to_string(reinterpret_cast<uint64_t>(this)) + ">";
842  for (const auto& scalar_expr : scalar_exprs_) {
843  result += " " + scalar_expr->toString();
844  }
845  return result + ")";
846  }
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 852 of file RelAlgDagBuilder.h.

Referenced by RelModify::applyUpdateModificationsToInputNode().

852  {
853  for (int i = 0; i < static_cast<int>(scalar_exprs_.size()); i++) {
854  visitor_functor(i);
855  }
856  }
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 778 of file RelAlgDagBuilder.h.

Member Data Documentation

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

Definition at line 866 of file RelAlgDagBuilder.h.

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

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

Definition at line 865 of file RelAlgDagBuilder.h.

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


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