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

#include <RelAlgAbstractInterpreter.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 ()
 
virtual ~RelAlgNode ()
 
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
std::vector< std::shared_ptr
< const RelAlgNode > > 
inputs_
 
const unsigned id_
 

Detailed Description

Definition at line 1199 of file RelAlgAbstractInterpreter.h.

Member Typedef Documentation

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

Definition at line 1202 of file RelAlgAbstractInterpreter.h.

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

Definition at line 1203 of file RelAlgAbstractInterpreter.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 1201 of file RelAlgAbstractInterpreter.h.

1201 { 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 1232 of file RelAlgAbstractInterpreter.h.

References RelAlgNode::inputs_.

1238  : catalog_(cat)
1239  , table_descriptor_(td)
1240  , flattened_(flattened)
1241  , operation_(yieldModifyOperationEnum(op_string))
1242  , target_column_list_(target_column_list) {
1243  inputs_.push_back(input);
1244  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
const TableDescriptor * table_descriptor_
Catalog_Namespace::Catalog const & catalog_
static ModifyOperation yieldModifyOperationEnum(std::string const &op_string)
ModifyOperation operation_
TargetColumnList target_column_list_
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 1246 of file RelAlgAbstractInterpreter.h.

References RelAlgNode::inputs_.

1252  : catalog_(cat)
1253  , table_descriptor_(td)
1254  , flattened_(flattened)
1255  , operation_(op)
1256  , target_column_list_(target_column_list) {
1257  inputs_.push_back(input);
1258  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
const TableDescriptor * table_descriptor_
Catalog_Namespace::Catalog const & catalog_
ModifyOperation operation_
TargetColumnList target_column_list_

Member Function Documentation

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 1349 of file RelAlgAbstractInterpreter.h.

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

1349  {
1350  RelProject const* previous_project_node =
1351  dynamic_cast<RelProject const*>(inputs_[0].get());
1352  CHECK(previous_project_node != nullptr);
1353  previous_project_node->setDeleteViaSelectFlag();
1354  previous_project_node->injectOffsetInFragmentExpr();
1355  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1356  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
CHECK(cgen_state)
const TableDescriptor * table_descriptor_
void setModifiedTableDescriptor(TableDescriptor const *td) const
void injectOffsetInFragmentExpr() const

+ Here is the call graph for this function:

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 1287 of file RelAlgAbstractInterpreter.h.

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

1287  {
1288  RelProject const* previous_project_node =
1289  dynamic_cast<RelProject const*>(inputs_[0].get());
1290  CHECK(previous_project_node != nullptr);
1291 
1292  previous_project_node->setUpdateViaSelectFlag();
1293  // remove the offset column in the projection for update handling
1294  target_column_list_.pop_back();
1295 
1296  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1297  previous_project_node->setTargetColumns(target_column_list_);
1298 
1299  int target_update_column_expr_start = 0;
1300  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
1301  CHECK(target_update_column_expr_start >= 0);
1302  CHECK(target_update_column_expr_end >= 0);
1303 
1304  bool varlen_update_required = false;
1305 
1306  auto varlen_scan_visitor = [this,
1307  &varlen_update_required,
1308  target_update_column_expr_start,
1309  target_update_column_expr_end](int index) {
1310  if (index >= target_update_column_expr_start &&
1311  index <= target_update_column_expr_end) {
1312  auto target_index = index - target_update_column_expr_start;
1313 
1314  auto* column_desc = catalog_.getMetadataForColumn(
1316  CHECK(column_desc);
1317 
1318  if (table_descriptor_->nShards) {
1319  const auto shard_cd =
1321  CHECK(shard_cd);
1322  if ((column_desc->columnName == shard_cd->columnName)) {
1323  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
1324  }
1325  }
1326 
1327  // Check for valid types
1328  if (is_feature_enabled<VarlenUpdates>()) {
1329  if (column_desc->columnType.is_varlen()) {
1330  varlen_update_required = true;
1331  }
1332 
1333  if (column_desc->columnType.is_geometry()) {
1334  throw std::runtime_error("UPDATE of a geo column is unsupported.");
1335  }
1336  } else {
1337  if (column_desc->columnType.is_varlen()) {
1338  throw std::runtime_error(
1339  "UPDATE of a none-encoded string, geo, or array column is unsupported.");
1340  }
1341  }
1342  }
1343  };
1344 
1345  previous_project_node->visitScalarExprs(varlen_scan_visitor);
1346  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
1347  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
void setVarlenUpdateRequired(bool required) const
void setTargetColumns(ColumnNameList const &target_columns) const
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:2881
CHECK(cgen_state)
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
TargetColumnList target_column_list_

+ Here is the call graph for this function:

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

Implements RelAlgNode.

Definition at line 1267 of file RelAlgAbstractInterpreter.h.

References catalog_(), and RelAlgNode::inputs_.

1267  {
1268  return std::make_shared<RelModify>(catalog_,
1270  flattened_,
1271  operation_,
1273  inputs_[0]);
1274  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
const TableDescriptor * table_descriptor_
Catalog_Namespace::Catalog const & catalog_
ModifyOperation operation_
TargetColumnList target_column_list_

+ Here is the call graph for this function:

ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 1262 of file RelAlgAbstractInterpreter.h.

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

Definition at line 1260 of file RelAlgAbstractInterpreter.h.

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

Definition at line 1264 of file RelAlgAbstractInterpreter.h.

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

Definition at line 1263 of file RelAlgAbstractInterpreter.h.

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

Definition at line 1261 of file RelAlgAbstractInterpreter.h.

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

Implements RelAlgNode.

Definition at line 1266 of file RelAlgAbstractInterpreter.h.

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

Implements RelAlgNode.

Definition at line 1276 of file RelAlgAbstractInterpreter.h.

References to_string().

1276  {
1277  std::ostringstream result_stream;
1278  result_stream << std::boolalpha
1279  << "(RelModify<" + std::to_string(reinterpret_cast<uint64_t>(this)) +
1280  "> "
1281  << table_descriptor_->tableName << " flattened= " << flattened_
1282  << " operation= " << yieldModifyOperationString(operation_) << ")";
1283 
1284  return result_stream.str();
1285  }
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:

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

Definition at line 1219 of file RelAlgAbstractInterpreter.h.

1219  {
1220  if (op_string == "INSERT") {
1221  return ModifyOperation::Insert;
1222  } else if (op_string == "DELETE") {
1223  return ModifyOperation::Delete;
1224  } else if (op_string == "UPDATE") {
1225  return ModifyOperation::Update;
1226  }
1227 
1228  throw std::runtime_error(
1229  std::string("Unsupported logical modify operation encountered " + op_string));
1230  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 1205 of file RelAlgAbstractInterpreter.h.

1205  {
1206  switch (op) {
1208  return "DELETE";
1210  return "INSERT";
1212  return "UPDATE";
1213  default:
1214  break;
1215  }
1216  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
1217  }

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 1359 of file RelAlgAbstractInterpreter.h.

bool RelModify::flattened_
private

Definition at line 1361 of file RelAlgAbstractInterpreter.h.

ModifyOperation RelModify::operation_
private

Definition at line 1362 of file RelAlgAbstractInterpreter.h.

const TableDescriptor* RelModify::table_descriptor_
private

Definition at line 1360 of file RelAlgAbstractInterpreter.h.

TargetColumnList RelModify::target_column_list_
private

Definition at line 1363 of file RelAlgAbstractInterpreter.h.


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