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

#include <RelAlgAbstractInterpreter.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 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 774 of file RelAlgAbstractInterpreter.h.

Member Typedef Documentation

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

Definition at line 777 of file RelAlgAbstractInterpreter.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 781 of file RelAlgAbstractInterpreter.h.

References RelAlgNode::inputs_.

784  : ModifyManipulationTarget(false, false, false, nullptr)
785  , scalar_exprs_(std::move(scalar_exprs))
786  , fields_(fields) {
787  inputs_.push_back(input);
788  }
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 103 of file RelAlgAbstractInterpreter.cpp.

References fields_, and scalar_exprs_.

104  {
105  fields_.emplace_back(std::move(new_field_name));
106  scalar_exprs_.emplace_back(std::move(new_input));
107 }
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 291 of file RelAlgAbstractInterpreter.cpp.

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

291  {
292  RexDeepCopyVisitor copier;
293  std::vector<std::unique_ptr<const RexScalar>> exprs_copy;
294  for (auto& expr : scalar_exprs_) {
295  exprs_copy.push_back(copier.visit(expr.get()));
296  }
297  return std::make_shared<RelProject>(exprs_copy, fields_, inputs_[0]);
298 }
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 822 of file RelAlgAbstractInterpreter.h.

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

Definition at line 829 of file RelAlgAbstractInterpreter.h.

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

Definition at line 826 of file RelAlgAbstractInterpreter.h.

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

826 { 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 812 of file RelAlgAbstractInterpreter.h.

References CHECK().

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

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

References CHECK().

817  {
818  CHECK(idx < scalar_exprs_.size());
819  return scalar_exprs_[idx].release();
820  }
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 856 of file RelAlgAbstractInterpreter.h.

References kINT.

Referenced by RelModify::applyDeleteModificationsToInputNode().

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

+ Here is the caller graph for this function:

bool RelProject::isIdentity ( ) const

Definition at line 176 of file RelAlgAbstractInterpreter.cpp.

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

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

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

248  {
249  if (!isSimple()) {
250  return false;
251  }
252  CHECK_EQ(scalar_exprs_.size(), fields_.size());
253  for (size_t i = 0; i < fields_.size(); ++i) {
254  auto rex_in = dynamic_cast<const RexInput*>(scalar_exprs_[i].get());
255  CHECK(rex_in);
256  if (isRenamedInput(rex_in->getSourceNode(), rex_in->getIndex(), fields_[i])) {
257  return true;
258  }
259  }
260  return false;
261 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< std::string > fields_
CHECK(cgen_state)
bool isRenamedInput(const RelAlgNode *node, const size_t index, const std::string &new_name)
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 797 of file RelAlgAbstractInterpreter.h.

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

797  {
798  for (const auto& expr : scalar_exprs_) {
799  if (!dynamic_cast<const RexInput*>(expr.get())) {
800  return false;
801  }
802  }
803  return true;
804  }
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 94 of file RelAlgAbstractInterpreter.cpp.

References RelAlgNode::replaceInput(), and scalar_exprs_.

95  {
96  RelAlgNode::replaceInput(old_input, input);
97  RexRebindInputsVisitor rebind_inputs(old_input.get(), input.get());
98  for (const auto& scalar_expr : scalar_exprs_) {
99  rebind_inputs.visit(scalar_expr.get());
100  }
101 }
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 790 of file RelAlgAbstractInterpreter.h.

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

Definition at line 827 of file RelAlgAbstractInterpreter.h.

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

Implements RelAlgNode.

Definition at line 837 of file RelAlgAbstractInterpreter.h.

References run_benchmark_import::result, and to_string().

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

Referenced by RelModify::applyUpdateModificationsToInputNode().

850  {
851  for (int i = 0; i < static_cast<int>(scalar_exprs_.size()); i++) {
852  visitor_functor(i);
853  }
854  }
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 776 of file RelAlgAbstractInterpreter.h.

Member Data Documentation

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

Definition at line 864 of file RelAlgAbstractInterpreter.h.

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

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

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