OmniSciDB  c07336695a
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 1192 of file RelAlgAbstractInterpreter.h.

Member Typedef Documentation

◆ RelAlgNodeInputPtr

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

Definition at line 1195 of file RelAlgAbstractInterpreter.h.

◆ TargetColumnList

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

Definition at line 1196 of file RelAlgAbstractInterpreter.h.

Member Enumeration Documentation

◆ ModifyOperation

Enumerator
Insert 
Delete 
Update 

Definition at line 1194 of file RelAlgAbstractInterpreter.h.

1194 { 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 1225 of file RelAlgAbstractInterpreter.h.

1231  : catalog_(cat)
1232  , table_descriptor_(td)
1233  , flattened_(flattened)
1234  , operation_(yieldModifyOperationEnum(op_string))
1235  , target_column_list_(target_column_list) {
1236  inputs_.push_back(input);
1237  }
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() [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 1239 of file RelAlgAbstractInterpreter.h.

1245  : catalog_(cat)
1246  , table_descriptor_(td)
1247  , flattened_(flattened)
1248  , operation_(op)
1249  , target_column_list_(target_column_list) {
1250  inputs_.push_back(input);
1251  }
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

◆ applyDeleteModificationsToInputNode()

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 1342 of file RelAlgAbstractInterpreter.h.

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

1342  {
1343  RelProject const* previous_project_node =
1344  dynamic_cast<RelProject const*>(inputs_[0].get());
1345  CHECK(previous_project_node != nullptr);
1346  previous_project_node->setDeleteViaSelectFlag();
1347  previous_project_node->injectOffsetInFragmentExpr();
1348  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1349  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
void setModifiedTableDescriptor(TableDescriptor const *td) const
const TableDescriptor * table_descriptor_
void injectOffsetInFragmentExpr() const
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ applyUpdateModificationsToInputNode()

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 1280 of file RelAlgAbstractInterpreter.h.

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

1280  {
1281  RelProject const* previous_project_node =
1282  dynamic_cast<RelProject const*>(inputs_[0].get());
1283  CHECK(previous_project_node != nullptr);
1284 
1285  previous_project_node->setUpdateViaSelectFlag();
1286  previous_project_node->injectOffsetInFragmentExpr();
1287  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
1288  previous_project_node->setTargetColumns(target_column_list_);
1289 
1290  int target_update_column_expr_start =
1291  (int)(previous_project_node->getFields().size() - target_column_list_.size() - 1);
1292  int target_update_column_expr_end =
1293  (int)(previous_project_node->getFields().size() - 2);
1294  CHECK(target_update_column_expr_start >= 0);
1295  CHECK(target_update_column_expr_end >= 0);
1296 
1297  bool varlen_update_required = false;
1298 
1299  auto varlen_scan_visitor = [this,
1300  &varlen_update_required,
1301  target_update_column_expr_start,
1302  target_update_column_expr_end](int index) {
1303  if (index >= target_update_column_expr_start &&
1304  index <= target_update_column_expr_end) {
1305  auto target_index = index - target_update_column_expr_start;
1306 
1307  auto* column_desc = catalog_.getMetadataForColumn(
1309  CHECK(column_desc);
1310 
1311  if (table_descriptor_->nShards) {
1312  const auto shard_cd =
1314  CHECK(shard_cd);
1315  if ((column_desc->columnName == shard_cd->columnName)) {
1316  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
1317  }
1318  }
1319 
1320  // Check for valid types
1321  if (is_feature_enabled<VarlenUpdates>()) {
1322  if (column_desc->columnType.is_varlen()) {
1323  varlen_update_required = true;
1324  }
1325 
1326  if (column_desc->columnType.is_geometry()) {
1327  throw std::runtime_error("UPDATE of a geo column is unsupported.");
1328  }
1329  } else {
1330  if (column_desc->columnType.is_varlen()) {
1331  throw std::runtime_error(
1332  "UPDATE of a none-encoded string, geo, or array column is unsupported.");
1333  }
1334  }
1335  }
1336  };
1337 
1338  previous_project_node->visitScalarExprs(varlen_scan_visitor);
1339  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
1340  }
std::vector< std::shared_ptr< const RelAlgNode > > inputs_
void setTargetColumns(ColumnNameList const &target_columns) const
void setModifiedTableDescriptor(TableDescriptor const *td) const
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:2879
const TableDescriptor * table_descriptor_
Catalog_Namespace::Catalog const & catalog_
void injectOffsetInFragmentExpr() const
#define CHECK(condition)
Definition: Logger.h:187
const std::vector< std::string > & getFields() const
void setVarlenUpdateRequired(bool required) const
TargetColumnList target_column_list_
void visitScalarExprs(EXPR_VISITOR_FUNCTOR visitor_functor) const
+ Here is the call graph for this function:

◆ deepCopy()

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

Implements RelAlgNode.

Definition at line 1260 of file RelAlgAbstractInterpreter.h.

Referenced by RelProject::toString().

1260  {
1261  return std::make_shared<RelModify>(catalog_,
1263  flattened_,
1264  operation_,
1266  inputs_[0]);
1267  }
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 caller graph for this function:

◆ getOperation()

ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 1255 of file RelAlgAbstractInterpreter.h.

1255 { return operation_; }
ModifyOperation operation_

◆ getTableDescriptor()

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

Definition at line 1253 of file RelAlgAbstractInterpreter.h.

1253 { return table_descriptor_; }
const TableDescriptor * table_descriptor_

◆ getUpdateColumnCount()

int RelModify::getUpdateColumnCount ( ) const
inline

Definition at line 1257 of file RelAlgAbstractInterpreter.h.

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

◆ getUpdateColumnNames()

TargetColumnList const& RelModify::getUpdateColumnNames ( )
inline

Definition at line 1256 of file RelAlgAbstractInterpreter.h.

1256 { return target_column_list_; }
TargetColumnList target_column_list_

◆ isFlattened()

bool const RelModify::isFlattened ( ) const
inline

Definition at line 1254 of file RelAlgAbstractInterpreter.h.

1254 { return flattened_; }

◆ size()

size_t RelModify::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 1259 of file RelAlgAbstractInterpreter.h.

1259 { return 0; }

◆ toString()

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

Implements RelAlgNode.

Definition at line 1269 of file RelAlgAbstractInterpreter.h.

References to_string().

1269  {
1270  std::ostringstream result_stream;
1271  result_stream << std::boolalpha
1272  << "(RelModify<" + std::to_string(reinterpret_cast<uint64_t>(this)) +
1273  "> "
1274  << table_descriptor_->tableName << " flattened= " << flattened_
1275  << " operation= " << yieldModifyOperationString(operation_) << ")";
1276 
1277  return result_stream.str();
1278  }
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 1212 of file RelAlgAbstractInterpreter.h.

1212  {
1213  if (op_string == "INSERT") {
1214  return ModifyOperation::Insert;
1215  } else if (op_string == "DELETE") {
1216  return ModifyOperation::Delete;
1217  } else if (op_string == "UPDATE") {
1218  return ModifyOperation::Update;
1219  }
1220 
1221  throw std::runtime_error(
1222  std::string("Unsupported logical modify operation encountered " + op_string));
1223  }

◆ yieldModifyOperationString()

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

Definition at line 1198 of file RelAlgAbstractInterpreter.h.

1198  {
1199  switch (op) {
1201  return "DELETE";
1203  return "INSERT";
1205  return "UPDATE";
1206  default:
1207  break;
1208  }
1209  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
1210  }

Member Data Documentation

◆ catalog_

Catalog_Namespace::Catalog const& RelModify::catalog_
private

Definition at line 1352 of file RelAlgAbstractInterpreter.h.

◆ flattened_

bool RelModify::flattened_
private

Definition at line 1354 of file RelAlgAbstractInterpreter.h.

◆ operation_

ModifyOperation RelModify::operation_
private

Definition at line 1355 of file RelAlgAbstractInterpreter.h.

◆ table_descriptor_

const TableDescriptor* RelModify::table_descriptor_
private

Definition at line 1353 of file RelAlgAbstractInterpreter.h.

◆ target_column_list_

TargetColumnList RelModify::target_column_list_
private

Definition at line 1356 of file RelAlgAbstractInterpreter.h.


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