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

#include <RelAlgDagBuilder.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 constgetUpdateColumnNames () const
 
int getUpdateColumnCount () const
 
size_t size () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
std::string toString () 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
 
const std::vector
< TargetMetaInfo > & 
getOutputMetainfo () const
 
unsigned getId () 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 constcatalog_
 
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 > hash_
 

Detailed Description

Definition at line 1722 of file RelAlgDagBuilder.h.

Member Typedef Documentation

Definition at line 1725 of file RelAlgDagBuilder.h.

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

Definition at line 1726 of file RelAlgDagBuilder.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 1724 of file RelAlgDagBuilder.h.

1724 { 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 1755 of file RelAlgDagBuilder.h.

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

Referenced by toHash().

1761  : catalog_(cat)
1762  , table_descriptor_(td)
1763  , flattened_(flattened)
1764  , operation_(yieldModifyOperationEnum(op_string))
1765  , target_column_list_(target_column_list) {
1767  inputs_.push_back(input);
1768  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
const TableDescriptor * table_descriptor_
Catalog_Namespace::Catalog const & catalog_
static ModifyOperation yieldModifyOperationEnum(std::string const &op_string)
ModifyOperation operation_
TargetColumnList target_column_list_
RelAlgInputs inputs_

+ 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 1770 of file RelAlgDagBuilder.h.

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

1776  : catalog_(cat)
1777  , table_descriptor_(td)
1778  , flattened_(flattened)
1779  , operation_(op)
1780  , target_column_list_(target_column_list) {
1782  inputs_.push_back(input);
1783  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
const TableDescriptor * table_descriptor_
Catalog_Namespace::Catalog const & catalog_
ModifyOperation operation_
TargetColumnList target_column_list_
RelAlgInputs inputs_

+ Here is the call graph for this function:

Member Function Documentation

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 1884 of file RelAlgDagBuilder.h.

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

1884  {
1885  RelProject const* previous_project_node =
1886  dynamic_cast<RelProject const*>(inputs_[0].get());
1887  CHECK(previous_project_node != nullptr);
1888  previous_project_node->setDeleteViaSelectFlag();
1889  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1890  }
#define const
void setDeleteViaSelectFlag() const
const TableDescriptor * table_descriptor_
void setModifiedTableDescriptor(TableDescriptor const *td) const
#define CHECK(condition)
Definition: Logger.h:211
RelAlgInputs inputs_

+ Here is the call graph for this function:

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 1825 of file RelAlgDagBuilder.h.

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

1825  {
1826  RelProject const* previous_project_node =
1827  dynamic_cast<RelProject const*>(inputs_[0].get());
1828  CHECK(previous_project_node != nullptr);
1829 
1830  if (previous_project_node->hasWindowFunctionExpr()) {
1831  throw std::runtime_error(
1832  "UPDATE of a column using a window function is not currently supported.");
1833  }
1834 
1835  previous_project_node->setUpdateViaSelectFlag();
1836  // remove the offset column in the projection for update handling
1837  target_column_list_.pop_back();
1838 
1839  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1840  previous_project_node->setTargetColumns(target_column_list_);
1841 
1842  int target_update_column_expr_start = 0;
1843  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
1844  CHECK(target_update_column_expr_start >= 0);
1845  CHECK(target_update_column_expr_end >= 0);
1846 
1847  bool varlen_update_required = false;
1848 
1849  auto varlen_scan_visitor = [this,
1850  &varlen_update_required,
1851  target_update_column_expr_start,
1852  target_update_column_expr_end](int index) {
1853  if (index >= target_update_column_expr_start &&
1854  index <= target_update_column_expr_end) {
1855  auto target_index = index - target_update_column_expr_start;
1856 
1857  auto* column_desc = catalog_.getMetadataForColumn(
1859  CHECK(column_desc);
1860 
1861  if (table_descriptor_->nShards) {
1862  const auto shard_cd =
1864  CHECK(shard_cd);
1865  if ((column_desc->columnName == shard_cd->columnName)) {
1866  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
1867  }
1868  }
1869 
1870  // Check for valid types
1871  if (column_desc->columnType.is_varlen()) {
1872  varlen_update_required = true;
1873  }
1874  if (column_desc->columnType.is_geometry()) {
1875  throw std::runtime_error("UPDATE of a geo column is unsupported.");
1876  }
1877  }
1878  };
1879 
1880  previous_project_node->visitScalarExprs(varlen_scan_visitor);
1881  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
1882  }
void setVarlenUpdateRequired(bool required) const
void setTargetColumns(ColumnNameList const &target_columns) const
#define const
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:4107
const TableDescriptor * table_descriptor_
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
Catalog_Namespace::Catalog const & catalog_
void visitScalarExprs(EXPR_VISITOR_FUNCTOR visitor_functor) const
void setModifiedTableDescriptor(TableDescriptor const *td) const
bool hasWindowFunctionExpr() const
#define CHECK(condition)
Definition: Logger.h:211
void setUpdateViaSelectFlag() const
TargetColumnList target_column_list_
RelAlgInputs inputs_

+ Here is the call graph for this function:

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

Implements RelAlgNode.

Definition at line 1792 of file RelAlgDagBuilder.h.

1792  {
1793  return std::make_shared<RelModify>(*this);
1794  }
ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 1787 of file RelAlgDagBuilder.h.

References operation_.

1787 { return operation_; }
ModifyOperation operation_
TableDescriptor const* const RelModify::getTableDescriptor ( ) const
inline

Definition at line 1785 of file RelAlgDagBuilder.h.

References table_descriptor_.

1785 { return table_descriptor_; }
const TableDescriptor * table_descriptor_
int RelModify::getUpdateColumnCount ( ) const
inline

Definition at line 1789 of file RelAlgDagBuilder.h.

References target_column_list_.

1789 { return target_column_list_.size(); }
TargetColumnList target_column_list_
TargetColumnList const& RelModify::getUpdateColumnNames ( ) const
inline

Definition at line 1788 of file RelAlgDagBuilder.h.

References target_column_list_.

1788 { return target_column_list_; }
TargetColumnList target_column_list_
bool const RelModify::isFlattened ( ) const
inline

Definition at line 1786 of file RelAlgDagBuilder.h.

References flattened_.

1786 { return flattened_; }
size_t RelModify::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1791 of file RelAlgDagBuilder.h.

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

Implements RelAlgNode.

Definition at line 1811 of file RelAlgDagBuilder.h.

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

1811  {
1812  if (!hash_) {
1813  hash_ = typeid(RelModify).hash_code();
1814  boost::hash_combine(*hash_, table_descriptor_->tableName);
1815  boost::hash_combine(*hash_, flattened_);
1816  boost::hash_combine(*hash_, yieldModifyOperationString(operation_));
1817  boost::hash_combine(*hash_, ::toString(target_column_list_));
1818  for (auto& node : inputs_) {
1819  boost::hash_combine(*hash_, node->toHash());
1820  }
1821  }
1822  return *hash_;
1823  }
std::string toString() const override
std::string tableName
const TableDescriptor * table_descriptor_
std::optional< size_t > hash_
static std::string yieldModifyOperationString(ModifyOperation const op)
ModifyOperation operation_
TargetColumnList target_column_list_
RelModify(Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td, bool flattened, std::string const &op_string, TargetColumnList const &target_column_list, RelAlgNodeInputPtr input)
RelAlgInputs inputs_

+ Here is the call graph for this function:

std::string RelModify::toString ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1796 of file RelAlgDagBuilder.h.

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

Referenced by toHash().

1796  {
1797  return cat(::typeName(this),
1798  "(",
1800  ", flattened=",
1802  ", op=",
1804  ", target_column_list=",
1806  ", inputs=",
1807  ::toString(inputs_),
1808  ")");
1809  }
std::string toString() const override
std::string cat(Ts &&...args)
std::string tableName
std::string to_string(char const *&&v)
const TableDescriptor * table_descriptor_
static std::string yieldModifyOperationString(ModifyOperation const op)
std::string typeName(const T *v)
Definition: toString.h:93
ModifyOperation operation_
TargetColumnList target_column_list_
RelAlgInputs inputs_

+ 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 1742 of file RelAlgDagBuilder.h.

References Delete, Insert, and Update.

1742  {
1743  if (op_string == "INSERT") {
1744  return ModifyOperation::Insert;
1745  } else if (op_string == "DELETE") {
1746  return ModifyOperation::Delete;
1747  } else if (op_string == "UPDATE") {
1748  return ModifyOperation::Update;
1749  }
1750 
1751  throw std::runtime_error(
1752  std::string("Unsupported logical modify operation encountered " + op_string));
1753  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 1728 of file RelAlgDagBuilder.h.

References Delete, Insert, and Update.

Referenced by toHash(), and toString().

1728  {
1729  switch (op) {
1731  return "DELETE";
1733  return "INSERT";
1735  return "UPDATE";
1736  default:
1737  break;
1738  }
1739  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
1740  }

+ Here is the caller graph for this function:

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 1893 of file RelAlgDagBuilder.h.

Referenced by applyUpdateModificationsToInputNode().

bool RelModify::flattened_
private

Definition at line 1895 of file RelAlgDagBuilder.h.

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

ModifyOperation RelModify::operation_
private

Definition at line 1896 of file RelAlgDagBuilder.h.

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

TargetColumnList RelModify::target_column_list_
private

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