OmniSciDB  8a228a1076
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 const & getUpdateColumnNames ()
 
int getUpdateColumnCount () const
 
size_t size () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
std::string toString () const override
 
void applyUpdateModificationsToInputNode ()
 
void applyDeleteModificationsToInputNode ()
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode (RelAlgInputs inputs={})
 
virtual ~RelAlgNode ()
 
void resetQueryExecutionState ()
 
void setContextData (const void *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 void * getContextData () 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)
 
bool isNop () const
 
void markAsNop ()
 

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_
 

Detailed Description

Definition at line 1453 of file RelAlgDagBuilder.h.

Member Typedef Documentation

◆ RelAlgNodeInputPtr

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

Definition at line 1456 of file RelAlgDagBuilder.h.

◆ TargetColumnList

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

Definition at line 1457 of file RelAlgDagBuilder.h.

Member Enumeration Documentation

◆ ModifyOperation

Enumerator
Insert 
Delete 
Update 

Definition at line 1455 of file RelAlgDagBuilder.h.

1455 { Insert, Delete, Update };

Constructor & Destructor Documentation

◆ RelModify() [1/2]

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

References foreign_storage::validate_non_foreign_table_write().

1492  : catalog_(cat)
1493  , table_descriptor_(td)
1494  , flattened_(flattened)
1495  , operation_(yieldModifyOperationEnum(op_string))
1496  , target_column_list_(target_column_list) {
1498  inputs_.push_back(input);
1499  }
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:

◆ RelModify() [2/2]

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

References foreign_storage::validate_non_foreign_table_write().

1507  : catalog_(cat)
1508  , table_descriptor_(td)
1509  , flattened_(flattened)
1510  , operation_(op)
1511  , target_column_list_(target_column_list) {
1513  inputs_.push_back(input);
1514  }
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

◆ applyDeleteModificationsToInputNode()

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 1592 of file RelAlgDagBuilder.h.

References CHECK, ModifyManipulationTarget::setDeleteViaSelectFlag(), and ModifyManipulationTarget::setModifiedTableDescriptor().

1592  {
1593  RelProject const* previous_project_node =
1594  dynamic_cast<RelProject const*>(inputs_[0].get());
1595  CHECK(previous_project_node != nullptr);
1596  previous_project_node->setDeleteViaSelectFlag();
1597  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1598  }
void setModifiedTableDescriptor(TableDescriptor const *td) const
void setDeleteViaSelectFlag() const
const TableDescriptor * table_descriptor_
#define CHECK(condition)
Definition: Logger.h:197
RelAlgInputs inputs_
+ Here is the call graph for this function:

◆ applyUpdateModificationsToInputNode()

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 1538 of file RelAlgDagBuilder.h.

References CHECK, ModifyManipulationTarget::setModifiedTableDescriptor(), ModifyManipulationTarget::setTargetColumns(), ModifyManipulationTarget::setUpdateViaSelectFlag(), ModifyManipulationTarget::setVarlenUpdateRequired(), and RelProject::visitScalarExprs().

1538  {
1539  RelProject const* previous_project_node =
1540  dynamic_cast<RelProject const*>(inputs_[0].get());
1541  CHECK(previous_project_node != nullptr);
1542 
1543  previous_project_node->setUpdateViaSelectFlag();
1544  // remove the offset column in the projection for update handling
1545  target_column_list_.pop_back();
1546 
1547  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1548  previous_project_node->setTargetColumns(target_column_list_);
1549 
1550  int target_update_column_expr_start = 0;
1551  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
1552  CHECK(target_update_column_expr_start >= 0);
1553  CHECK(target_update_column_expr_end >= 0);
1554 
1555  bool varlen_update_required = false;
1556 
1557  auto varlen_scan_visitor = [this,
1558  &varlen_update_required,
1559  target_update_column_expr_start,
1560  target_update_column_expr_end](int index) {
1561  if (index >= target_update_column_expr_start &&
1562  index <= target_update_column_expr_end) {
1563  auto target_index = index - target_update_column_expr_start;
1564 
1565  auto* column_desc = catalog_.getMetadataForColumn(
1567  CHECK(column_desc);
1568 
1569  if (table_descriptor_->nShards) {
1570  const auto shard_cd =
1572  CHECK(shard_cd);
1573  if ((column_desc->columnName == shard_cd->columnName)) {
1574  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
1575  }
1576  }
1577 
1578  // Check for valid types
1579  if (column_desc->columnType.is_varlen()) {
1580  varlen_update_required = true;
1581  }
1582  if (column_desc->columnType.is_geometry()) {
1583  throw std::runtime_error("UPDATE of a geo column is unsupported.");
1584  }
1585  }
1586  };
1587 
1588  previous_project_node->visitScalarExprs(varlen_scan_visitor);
1589  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
1590  }
void setTargetColumns(ColumnNameList const &target_columns) const
void setModifiedTableDescriptor(TableDescriptor const *td) const
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
void setUpdateViaSelectFlag() const
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:3489
const TableDescriptor * table_descriptor_
Catalog_Namespace::Catalog const & catalog_
#define CHECK(condition)
Definition: Logger.h:197
void setVarlenUpdateRequired(bool required) const
TargetColumnList target_column_list_
void visitScalarExprs(EXPR_VISITOR_FUNCTOR visitor_functor) const
RelAlgInputs inputs_
+ Here is the call graph for this function:

◆ deepCopy()

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

Implements RelAlgNode.

Definition at line 1523 of file RelAlgDagBuilder.h.

1523  {
1524  return std::make_shared<RelModify>(*this);
1525  }

◆ getOperation()

ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 1518 of file RelAlgDagBuilder.h.

1518 { return operation_; }
ModifyOperation operation_

◆ getTableDescriptor()

TableDescriptor const* const RelModify::getTableDescriptor ( ) const
inline

Definition at line 1516 of file RelAlgDagBuilder.h.

1516 { return table_descriptor_; }
const TableDescriptor * table_descriptor_

◆ getUpdateColumnCount()

int RelModify::getUpdateColumnCount ( ) const
inline

Definition at line 1520 of file RelAlgDagBuilder.h.

1520 { return target_column_list_.size(); }
TargetColumnList target_column_list_

◆ getUpdateColumnNames()

TargetColumnList const& RelModify::getUpdateColumnNames ( )
inline

Definition at line 1519 of file RelAlgDagBuilder.h.

1519 { return target_column_list_; }
TargetColumnList target_column_list_

◆ isFlattened()

bool const RelModify::isFlattened ( ) const
inline

Definition at line 1517 of file RelAlgDagBuilder.h.

1517 { return flattened_; }

◆ size()

size_t RelModify::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1522 of file RelAlgDagBuilder.h.

1522 { return 0; }

◆ toString()

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

Implements RelAlgNode.

Definition at line 1527 of file RelAlgDagBuilder.h.

References to_string().

1527  {
1528  std::ostringstream result_stream;
1529  result_stream << std::boolalpha
1530  << "(RelModify<" + std::to_string(reinterpret_cast<uint64_t>(this)) +
1531  "> "
1532  << table_descriptor_->tableName << " flattened= " << flattened_
1533  << " operation= " << yieldModifyOperationString(operation_) << ")";
1534 
1535  return result_stream.str();
1536  }
std::string tableName
std::string to_string(char const *&&v)
const TableDescriptor * table_descriptor_
static std::string yieldModifyOperationString(ModifyOperation const op)
ModifyOperation operation_
+ Here is the call graph for this function:

◆ yieldModifyOperationEnum()

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

Definition at line 1473 of file RelAlgDagBuilder.h.

1473  {
1474  if (op_string == "INSERT") {
1475  return ModifyOperation::Insert;
1476  } else if (op_string == "DELETE") {
1477  return ModifyOperation::Delete;
1478  } else if (op_string == "UPDATE") {
1479  return ModifyOperation::Update;
1480  }
1481 
1482  throw std::runtime_error(
1483  std::string("Unsupported logical modify operation encountered " + op_string));
1484  }

◆ yieldModifyOperationString()

static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 1459 of file RelAlgDagBuilder.h.

1459  {
1460  switch (op) {
1462  return "DELETE";
1464  return "INSERT";
1466  return "UPDATE";
1467  default:
1468  break;
1469  }
1470  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
1471  }

Member Data Documentation

◆ catalog_

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 1601 of file RelAlgDagBuilder.h.

◆ flattened_

bool RelModify::flattened_
private

Definition at line 1603 of file RelAlgDagBuilder.h.

◆ operation_

ModifyOperation RelModify::operation_
private

Definition at line 1604 of file RelAlgDagBuilder.h.

◆ table_descriptor_

const TableDescriptor* RelModify::table_descriptor_
private

Definition at line 1602 of file RelAlgDagBuilder.h.

◆ target_column_list_

TargetColumnList RelModify::target_column_list_
private

Definition at line 1605 of file RelAlgDagBuilder.h.


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