OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RelModify Class Reference

#include <RelAlgDag.h>

+ Inheritance diagram for RelModify:
+ Collaboration diagram for RelModify:

Public Types

enum  ModifyOperation { ModifyOperation::Insert, ModifyOperation::Delete, ModifyOperation::Update }
 
using RelAlgNodeInputPtr = std::shared_ptr< const RelAlgNode >
 
using TargetColumnList = std::vector< std::string >
 

Public Member Functions

 RelModify (Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td)
 
 RelModify (Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td, bool flattened, std::string const &op_string, TargetColumnList const &target_column_list, RelAlgNodeInputPtr input)
 
 RelModify (Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td, bool flattened, ModifyOperation op, TargetColumnList const &target_column_list, RelAlgNodeInputPtr input)
 
TableDescriptor const *const getTableDescriptor () const
 
bool const isFlattened () const
 
ModifyOperation getOperation () const
 
TargetColumnList const & getUpdateColumnNames () const
 
int getUpdateColumnCount () const
 
size_t size () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
std::string toString (RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
 
size_t toHash () const override
 
void applyUpdateModificationsToInputNode ()
 
void applyDeleteModificationsToInputNode ()
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode (RelAlgInputs inputs={})
 
virtual ~RelAlgNode ()
 
void resetQueryExecutionState ()
 
void setContextData (const RaExecutionDesc *context_data) const
 
void setOutputMetainfo (std::vector< TargetMetaInfo > targets_metainfo) const
 
void setQueryPlanDag (const std::string &extracted_query_plan_dag) const
 
std::string getQueryPlanDag () const
 
size_t getQueryPlanDagHash () const
 
const std::vector
< TargetMetaInfo > & 
getOutputMetainfo () const
 
unsigned getId () const
 
void setIdInPlanTree (size_t id) const
 
std::optional< size_t > getIdInPlanTree () const
 
bool hasContextData () const
 
const RaExecutionDescgetContextData () 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
 
virtual void replaceInput (std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input)
 
void setRelNodeDagId (const size_t id) const
 
size_t getRelNodeDagId () const
 
bool isNop () const
 
void markAsNop ()
 
void clearContextData () const
 

Static Public Member Functions

static std::string yieldModifyOperationString (ModifyOperation const op)
 
static ModifyOperation yieldModifyOperationEnum (std::string const &op_string)
 
- Static Public Member Functions inherited from RelAlgNode
static void resetRelAlgFirstId () noexcept
 

Private Attributes

Catalog_Namespace::Catalog const & catalog_
 
const TableDescriptortable_descriptor_
 
bool flattened_
 
ModifyOperation operation_
 
TargetColumnList target_column_list_
 

Friends

struct RelAlgDagSerializer
 

Additional Inherited Members

- Protected Attributes inherited from RelAlgNode
RelAlgInputs inputs_
 
unsigned id_
 
std::optional< size_t > id_in_plan_tree_
 
std::optional< size_t > hash_
 

Detailed Description

Definition at line 2018 of file RelAlgDag.h.

Member Typedef Documentation

using RelModify::RelAlgNodeInputPtr = std::shared_ptr<const RelAlgNode>

Definition at line 2021 of file RelAlgDag.h.

using RelModify::TargetColumnList = std::vector<std::string>

Definition at line 2022 of file RelAlgDag.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 2020 of file RelAlgDag.h.

2020 { Insert, Delete, Update };

Constructor & Destructor Documentation

RelModify::RelModify ( Catalog_Namespace::Catalog const &  cat,
TableDescriptor const *const  td 
)
inline

Definition at line 2052 of file RelAlgDag.h.

Referenced by toHash().

2053  : catalog_{cat}
2054  , table_descriptor_{td}
2055  , flattened_{false}
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2217
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2215
ModifyOperation operation_
Definition: RelAlgDag.h:2218

+ Here is the caller graph for this function:

RelModify::RelModify ( Catalog_Namespace::Catalog const &  cat,
TableDescriptor const *const  td,
bool  flattened,
std::string const &  op_string,
TargetColumnList const &  target_column_list,
RelAlgNodeInputPtr  input 
)
inline

Definition at line 2058 of file RelAlgDag.h.

References RelAlgNode::inputs_, table_descriptor_, and foreign_storage::validate_non_foreign_table_write().

2064  : catalog_(cat)
2065  , table_descriptor_(td)
2066  , flattened_(flattened)
2067  , operation_(yieldModifyOperationEnum(op_string))
2068  , target_column_list_(target_column_list) {
2070  inputs_.push_back(input);
2071  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2217
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2215
static ModifyOperation yieldModifyOperationEnum(std::string const &op_string)
Definition: RelAlgDag.h:2038
ModifyOperation operation_
Definition: RelAlgDag.h:2218
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2219
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

RelModify::RelModify ( Catalog_Namespace::Catalog const &  cat,
TableDescriptor const *const  td,
bool  flattened,
ModifyOperation  op,
TargetColumnList const &  target_column_list,
RelAlgNodeInputPtr  input 
)
inline

Definition at line 2073 of file RelAlgDag.h.

References RelAlgNode::inputs_, table_descriptor_, and foreign_storage::validate_non_foreign_table_write().

2079  : catalog_(cat)
2080  , table_descriptor_(td)
2081  , flattened_(flattened)
2082  , operation_(op)
2083  , target_column_list_(target_column_list) {
2085  inputs_.push_back(input);
2086  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2217
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2215
ModifyOperation operation_
Definition: RelAlgDag.h:2218
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2219
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

Member Function Documentation

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 2206 of file RelAlgDag.h.

References CHECK, RelAlgNode::inputs_, ModifyManipulationTarget::setDeleteViaSelectFlag(), ModifyManipulationTarget::setModifiedTableDescriptor(), and table_descriptor_.

2206  {
2207  RelProject const* previous_project_node =
2208  dynamic_cast<RelProject const*>(inputs_[0].get());
2209  CHECK(previous_project_node != nullptr);
2210  previous_project_node->setDeleteViaSelectFlag(true);
2211  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2212  }
void setDeleteViaSelectFlag(bool required) const
Definition: RelAlgDag.h:1061
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
void setModifiedTableDescriptor(TableDescriptor const *td) const
Definition: RelAlgDag.h:1069
#define CHECK(condition)
Definition: Logger.h:289
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 2139 of file RelAlgDag.h.

References catalog_, CHECK, TableDescriptor::fragmenter, Catalog_Namespace::Catalog::getMetadataForColumn(), Catalog_Namespace::Catalog::getShardColumnMetadataForTable(), RelProject::hasWindowFunctionExpr(), RelAlgNode::inputs_, TableDescriptor::nShards, ModifyManipulationTarget::setModifiedTableDescriptor(), ModifyManipulationTarget::setTargetColumns(), ModifyManipulationTarget::setUpdateViaSelectFlag(), ModifyManipulationTarget::setVarlenUpdateRequired(), table_descriptor_, TableDescriptor::tableId, target_column_list_, and RelProject::visitScalarExprs().

2139  {
2140  RelProject const* previous_project_node =
2141  dynamic_cast<RelProject const*>(inputs_[0].get());
2142  CHECK(previous_project_node != nullptr);
2143 
2144  if (previous_project_node->hasWindowFunctionExpr()) {
2145  if (table_descriptor_->fragmenter->getNumFragments() > 1) {
2146  throw std::runtime_error(
2147  "UPDATE of a column of multi-fragmented table using window function not "
2148  "currently supported.");
2149  }
2150  if (table_descriptor_->nShards > 0) {
2151  throw std::runtime_error(
2152  "UPDATE of a column of sharded table using window function not "
2153  "currently supported.");
2154  }
2155  }
2156 
2157  previous_project_node->setUpdateViaSelectFlag(true);
2158  // remove the offset column in the projection for update handling
2159  target_column_list_.pop_back();
2160 
2161  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2162  previous_project_node->setTargetColumns(target_column_list_);
2163 
2164  int target_update_column_expr_start = 0;
2165  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
2166  CHECK(target_update_column_expr_start >= 0);
2167  CHECK(target_update_column_expr_end >= 0);
2168 
2169  bool varlen_update_required = false;
2170 
2171  auto varlen_scan_visitor = [this,
2172  &varlen_update_required,
2173  target_update_column_expr_start,
2174  target_update_column_expr_end](int index) {
2175  if (index >= target_update_column_expr_start &&
2176  index <= target_update_column_expr_end) {
2177  auto target_index = index - target_update_column_expr_start;
2178 
2179  auto* column_desc = catalog_.getMetadataForColumn(
2181  CHECK(column_desc);
2182 
2183  if (table_descriptor_->nShards) {
2184  const auto shard_cd =
2186  CHECK(shard_cd);
2187  if ((column_desc->columnName == shard_cd->columnName)) {
2188  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
2189  }
2190  }
2191 
2192  // Check for valid types
2193  if (column_desc->columnType.is_varlen()) {
2194  varlen_update_required = true;
2195  }
2196  if (column_desc->columnType.is_geometry()) {
2197  throw std::runtime_error("UPDATE of a geo column is unsupported.");
2198  }
2199  }
2200  };
2201 
2202  previous_project_node->visitScalarExprs(varlen_scan_visitor);
2203  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
2204  }
void setVarlenUpdateRequired(bool required) const
Definition: RelAlgDag.h:1062
void setTargetColumns(ColumnNameList const &target_columns) const
Definition: RelAlgDag.h:1081
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:4662
void setUpdateViaSelectFlag(bool required) const
Definition: RelAlgDag.h:1060
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2215
void visitScalarExprs(EXPR_VISITOR_FUNCTOR visitor_functor) const
Definition: RelAlgDag.h:1278
void setModifiedTableDescriptor(TableDescriptor const *td) const
Definition: RelAlgDag.h:1069
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
bool hasWindowFunctionExpr() const
Definition: RelAlgDag.cpp:2766
#define CHECK(condition)
Definition: Logger.h:289
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2219
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

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

Implements RelAlgNode.

Definition at line 2095 of file RelAlgDag.h.

2095  {
2096  return std::make_shared<RelModify>(*this);
2097  }
ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 2090 of file RelAlgDag.h.

References operation_.

2090 { return operation_; }
ModifyOperation operation_
Definition: RelAlgDag.h:2218
TableDescriptor const* const RelModify::getTableDescriptor ( ) const
inline

Definition at line 2088 of file RelAlgDag.h.

References table_descriptor_.

2088 { return table_descriptor_; }
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
int RelModify::getUpdateColumnCount ( ) const
inline

Definition at line 2092 of file RelAlgDag.h.

References target_column_list_.

2092 { return target_column_list_.size(); }
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2219
TargetColumnList const& RelModify::getUpdateColumnNames ( ) const
inline

Definition at line 2091 of file RelAlgDag.h.

References target_column_list_.

2091 { return target_column_list_; }
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2219
bool const RelModify::isFlattened ( ) const
inline

Definition at line 2089 of file RelAlgDag.h.

References flattened_.

2089 { return flattened_; }
bool flattened_
Definition: RelAlgDag.h:2217
size_t RelModify::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2094 of file RelAlgDag.h.

2094 { return 0; }
size_t RelModify::toHash ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2125 of file RelAlgDag.h.

References flattened_, RelAlgNode::hash_, RelAlgNode::inputs_, operation_, RelModify(), table_descriptor_, TableDescriptor::tableName, target_column_list_, toString(), and yieldModifyOperationString().

2125  {
2126  if (!hash_) {
2127  hash_ = typeid(RelModify).hash_code();
2128  boost::hash_combine(*hash_, table_descriptor_->tableName);
2129  boost::hash_combine(*hash_, flattened_);
2130  boost::hash_combine(*hash_, yieldModifyOperationString(operation_));
2131  boost::hash_combine(*hash_, ::toString(target_column_list_));
2132  for (auto& node : inputs_) {
2133  boost::hash_combine(*hash_, node->toHash());
2134  }
2135  }
2136  return *hash_;
2137  }
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:2099
bool flattened_
Definition: RelAlgDag.h:2217
RelModify(Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td)
Definition: RelAlgDag.h:2052
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
std::optional< size_t > hash_
Definition: RelAlgDag.h:955
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:2024
ModifyOperation operation_
Definition: RelAlgDag.h:2218
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2219
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

std::string RelModify::toString ( RelRexToStringConfig  config = RelRexToStringConfig::defaults()) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2099 of file RelAlgDag.h.

References cat(), flattened_, RelAlgNode::inputs_, operation_, table_descriptor_, TableDescriptor::tableName, target_column_list_, to_string(), typeName(), and yieldModifyOperationString().

Referenced by toHash().

2100  {
2101  auto ret = cat(::typeName(this),
2102  "(",
2104  ", flattened=",
2106  ", op=",
2108  ", target_column_list=",
2110  if (!config.skip_input_nodes) {
2111  ret += ", inputs=", ::toString(inputs_);
2112  } else {
2113  ret += ", input node id={";
2114  for (auto& input : inputs_) {
2115  auto node_id_in_plan = input->getIdInPlanTree();
2116  auto node_id_str = node_id_in_plan ? std::to_string(*node_id_in_plan)
2117  : std::to_string(input->getId());
2118  ret += node_id_str + " ";
2119  }
2120  ret += "}";
2121  }
2122  return cat(ret, ")");
2123  }
std::string cat(Ts &&...args)
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:2099
bool flattened_
Definition: RelAlgDag.h:2217
std::string to_string(char const *&&v)
unsigned getId() const
Definition: RelAlgDag.h:880
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2216
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:2024
std::string typeName(const T *v)
Definition: toString.h:103
ModifyOperation operation_
Definition: RelAlgDag.h:2218
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2219
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ModifyOperation RelModify::yieldModifyOperationEnum ( std::string const &  op_string)
inlinestatic

Definition at line 2038 of file RelAlgDag.h.

References Delete, Insert, and Update.

2038  {
2039  if (op_string == "INSERT") {
2040  return ModifyOperation::Insert;
2041  } else if (op_string == "DELETE") {
2042  return ModifyOperation::Delete;
2043  } else if (op_string == "UPDATE") {
2044  return ModifyOperation::Update;
2045  }
2046 
2047  throw std::runtime_error(
2048  std::string("Unsupported logical modify operation encountered " + op_string));
2049  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 2024 of file RelAlgDag.h.

References Delete, Insert, and Update.

Referenced by toHash(), and toString().

2024  {
2025  switch (op) {
2027  return "DELETE";
2029  return "INSERT";
2031  return "UPDATE";
2032  default:
2033  break;
2034  }
2035  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
2036  }

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend struct RelAlgDagSerializer
friend

Definition at line 2221 of file RelAlgDag.h.

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 2215 of file RelAlgDag.h.

Referenced by applyUpdateModificationsToInputNode().

bool RelModify::flattened_
private

Definition at line 2217 of file RelAlgDag.h.

Referenced by isFlattened(), toHash(), and toString().

ModifyOperation RelModify::operation_
private

Definition at line 2218 of file RelAlgDag.h.

Referenced by getOperation(), toHash(), and toString().

const TableDescriptor* RelModify::table_descriptor_
private
TargetColumnList RelModify::target_column_list_
private

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