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

#include <RelAlgDag.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)
 
 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)
 
virtual void acceptChildren (Visitor &v) const override
 
virtual void accept (Visitor &v, std::string name) const override
 
TableDescriptor const *const getTableDescriptor () const
 
const Catalog_Namespace::CataloggetCatalog () const
 
bool const isFlattened () const
 
ModifyOperation getOperation () const
 
TargetColumnList const & getUpdateColumnNames () const
 
int getUpdateColumnCount () const
 
size_t size () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
std::string toString (RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
 
void applyUpdateModificationsToInputNode ()
 
void applyDeleteModificationsToInputNode ()
 
virtual size_t toHash () const override
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode (RelAlgInputs inputs={})
 
virtual ~RelAlgNode ()
 
void resetQueryExecutionState ()
 
void setContextData (const RaExecutionDesc *context_data) const
 
void setOutputMetainfo (std::vector< TargetMetaInfo > targets_metainfo) const
 
void setQueryPlanDag (const std::string &extracted_query_plan_dag) const
 
std::string getQueryPlanDag () const
 
size_t getQueryPlanDagHash () 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
 
const std::vector< RelAlgNode
const * > 
getInputs () 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
 
- Public Member Functions inherited from RelAlgDagNode
 RelAlgDagNode ()
 
virtual size_t getStepNumber () const
 
virtual void setStepNumber (size_t step) const
 
std::optional< size_t > getIdInPlanTree () const
 
void setIdInPlanTree (size_t id) 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_
 

Friends

struct RelAlgDagSerializer
 
std::size_t hash_value (RelModify const &)
 

Additional Inherited Members

- Protected Attributes inherited from RelAlgNode
RelAlgInputs inputs_
 
unsigned id_
 
std::optional< size_t > hash_
 
- Protected Attributes inherited from RelAlgDagNode
size_t step_ {0}
 
std::optional< size_t > id_in_plan_tree_
 

Detailed Description

Definition at line 2287 of file RelAlgDag.h.

Member Typedef Documentation

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

Definition at line 2290 of file RelAlgDag.h.

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

Definition at line 2291 of file RelAlgDag.h.

Member Enumeration Documentation

Enumerator
Insert 
Delete 
Update 

Definition at line 2289 of file RelAlgDag.h.

2289 { Insert, Delete, Update };

Constructor & Destructor Documentation

RelModify::RelModify ( Catalog_Namespace::Catalog const &  cat,
TableDescriptor const *const  td 
)
inline

Definition at line 2321 of file RelAlgDag.h.

2322  : catalog_{cat}
2323  , table_descriptor_{td}
2324  , flattened_{false}
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2495
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2494
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2493
ModifyOperation operation_
Definition: RelAlgDag.h:2496
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 2327 of file RelAlgDag.h.

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

2333  : catalog_(cat)
2334  , table_descriptor_(td)
2335  , flattened_(flattened)
2336  , operation_(yieldModifyOperationEnum(op_string))
2337  , target_column_list_(target_column_list) {
2339  inputs_.push_back(input);
2340  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2495
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2494
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2493
static ModifyOperation yieldModifyOperationEnum(std::string const &op_string)
Definition: RelAlgDag.h:2307
ModifyOperation operation_
Definition: RelAlgDag.h:2496
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2497
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ 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 2342 of file RelAlgDag.h.

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

2348  : catalog_(cat)
2349  , table_descriptor_(td)
2350  , flattened_(flattened)
2351  , operation_(op)
2352  , target_column_list_(target_column_list) {
2354  inputs_.push_back(input);
2355  }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
std::string cat(Ts &&...args)
bool flattened_
Definition: RelAlgDag.h:2495
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2494
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2493
ModifyOperation operation_
Definition: RelAlgDag.h:2496
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2497
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the call graph for this function:

Member Function Documentation

virtual void RelModify::accept ( Visitor v,
std::string  name 
) const
inlineoverridevirtual

Implements RelAlgDagNode.

Definition at line 2364 of file RelAlgDag.h.

References acceptChildren(), and RelAlgDagNode::Visitor::visit().

Referenced by TableFunctionsFactory_node.PrintNode::__str__().

2364  {
2365  if (v.visit(this, std::move(name))) {
2366  acceptChildren(v);
2367  }
2368  }
virtual void acceptChildren(Visitor &v) const override
Definition: RelAlgDag.h:2357
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void RelModify::acceptChildren ( Visitor v) const
inlineoverridevirtual

Implements RelAlgDagNode.

Definition at line 2357 of file RelAlgDag.h.

References RelAlgNode::getInputs(), and anonymous_namespace{Utm.h}::n.

Referenced by accept().

2357  {
2358  for (auto& n : getInputs()) {
2359  if (n) {
2360  n->accept(v, "input");
2361  }
2362  }
2363  }
const std::vector< RelAlgNode const * > getInputs() const
Definition: RelAlgDag.h:882
constexpr double n
Definition: Utm.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelModify::applyDeleteModificationsToInputNode ( )
inline

Definition at line 2479 of file RelAlgDag.h.

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

2479  {
2480  auto previous_node = dynamic_cast<RelProject const*>(inputs_[0].get());
2481  CHECK(previous_node != nullptr);
2482  auto previous_project_node = const_cast<RelProject*>(previous_node);
2483  previous_project_node->setDeleteViaSelectFlag(true);
2484  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2485  previous_project_node->setModifiedTableCatalog(&catalog_);
2486  }
void setDeleteViaSelectFlag(bool required) const
Definition: RelAlgDag.h:1199
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2494
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2493
#define CHECK(condition)
Definition: Logger.h:291
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the call graph for this function:

void RelModify::applyUpdateModificationsToInputNode ( )
inline

Definition at line 2411 of file RelAlgDag.h.

References catalog_, CHECK, TableDescriptor::fragmenter, Catalog_Namespace::Catalog::getMetadataForColumn(), Catalog_Namespace::Catalog::getShardColumnMetadataForTable(), RelAlgNode::inputs_, TableDescriptor::nShards, table_descriptor_, TableDescriptor::tableId, and target_column_list_.

2411  {
2412  auto previous_node = dynamic_cast<RelProject const*>(inputs_[0].get());
2413  CHECK(previous_node != nullptr);
2414  auto previous_project_node = const_cast<RelProject*>(previous_node);
2415 
2416  if (previous_project_node->hasWindowFunctionExpr()) {
2417  if (table_descriptor_->fragmenter->getNumFragments() > 1) {
2418  throw std::runtime_error(
2419  "UPDATE of a column of multi-fragmented table using window function not "
2420  "currently supported.");
2421  }
2422  if (table_descriptor_->nShards > 0) {
2423  throw std::runtime_error(
2424  "UPDATE of a column of sharded table using window function not "
2425  "currently supported.");
2426  }
2427  }
2428 
2429  previous_project_node->setUpdateViaSelectFlag(true);
2430  // remove the offset column in the projection for update handling
2431  target_column_list_.pop_back();
2432 
2433  previous_project_node->setModifiedTableDescriptor(table_descriptor_);
2434  previous_project_node->setTargetColumns(target_column_list_);
2435  previous_project_node->setModifiedTableCatalog(&catalog_);
2436 
2437  int target_update_column_expr_start = 0;
2438  int target_update_column_expr_end = (int)(target_column_list_.size() - 1);
2439  CHECK(target_update_column_expr_start >= 0);
2440  CHECK(target_update_column_expr_end >= 0);
2441 
2442  bool varlen_update_required = false;
2443 
2444  auto varlen_scan_visitor = [this,
2445  &varlen_update_required,
2446  target_update_column_expr_start,
2447  target_update_column_expr_end](int index) {
2448  if (index >= target_update_column_expr_start &&
2449  index <= target_update_column_expr_end) {
2450  auto target_index = index - target_update_column_expr_start;
2451 
2452  auto* column_desc = catalog_.getMetadataForColumn(
2454  CHECK(column_desc);
2455 
2456  if (table_descriptor_->nShards) {
2457  const auto shard_cd =
2459  CHECK(shard_cd);
2460  if ((column_desc->columnName == shard_cd->columnName)) {
2461  throw std::runtime_error("UPDATE of a shard key is currently unsupported.");
2462  }
2463  }
2464 
2465  // Check for valid types
2466  if (column_desc->columnType.is_varlen()) {
2467  varlen_update_required = true;
2468  }
2469  if (column_desc->columnType.is_geometry()) {
2470  throw std::runtime_error("UPDATE of a geo column is unsupported.");
2471  }
2472  }
2473  };
2474 
2475  previous_project_node->visitScalarExprs(varlen_scan_visitor);
2476  previous_project_node->setVarlenUpdateRequired(varlen_update_required);
2477  }
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:4861
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2494
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2493
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define CHECK(condition)
Definition: Logger.h:291
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2497
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the call graph for this function:

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

Implements RelAlgNode.

Definition at line 2380 of file RelAlgDag.h.

2380  {
2381  return std::make_shared<RelModify>(*this);
2382  }
const Catalog_Namespace::Catalog& RelModify::getCatalog ( ) const
inline

Definition at line 2372 of file RelAlgDag.h.

References catalog_.

2372 { return catalog_; }
Catalog_Namespace::Catalog const & catalog_
Definition: RelAlgDag.h:2493
ModifyOperation RelModify::getOperation ( ) const
inline

Definition at line 2375 of file RelAlgDag.h.

References operation_.

2375 { return operation_; }
ModifyOperation operation_
Definition: RelAlgDag.h:2496
TableDescriptor const* const RelModify::getTableDescriptor ( ) const
inline

Definition at line 2370 of file RelAlgDag.h.

References table_descriptor_.

2370 { return table_descriptor_; }
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2494
int RelModify::getUpdateColumnCount ( ) const
inline

Definition at line 2377 of file RelAlgDag.h.

References target_column_list_.

2377 { return target_column_list_.size(); }
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2497
TargetColumnList const& RelModify::getUpdateColumnNames ( ) const
inline

Definition at line 2376 of file RelAlgDag.h.

References target_column_list_.

2376 { return target_column_list_; }
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2497
bool const RelModify::isFlattened ( ) const
inline

Definition at line 2374 of file RelAlgDag.h.

References flattened_.

2374 { return flattened_; }
bool flattened_
Definition: RelAlgDag.h:2495
size_t RelModify::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2379 of file RelAlgDag.h.

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

Implements RelAlgNode.

Definition at line 2488 of file RelAlgDag.h.

References hash_value.

2488 { return hash_value(*this); }
friend std::size_t hash_value(RelModify const &)
Definition: RelAlgDag.cpp:3804
std::string RelModify::toString ( RelRexToStringConfig  config = RelRexToStringConfig::defaults()) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2384 of file RelAlgDag.h.

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

2385  {
2386  auto ret = cat(::typeName(this),
2387  "(",
2389  ", flattened=",
2391  ", op=",
2393  ", target_column_list=",
2395 
2396  if (!config.skip_input_nodes) {
2397  ret += ", inputs=", ::toString(inputs_);
2398  } else {
2399  ret += ", input node id={";
2400  for (auto& input : inputs_) {
2401  auto node_id_in_plan = input->getIdInPlanTree();
2402  auto node_id_str = node_id_in_plan ? std::to_string(*node_id_in_plan)
2403  : std::to_string(input->getId());
2404  ret += node_id_str + " ";
2405  }
2406  ret += "}";
2407  }
2408  return cat(ret, ")");
2409  }
std::string cat(Ts &&...args)
std::string tableName
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:2384
bool flattened_
Definition: RelAlgDag.h:2495
std::string to_string(char const *&&v)
unsigned getId() const
Definition: RelAlgDag.h:869
const TableDescriptor * table_descriptor_
Definition: RelAlgDag.h:2494
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:2293
std::string typeName(const T *v)
Definition: toString.h:106
ModifyOperation operation_
Definition: RelAlgDag.h:2496
TargetColumnList target_column_list_
Definition: RelAlgDag.h:2497
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the call graph for this function:

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

Definition at line 2307 of file RelAlgDag.h.

References Delete, Insert, and Update.

2307  {
2308  if (op_string == "INSERT") {
2309  return ModifyOperation::Insert;
2310  } else if (op_string == "DELETE") {
2311  return ModifyOperation::Delete;
2312  } else if (op_string == "UPDATE") {
2313  return ModifyOperation::Update;
2314  }
2315 
2316  throw std::runtime_error(
2317  std::string("Unsupported logical modify operation encountered " + op_string));
2318  }
static std::string RelModify::yieldModifyOperationString ( ModifyOperation const  op)
inlinestatic

Definition at line 2293 of file RelAlgDag.h.

References Delete, Insert, and Update.

Referenced by hash_value(), and toString().

2293  {
2294  switch (op) {
2296  return "DELETE";
2298  return "INSERT";
2300  return "UPDATE";
2301  default:
2302  break;
2303  }
2304  throw std::runtime_error("Unexpected ModifyOperation enum encountered.");
2305  }

+ Here is the caller graph for this function:

Friends And Related Function Documentation

std::size_t hash_value ( RelModify const &  rel_modify)
friend

Definition at line 3804 of file RelAlgDag.cpp.

Referenced by toHash().

3804  {
3805  if (rel_modify.hash_) {
3806  return *rel_modify.hash_;
3807  }
3808  rel_modify.hash_ = typeid(RelModify).hash_code();
3809  boost::hash_combine(*rel_modify.hash_, rel_modify.table_descriptor_->tableName);
3810  boost::hash_combine(*rel_modify.hash_, rel_modify.table_descriptor_->tableId);
3811  boost::hash_combine(*rel_modify.hash_, rel_modify.flattened_);
3812  boost::hash_combine(*rel_modify.hash_,
3813  RelModify::yieldModifyOperationString(rel_modify.operation_));
3814  boost::hash_combine(*rel_modify.hash_, rel_modify.target_column_list_);
3815  boost::hash_combine(*rel_modify.hash_, rel_modify.inputs_);
3816  return *rel_modify.hash_;
3817 }
RelModify(Catalog_Namespace::Catalog const &cat, TableDescriptor const *const td)
Definition: RelAlgDag.h:2321
static std::string yieldModifyOperationString(ModifyOperation const op)
Definition: RelAlgDag.h:2293
friend struct RelAlgDagSerializer
friend

Definition at line 2499 of file RelAlgDag.h.

Member Data Documentation

Catalog_Namespace::Catalog const& RelModify::catalog_
private
bool RelModify::flattened_
private

Definition at line 2495 of file RelAlgDag.h.

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

ModifyOperation RelModify::operation_
private

Definition at line 2496 of file RelAlgDag.h.

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