OmniSciDB  cde582ebc3
 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 1858 of file RelAlgDag.h.

Member Typedef Documentation

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

Definition at line 1861 of file RelAlgDag.h.

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

Definition at line 1862 of file RelAlgDag.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 1860 of file RelAlgDag.h.

1860 { 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 1891 of file RelAlgDag.h.

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

Referenced by toHash().

1897  : catalog_(cat)
1898  , table_descriptor_(td)
1899  , flattened_(flattened)
1900  , operation_(yieldModifyOperationEnum(op_string))
1901  , target_column_list_(target_column_list) {
1903  inputs_.push_back(input);
1904  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2042
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2041
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2040
static ModifyOperation yieldModifyOperationEnum(std::string const &op_string)
Definition: RelAlgDag.h:1878
ModifyOperation operation_
Definition: RelAlgDag.h:2043
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2044
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 1906 of file RelAlgDag.h.

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

1912  : catalog_(cat)
1913  , table_descriptor_(td)
1914  , flattened_(flattened)
1915  , operation_(op)
1916  , target_column_list_(target_column_list) {
1918  inputs_.push_back(input);
1919  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2042
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2041
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2040
ModifyOperation operation_
Definition: RelAlgDag.h:2043
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2044
RelAlgInputs inputs_
Definition: RelAlgDag.h:886

+ Here is the call graph for this function:

Member Function Documentation

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 2031 of file RelAlgDag.h.

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

2031  {
2032  RelProject const* previous_project_node =
2033  dynamic_cast<RelProject const*>(inputs_[0].get());
2034  CHECK(previous_project_node != nullptr);
2035  previous_project_node->setDeleteViaSelectFlag();
2036  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2037  }
void setDeleteViaSelectFlag() const
Definition: RelAlgDag.h:988
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2041
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 1972 of file RelAlgDag.h.

References catalog_, CHECK, 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().

1972  {
1973  RelProject const* previous_project_node =
1974  dynamic_cast<RelProject const*>(inputs_[0].get());
1975  CHECK(previous_project_node != nullptr);
1976 
1977  if (previous_project_node->hasWindowFunctionExpr()) {
1978  throw std::runtime_error(
1979  "UPDATE of a column using a window function is not currently supported.");
1980  }
1981 
1982  previous_project_node->setUpdateViaSelectFlag();
1983  // remove the offset column in the projection for update handling
1984  target_column_list_.pop_back();
1985 
1986  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1987  previous_project_node->setTargetColumns(target_column_list_);
1988 
1989  int target_update_column_expr_start = 0;
1990  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
1991  CHECK(target_update_column_expr_start >= 0);
1992  CHECK(target_update_column_expr_end >= 0);
1993 
1994  bool varlen_update_required = false;
1995 
1996  auto varlen_scan_visitor = [this,
1997  &varlen_update_required,
1998  target_update_column_expr_start,
1999  target_update_column_expr_end](int index) {
2000  if (index >= target_update_column_expr_start &&
2001  index <= target_update_column_expr_end) {
2002  auto target_index = index - target_update_column_expr_start;
2003 
2004  auto* column_desc = catalog_.getMetadataForColumn(
2006  CHECK(column_desc);
2007 
2008  if (table_descriptor_->nShards) {
2009  const auto shard_cd =
2011  CHECK(shard_cd);
2012  if ((column_desc->columnName == shard_cd->columnName)) {
2013  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
2014  }
2015  }
2016 
2017  // Check for valid types
2018  if (column_desc->columnType.is_varlen()) {
2019  varlen_update_required = true;
2020  }
2021  if (column_desc->columnType.is_geometry()) {
2022  throw std::runtime_error("UPDATE of a geo column is unsupported.");
2023  }
2024  }
2025  };
2026 
2027  previous_project_node->visitScalarExprs(varlen_scan_visitor);
2028  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
2029  }
void setVarlenUpdateRequired(bool required) const
Definition: RelAlgDag.h:989
void setTargetColumns(ColumnNameList const &target_columns) const
Definition: RelAlgDag.h:1004
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:4583
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2041
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2040
void visitScalarExprs(EXPR_VISITOR_FUNCTOR visitor_functor) const
Definition: RelAlgDag.h:1155
void setModifiedTableDescriptor(TableDescriptor const *td) const
Definition: RelAlgDag.h:995
bool hasWindowFunctionExpr() const
Definition: RelAlgDag.cpp:2623
#define CHECK(condition)
Definition: Logger.h:222
void setUpdateViaSelectFlag() const
Definition: RelAlgDag.h:987
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2044
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 1928 of file RelAlgDag.h.

1928  {
1929  return std::make_shared<RelModify>(*this);
1930  }
ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 1923 of file RelAlgDag.h.

References operation_.

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

Definition at line 1921 of file RelAlgDag.h.

References table_descriptor_.

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

Definition at line 1925 of file RelAlgDag.h.

References target_column_list_.

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

Definition at line 1924 of file RelAlgDag.h.

References target_column_list_.

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

Definition at line 1922 of file RelAlgDag.h.

References flattened_.

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

Implements RelAlgNode.

Definition at line 1927 of file RelAlgDag.h.

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

Implements RelAlgNode.

Definition at line 1958 of file RelAlgDag.h.

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

1958  {
1959  if (!hash_) {
1960  hash_ = typeid(RelModify).hash_code();
1961  boost::hash_combine(*hash_, table_descriptor_->tableName);
1962  boost::hash_combine(*hash_, flattened_);
1963  boost::hash_combine(*hash_, yieldModifyOperationString(operation_));
1964  boost::hash_combine(*hash_, ::toString(target_column_list_));
1965  for (auto& node : inputs_) {
1966  boost::hash_combine(*hash_, node->toHash());
1967  }
1968  }
1969  return *hash_;
1970  }
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:1932
bool flattened_
Definition: RelAlgDag.h:2042
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2041
std::optional< size_t > hash_
Definition: RelAlgDag.h:889
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:1864
ModifyOperation operation_
Definition: RelAlgDag.h:2043
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2044
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:1891
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 1932 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().

1933  {
1934  auto ret = cat(::typeName(this),
1935  "(",
1937  ", flattened=",
1939  ", op=",
1941  ", target_column_list=",
1943  if (!config.skip_input_nodes) {
1944  ret += ", inputs=", ::toString(inputs_);
1945  } else {
1946  ret += ", input node id={";
1947  for (auto& input : inputs_) {
1948  auto node_id_in_plan = input->getIdInPlanTree();
1949  auto node_id_str = node_id_in_plan ? std::to_string(*node_id_in_plan)
1950  : std::to_string(input->getId());
1951  ret += node_id_str + " ";
1952  }
1953  ret += "}";
1954  }
1955  return cat(ret, ")");
1956  }
std::string cat(Ts &&...args)
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:1932
bool flattened_
Definition: RelAlgDag.h:2042
std::string to_string(char const *&&v)
unsigned getId() const
Definition: RelAlgDag.h:814
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2041
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:1864
std::string typeName(const T *v)
Definition: toString.h:102
ModifyOperation operation_
Definition: RelAlgDag.h:2043
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2044
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 1878 of file RelAlgDag.h.

References Delete, Insert, and Update.

1878  {
1879  if (op_string == "INSERT") {
1880  return ModifyOperation::Insert;
1881  } else if (op_string == "DELETE") {
1882  return ModifyOperation::Delete;
1883  } else if (op_string == "UPDATE") {
1884  return ModifyOperation::Update;
1885  }
1886 
1887  throw std::runtime_error(
1888  std::string("Unsupported logical modify operation encountered " + op_string));
1889  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 1864 of file RelAlgDag.h.

References Delete, Insert, and Update.

Referenced by toHash(), and toString().

1864  {
1865  switch (op) {
1867  return "DELETE";
1869  return "INSERT";
1871  return "UPDATE";
1872  default:
1873  break;
1874  }
1875  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
1876  }

+ Here is the caller graph for this function:

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 2040 of file RelAlgDag.h.

Referenced by applyUpdateModificationsToInputNode().

bool RelModify::flattened_
private

Definition at line 2042 of file RelAlgDag.h.

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

ModifyOperation RelModify::operation_
private

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