OmniSciDB  c0231cc57d
 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, 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 (const 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_
 

Additional Inherited Members

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

Detailed Description

Definition at line 1900 of file RelAlgDag.h.

Member Typedef Documentation

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

Definition at line 1903 of file RelAlgDag.h.

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

Definition at line 1904 of file RelAlgDag.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 1902 of file RelAlgDag.h.

1902 { Insert, Delete, Update };

Constructor & Destructor Documentation

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

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

Referenced by toHash().

1939  : catalog_(cat)
1940  , table_descriptor_(td)
1941  , flattened_(flattened)
1942  , operation_(yieldModifyOperationEnum(op_string))
1943  , target_column_list_(target_column_list) {
1945  inputs_.push_back(input);
1946  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2092
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2091
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2090
static ModifyOperation yieldModifyOperationEnum(std::string const &op_string)
Definition: RelAlgDag.h:1920
ModifyOperation operation_
Definition: RelAlgDag.h:2093
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2094
RelAlgInputs inputs_
Definition: RelAlgDag.h:886

+ Here is the call graph for this function:

+ Here is the caller 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 1948 of file RelAlgDag.h.

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

1954  : catalog_(cat)
1955  , table_descriptor_(td)
1956  , flattened_(flattened)
1957  , operation_(op)
1958  , target_column_list_(target_column_list) {
1960  inputs_.push_back(input);
1961  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2092
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2091
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2090
ModifyOperation operation_
Definition: RelAlgDag.h:2093
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2094
RelAlgInputs inputs_
Definition: RelAlgDag.h:886

+ Here is the call graph for this function:

Member Function Documentation

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 2081 of file RelAlgDag.h.

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

2081  {
2082  RelProject const* previous_project_node =
2083  dynamic_cast<RelProject const*>(inputs_[0].get());
2084  CHECK(previous_project_node != nullptr);
2085  previous_project_node->setDeleteViaSelectFlag(true);
2086  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2087  }
void setDeleteViaSelectFlag(bool required) const
Definition: RelAlgDag.h:988
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2091
void setModifiedTableDescriptor(TableDescriptor const *td) const
Definition: RelAlgDag.h:995
#define CHECK(condition)
Definition: Logger.h:222
RelAlgInputs inputs_
Definition: RelAlgDag.h:886

+ Here is the call graph for this function:

void RelModify::applyUpdateModificationsToInputNode ( )
inline

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

2014  {
2015  RelProject const* previous_project_node =
2016  dynamic_cast<RelProject const*>(inputs_[0].get());
2017  CHECK(previous_project_node != nullptr);
2018 
2019  if (previous_project_node->hasWindowFunctionExpr()) {
2020  if (table_descriptor_->fragmenter->getNumFragments() > 1) {
2021  throw std::runtime_error(
2022  "UPDATE of a column of multi-fragmented table using window function not "
2023  "currently supported.");
2024  }
2025  if (table_descriptor_->nShards > 0) {
2026  throw std::runtime_error(
2027  "UPDATE of a column of sharded table using window function not "
2028  "currently supported.");
2029  }
2030  }
2031 
2032  previous_project_node->setUpdateViaSelectFlag(true);
2033  // remove the offset column in the projection for update handling
2034  target_column_list_.pop_back();
2035 
2036  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2037  previous_project_node->setTargetColumns(target_column_list_);
2038 
2039  int target_update_column_expr_start = 0;
2040  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
2041  CHECK(target_update_column_expr_start >= 0);
2042  CHECK(target_update_column_expr_end >= 0);
2043 
2044  bool varlen_update_required = false;
2045 
2046  auto varlen_scan_visitor = [this,
2047  &varlen_update_required,
2048  target_update_column_expr_start,
2049  target_update_column_expr_end](int index) {
2050  if (index >= target_update_column_expr_start &&
2051  index <= target_update_column_expr_end) {
2052  auto target_index = index - target_update_column_expr_start;
2053 
2054  auto* column_desc = catalog_.getMetadataForColumn(
2056  CHECK(column_desc);
2057 
2058  if (table_descriptor_->nShards) {
2059  const auto shard_cd =
2061  CHECK(shard_cd);
2062  if ((column_desc->columnName == shard_cd->columnName)) {
2063  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
2064  }
2065  }
2066 
2067  // Check for valid types
2068  if (column_desc->columnType.is_varlen()) {
2069  varlen_update_required = true;
2070  }
2071  if (column_desc->columnType.is_geometry()) {
2072  throw std::runtime_error("UPDATE of a geo column is unsupported.");
2073  }
2074  }
2075  };
2076 
2077  previous_project_node->visitScalarExprs(varlen_scan_visitor);
2078  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
2079  }
void setVarlenUpdateRequired(bool required) const
Definition: RelAlgDag.h:989
void setTargetColumns(ColumnNameList const &target_columns) const
Definition: RelAlgDag.h:1007
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:4612
void setUpdateViaSelectFlag(bool required) const
Definition: RelAlgDag.h:987
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2091
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2090
void visitScalarExprs(EXPR_VISITOR_FUNCTOR visitor_functor) const
Definition: RelAlgDag.h:1196
void setModifiedTableDescriptor(TableDescriptor const *td) const
Definition: RelAlgDag.h:995
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
bool hasWindowFunctionExpr() const
Definition: RelAlgDag.cpp:2632
#define CHECK(condition)
Definition: Logger.h:222
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2094
RelAlgInputs inputs_
Definition: RelAlgDag.h:886

+ Here is the call graph for this function:

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

Implements RelAlgNode.

Definition at line 1970 of file RelAlgDag.h.

1970  {
1971  return std::make_shared<RelModify>(*this);
1972  }
ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 1965 of file RelAlgDag.h.

References operation_.

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

Definition at line 1963 of file RelAlgDag.h.

References table_descriptor_.

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

Definition at line 1967 of file RelAlgDag.h.

References target_column_list_.

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

Definition at line 1966 of file RelAlgDag.h.

References target_column_list_.

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

Definition at line 1964 of file RelAlgDag.h.

References flattened_.

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

Implements RelAlgNode.

Definition at line 1969 of file RelAlgDag.h.

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

Implements RelAlgNode.

Definition at line 2000 of file RelAlgDag.h.

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

2000  {
2001  if (!hash_) {
2002  hash_ = typeid(RelModify).hash_code();
2003  boost::hash_combine(*hash_, table_descriptor_->tableName);
2004  boost::hash_combine(*hash_, flattened_);
2005  boost::hash_combine(*hash_, yieldModifyOperationString(operation_));
2006  boost::hash_combine(*hash_, ::toString(target_column_list_));
2007  for (auto& node : inputs_) {
2008  boost::hash_combine(*hash_, node->toHash());
2009  }
2010  }
2011  return *hash_;
2012  }
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:1974
bool flattened_
Definition: RelAlgDag.h:2092
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2091
std::optional< size_t > hash_
Definition: RelAlgDag.h:889
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:1906
ModifyOperation operation_
Definition: RelAlgDag.h:2093
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2094
RelModify(Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td, bool flattened, std::string const &op_string, TargetColumnList const &target_column_list, RelAlgNodeInputPtr input)
Definition: RelAlgDag.h:1933
RelAlgInputs inputs_
Definition: RelAlgDag.h:886

+ Here is the call graph for this function:

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

Implements RelAlgNode.

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

1975  {
1976  auto ret = cat(::typeName(this),
1977  "(",
1979  ", flattened=",
1981  ", op=",
1983  ", target_column_list=",
1985  if (!config.skip_input_nodes) {
1986  ret += ", inputs=", ::toString(inputs_);
1987  } else {
1988  ret += ", input node id={";
1989  for (auto& input : inputs_) {
1990  auto node_id_in_plan = input->getIdInPlanTree();
1991  auto node_id_str = node_id_in_plan ? std::to_string(*node_id_in_plan)
1992  : std::to_string(input->getId());
1993  ret += node_id_str + " ";
1994  }
1995  ret += "}";
1996  }
1997  return cat(ret, ")");
1998  }
std::string cat(Ts &&...args)
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:1974
bool flattened_
Definition: RelAlgDag.h:2092
std::string to_string(char const *&&v)
unsigned getId() const
Definition: RelAlgDag.h:814
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2091
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:1906
std::string typeName(const T *v)
Definition: toString.h:103
ModifyOperation operation_
Definition: RelAlgDag.h:2093
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2094
RelAlgInputs inputs_
Definition: RelAlgDag.h:886

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

References Delete, Insert, and Update.

1920  {
1921  if (op_string == "INSERT") {
1922  return ModifyOperation::Insert;
1923  } else if (op_string == "DELETE") {
1924  return ModifyOperation::Delete;
1925  } else if (op_string == "UPDATE") {
1926  return ModifyOperation::Update;
1927  }
1928 
1929  throw std::runtime_error(
1930  std::string("Unsupported logical modify operation encountered " + op_string));
1931  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 1906 of file RelAlgDag.h.

References Delete, Insert, and Update.

Referenced by toHash(), and toString().

1906  {
1907  switch (op) {
1909  return "DELETE";
1911  return "INSERT";
1913  return "UPDATE";
1914  default:
1915  break;
1916  }
1917  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
1918  }

+ Here is the caller graph for this function:

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 2090 of file RelAlgDag.h.

Referenced by applyUpdateModificationsToInputNode().

bool RelModify::flattened_
private

Definition at line 2092 of file RelAlgDag.h.

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

ModifyOperation RelModify::operation_
private

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