OmniSciDB  bf83d84833
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 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 ()
 
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_
 

Detailed Description

Definition at line 1443 of file RelAlgDagBuilder.h.

Member Typedef Documentation

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

Definition at line 1446 of file RelAlgDagBuilder.h.

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

Definition at line 1447 of file RelAlgDagBuilder.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 1445 of file RelAlgDagBuilder.h.

1445 { 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 1476 of file RelAlgDagBuilder.h.

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

1482  : catalog_(cat)
1483  , table_descriptor_(td)
1484  , flattened_(flattened)
1485  , operation_(yieldModifyOperationEnum(op_string))
1486  , target_column_list_(target_column_list) {
1488  inputs_.push_back(input);
1489  }
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::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 1491 of file RelAlgDagBuilder.h.

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

1497  : catalog_(cat)
1498  , table_descriptor_(td)
1499  , flattened_(flattened)
1500  , operation_(op)
1501  , target_column_list_(target_column_list) {
1503  inputs_.push_back(input);
1504  }
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 1586 of file RelAlgDagBuilder.h.

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

1586  {
1587  RelProject const* previous_project_node =
1588  dynamic_cast<RelProject const*>(inputs_[0].get());
1589  CHECK(previous_project_node != nullptr);
1590  previous_project_node->setDeleteViaSelectFlag();
1591  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1592  }
void setDeleteViaSelectFlag() const
const TableDescriptor * table_descriptor_
void setModifiedTableDescriptor(TableDescriptor const *td) const
#define CHECK(condition)
Definition: Logger.h:197
RelAlgInputs inputs_

+ Here is the call graph for this function:

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 1532 of file RelAlgDagBuilder.h.

References catalog_, CHECK, Catalog_Namespace::Catalog::getMetadataForColumn(), Catalog_Namespace::Catalog::getShardColumnMetadataForTable(), RelAlgNode::inputs_, TableDescriptor::nShards, ModifyManipulationTarget::setModifiedTableDescriptor(), ModifyManipulationTarget::setTargetColumns(), ModifyManipulationTarget::setUpdateViaSelectFlag(), ModifyManipulationTarget::setVarlenUpdateRequired(), table_descriptor_, TableDescriptor::tableId, target_column_list_, and RelProject::visitScalarExprs().

1532  {
1533  RelProject const* previous_project_node =
1534  dynamic_cast<RelProject const*>(inputs_[0].get());
1535  CHECK(previous_project_node != nullptr);
1536 
1537  previous_project_node->setUpdateViaSelectFlag();
1538  // remove the offset column in the projection for update handling
1539  target_column_list_.pop_back();
1540 
1541  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1542  previous_project_node->setTargetColumns(target_column_list_);
1543 
1544  int target_update_column_expr_start = 0;
1545  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
1546  CHECK(target_update_column_expr_start >= 0);
1547  CHECK(target_update_column_expr_end >= 0);
1548 
1549  bool varlen_update_required = false;
1550 
1551  auto varlen_scan_visitor = [this,
1552  &varlen_update_required,
1553  target_update_column_expr_start,
1554  target_update_column_expr_end](int index) {
1555  if (index >= target_update_column_expr_start &&
1556  index <= target_update_column_expr_end) {
1557  auto target_index = index - target_update_column_expr_start;
1558 
1559  auto* column_desc = catalog_.getMetadataForColumn(
1561  CHECK(column_desc);
1562 
1563  if (table_descriptor_->nShards) {
1564  const auto shard_cd =
1566  CHECK(shard_cd);
1567  if ((column_desc->columnName == shard_cd->columnName)) {
1568  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
1569  }
1570  }
1571 
1572  // Check for valid types
1573  if (column_desc->columnType.is_varlen()) {
1574  varlen_update_required = true;
1575  }
1576  if (column_desc->columnType.is_geometry()) {
1577  throw std::runtime_error("UPDATE of a geo column is unsupported.");
1578  }
1579  }
1580  };
1581 
1582  previous_project_node->visitScalarExprs(varlen_scan_visitor);
1583  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
1584  }
void setVarlenUpdateRequired(bool required) const
void setTargetColumns(ColumnNameList const &target_columns) const
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:3768
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
#define CHECK(condition)
Definition: Logger.h:197
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 1513 of file RelAlgDagBuilder.h.

1513  {
1514  return std::make_shared<RelModify>(*this);
1515  }
ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 1508 of file RelAlgDagBuilder.h.

References operation_.

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

Definition at line 1506 of file RelAlgDagBuilder.h.

References table_descriptor_.

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

Definition at line 1510 of file RelAlgDagBuilder.h.

References target_column_list_.

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

Definition at line 1509 of file RelAlgDagBuilder.h.

References target_column_list_.

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

Definition at line 1507 of file RelAlgDagBuilder.h.

References flattened_.

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

Implements RelAlgNode.

Definition at line 1512 of file RelAlgDagBuilder.h.

1512 { return 0; }
std::string RelModify::toString ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1517 of file RelAlgDagBuilder.h.

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

1517  {
1518  return cat(::typeName(this),
1519  "(",
1521  ", flattened=",
1523  ", op=",
1525  ", target_column_list=",
1527  ", inputs=",
1528  ::toString(inputs_),
1529  ")");
1530  }
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)
ModifyOperation operation_
TargetColumnList target_column_list_
RelAlgInputs inputs_

+ Here is the call graph for this function:

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

Definition at line 1463 of file RelAlgDagBuilder.h.

References Delete, Insert, and Update.

1463  {
1464  if (op_string == "INSERT") {
1465  return ModifyOperation::Insert;
1466  } else if (op_string == "DELETE") {
1467  return ModifyOperation::Delete;
1468  } else if (op_string == "UPDATE") {
1469  return ModifyOperation::Update;
1470  }
1471 
1472  throw std::runtime_error(
1473  std::string("Unsupported logical modify operation encountered " + op_string));
1474  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 1449 of file RelAlgDagBuilder.h.

References Delete, Insert, and Update.

Referenced by toString().

1449  {
1450  switch (op) {
1452  return "DELETE";
1454  return "INSERT";
1456  return "UPDATE";
1457  default:
1458  break;
1459  }
1460  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
1461  }

+ Here is the caller graph for this function:

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 1595 of file RelAlgDagBuilder.h.

Referenced by applyUpdateModificationsToInputNode().

bool RelModify::flattened_
private

Definition at line 1597 of file RelAlgDagBuilder.h.

Referenced by isFlattened(), and toString().

ModifyOperation RelModify::operation_
private

Definition at line 1598 of file RelAlgDagBuilder.h.

Referenced by getOperation(), 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: