OmniSciDB  c1a53651b2
 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
 
const Catalog_Namespace::CataloggetCatalog () 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 2038 of file RelAlgDag.h.

Member Typedef Documentation

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

Definition at line 2041 of file RelAlgDag.h.

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

Definition at line 2042 of file RelAlgDag.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 2040 of file RelAlgDag.h.

2040 { Insert, Delete, Update };

Constructor & Destructor Documentation

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

Definition at line 2072 of file RelAlgDag.h.

Referenced by toHash().

2073  : catalog_{cat}
2074  , table_descriptor_{td}
2075  , flattened_{false}
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2242
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2241
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2240
ModifyOperation operation_
Definition: RelAlgDag.h:2243

+ 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 2078 of file RelAlgDag.h.

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

2084  : catalog_(cat)
2085  , table_descriptor_(td)
2086  , flattened_(flattened)
2087  , operation_(yieldModifyOperationEnum(op_string))
2088  , target_column_list_(target_column_list) {
2090  inputs_.push_back(input);
2091  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2242
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2241
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2240
static ModifyOperation yieldModifyOperationEnum(std::string const &op_string)
Definition: RelAlgDag.h:2058
ModifyOperation operation_
Definition: RelAlgDag.h:2243
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2244
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 2093 of file RelAlgDag.h.

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

2099  : catalog_(cat)
2100  , table_descriptor_(td)
2101  , flattened_(flattened)
2102  , operation_(op)
2103  , target_column_list_(target_column_list) {
2105  inputs_.push_back(input);
2106  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2242
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2241
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2240
ModifyOperation operation_
Definition: RelAlgDag.h:2243
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2244
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

Member Function Documentation

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 2230 of file RelAlgDag.h.

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

2230  {
2231  auto previous_node = dynamic_cast<RelProject const*>(inputs_[0].get());
2232  CHECK(previous_node != nullptr);
2233  auto previous_project_node = const_cast<RelProject*>(previous_node);
2234  previous_project_node->setDeleteViaSelectFlag(true);
2235  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2236  previous_project_node->setModifiedTableCatalog(&catalog_);
2237  }
void setDeleteViaSelectFlag(bool required) const
Definition: RelAlgDag.h:1070
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2241
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2240
#define CHECK(condition)
Definition: Logger.h:291
RelAlgInputs inputs_
Definition: RelAlgDag.h:952

+ Here is the call graph for this function:

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 2162 of file RelAlgDag.h.

References catalog_, CHECK, TableDescriptor::fragmenter, Catalog_Namespace::Catalog::getMetadataForColumn(), Catalog_Namespace::Catalog::getShardColumnMetadataForTable(), RelAlgNode::inputs_, TableDescriptor::nShards, table_descriptor_, TableDescriptor::tableId, and target_column_list_.

2162  {
2163  auto previous_node = dynamic_cast<RelProject const*>(inputs_[0].get());
2164  CHECK(previous_node != nullptr);
2165  auto previous_project_node = const_cast<RelProject*>(previous_node);
2166 
2167  if (previous_project_node->hasWindowFunctionExpr()) {
2168  if (table_descriptor_->fragmenter->getNumFragments() > 1) {
2169  throw std::runtime_error(
2170  "UPDATE of a column of multi-fragmented table using window function not "
2171  "currently supported.");
2172  }
2173  if (table_descriptor_->nShards > 0) {
2174  throw std::runtime_error(
2175  "UPDATE of a column of sharded table using window function not "
2176  "currently supported.");
2177  }
2178  }
2179 
2180  previous_project_node->setUpdateViaSelectFlag(true);
2181  // remove the offset column in the projection for update handling
2182  target_column_list_.pop_back();
2183 
2184  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2185  previous_project_node->setTargetColumns(target_column_list_);
2186  previous_project_node->setModifiedTableCatalog(&catalog_);
2187 
2188  int target_update_column_expr_start = 0;
2189  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
2190  CHECK(target_update_column_expr_start >= 0);
2191  CHECK(target_update_column_expr_end >= 0);
2192 
2193  bool varlen_update_required = false;
2194 
2195  auto varlen_scan_visitor = [this,
2196  &varlen_update_required,
2197  target_update_column_expr_start,
2198  target_update_column_expr_end](int index) {
2199  if (index >= target_update_column_expr_start &&
2200  index <= target_update_column_expr_end) {
2201  auto target_index = index - target_update_column_expr_start;
2202 
2203  auto* column_desc = catalog_.getMetadataForColumn(
2205  CHECK(column_desc);
2206 
2207  if (table_descriptor_->nShards) {
2208  const auto shard_cd =
2210  CHECK(shard_cd);
2211  if ((column_desc->columnName == shard_cd->columnName)) {
2212  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
2213  }
2214  }
2215 
2216  // Check for valid types
2217  if (column_desc->columnType.is_varlen()) {
2218  varlen_update_required = true;
2219  }
2220  if (column_desc->columnType.is_geometry()) {
2221  throw std::runtime_error("UPDATE of a geo column is unsupported.");
2222  }
2223  }
2224  };
2225 
2226  previous_project_node->visitScalarExprs(varlen_scan_visitor);
2227  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
2228  }
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:4682
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2241
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2240
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define CHECK(condition)
Definition: Logger.h:291
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2244
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 2118 of file RelAlgDag.h.

2118  {
2119  return std::make_shared<RelModify>(*this);
2120  }
const Catalog_Namespace::Catalog& RelModify::getCatalog ( ) const
inline

Definition at line 2110 of file RelAlgDag.h.

References catalog_.

2110 { return catalog_; }
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2240
ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 2113 of file RelAlgDag.h.

References operation_.

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

Definition at line 2108 of file RelAlgDag.h.

References table_descriptor_.

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

Definition at line 2115 of file RelAlgDag.h.

References target_column_list_.

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

Definition at line 2114 of file RelAlgDag.h.

References target_column_list_.

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

Definition at line 2112 of file RelAlgDag.h.

References flattened_.

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

Implements RelAlgNode.

Definition at line 2117 of file RelAlgDag.h.

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

Implements RelAlgNode.

Definition at line 2148 of file RelAlgDag.h.

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

2148  {
2149  if (!hash_) {
2150  hash_ = typeid(RelModify).hash_code();
2151  boost::hash_combine(*hash_, table_descriptor_->tableName);
2152  boost::hash_combine(*hash_, flattened_);
2153  boost::hash_combine(*hash_, yieldModifyOperationString(operation_));
2154  boost::hash_combine(*hash_, ::toString(target_column_list_));
2155  for (auto& node : inputs_) {
2156  boost::hash_combine(*hash_, node->toHash());
2157  }
2158  }
2159  return *hash_;
2160  }
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:2122
bool flattened_
Definition: RelAlgDag.h:2242
RelModify(Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td)
Definition: RelAlgDag.h:2072
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2241
std::optional< size_t > hash_
Definition: RelAlgDag.h:955
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:2044
ModifyOperation operation_
Definition: RelAlgDag.h:2243
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2244
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 2122 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().

2123  {
2124  auto ret = cat(::typeName(this),
2125  "(",
2127  ", flattened=",
2129  ", op=",
2131  ", target_column_list=",
2133  if (!config.skip_input_nodes) {
2134  ret += ", inputs=", ::toString(inputs_);
2135  } else {
2136  ret += ", input node id={";
2137  for (auto& input : inputs_) {
2138  auto node_id_in_plan = input->getIdInPlanTree();
2139  auto node_id_str = node_id_in_plan ? std::to_string(*node_id_in_plan)
2140  : std::to_string(input->getId());
2141  ret += node_id_str + " ";
2142  }
2143  ret += "}";
2144  }
2145  return cat(ret, ")");
2146  }
std::string cat(Ts &&...args)
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:2122
bool flattened_
Definition: RelAlgDag.h:2242
std::string to_string(char const *&&v)
unsigned getId() const
Definition: RelAlgDag.h:880
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2241
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:2044
std::string typeName(const T *v)
Definition: toString.h:103
ModifyOperation operation_
Definition: RelAlgDag.h:2243
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2244
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 2058 of file RelAlgDag.h.

References Delete, Insert, and Update.

2058  {
2059  if (op_string == "INSERT") {
2060  return ModifyOperation::Insert;
2061  } else if (op_string == "DELETE") {
2062  return ModifyOperation::Delete;
2063  } else if (op_string == "UPDATE") {
2064  return ModifyOperation::Update;
2065  }
2066 
2067  throw std::runtime_error(
2068  std::string("Unsupported logical modify operation encountered " + op_string));
2069  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 2044 of file RelAlgDag.h.

References Delete, Insert, and Update.

Referenced by toHash(), and toString().

2044  {
2045  switch (op) {
2047  return "DELETE";
2049  return "INSERT";
2051  return "UPDATE";
2052  default:
2053  break;
2054  }
2055  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
2056  }

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend struct RelAlgDagSerializer
friend

Definition at line 2246 of file RelAlgDag.h.

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private
bool RelModify::flattened_
private

Definition at line 2242 of file RelAlgDag.h.

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

ModifyOperation RelModify::operation_
private

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