-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ enum class PhysicalOperatorType | |
STRING_LIST, | ||
DELETE, | ||
INSERT, | ||
UPDATE, | ||
}; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "sql/operator/update_logical_operator.h" | ||
|
||
UpdateLogicalOperator::UpdateLogicalOperator(Table *table, Value *value) | ||
: table_(table), value_(value) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
|
||
#include "sql/operator/logical_operator.h" | ||
#include "sql/parser/parse_defs.h" | ||
|
||
class UpdateLogicalOperator : public LogicalOperator | ||
{ | ||
public: | ||
UpdateLogicalOperator(Table *table, Value* value); | ||
virtual ~UpdateLogicalOperator() = default; | ||
|
||
LogicalOperatorType type() const override | ||
{ | ||
return LogicalOperatorType::UPDATE; | ||
} | ||
|
||
Table *table() const { return table_; } | ||
const Value *values() const { return value_; } | ||
Value *values() { return value_; } | ||
|
||
private: | ||
Table *table_ = nullptr; | ||
Value* value_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "sql/operator/update_physical_operator.h" | ||
#include "sql/stmt/update_stmt.h" | ||
#include "storage/table/table.h" | ||
#include "storage/trx/trx.h" | ||
|
||
using namespace std; | ||
|
||
UpdatePhysicalOperator::UpdatePhysicalOperator(Table *table, Value *value) | ||
: table_(table), value_(value) | ||
{} | ||
RC UpdatePhysicalOperator::open(Trx *trx) | ||
{ | ||
if (children_.empty()) { | ||
return RC::SUCCESS; | ||
} | ||
|
||
std::unique_ptr<PhysicalOperator> &child = children_[0]; | ||
RC rc = child->open(trx); | ||
if (rc != RC::SUCCESS) { | ||
LOG_WARN("failed to open child operator: %s", strrc(rc)); | ||
return rc; | ||
} | ||
|
||
trx_ = trx; | ||
|
||
return RC::SUCCESS; | ||
} | ||
|
||
RC UpdatePhysicalOperator::next() | ||
{ | ||
RC rc = RC::SUCCESS; | ||
if (children_.empty()) { | ||
return RC::RECORD_EOF; | ||
} | ||
|
||
PhysicalOperator *child = children_[0].get(); | ||
while (RC::SUCCESS == (rc = child->next())) { | ||
Tuple *tuple = child->current_tuple(); | ||
if (nullptr == tuple) { | ||
LOG_WARN("failed to get current record: %s", strrc(rc)); | ||
return rc; | ||
} | ||
|
||
RowTuple *row_tuple = static_cast<RowTuple *>(tuple); | ||
Record &record = row_tuple->record(); | ||
rc = trx_->update_record(table_, record); | ||
if (rc != RC::SUCCESS) { | ||
LOG_WARN("failed to delete record: %s", strrc(rc)); | ||
return rc; | ||
} | ||
} | ||
|
||
return RC::RECORD_EOF; | ||
} | ||
|
||
RC UpdatePhysicalOperator::close() | ||
{ | ||
if (!children_.empty()) { | ||
children_[0]->close(); | ||
} | ||
return RC::SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include "sql/operator/physical_operator.h" | ||
#include "sql/parser/parse.h" | ||
|
||
class UpdateStmt; | ||
|
||
class UpdatePhysicalOperator : public PhysicalOperator | ||
{ | ||
public: | ||
UpdatePhysicalOperator(Table *table, Value *value); | ||
|
||
virtual ~UpdatePhysicalOperator() = default; | ||
|
||
PhysicalOperatorType type() const override | ||
{ | ||
return PhysicalOperatorType::UPDATE; | ||
} | ||
|
||
RC open(Trx *trx) override; | ||
RC next() override; | ||
RC close() override; | ||
|
||
Tuple *current_tuple() override { return nullptr; } | ||
|
||
private: | ||
Table *table_ = nullptr; | ||
Value *value_ = nullptr; | ||
Trx *trx_ = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters