-
Notifications
You must be signed in to change notification settings - Fork 4
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
19 changed files
with
247 additions
and
32 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ enum class PhysicalOperatorType | |
CALC, | ||
STRING_LIST, | ||
DELETE, | ||
UPDATE, | ||
INSERT, | ||
}; | ||
|
||
|
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,10 @@ | ||
#include "sql/operator/update_logical_operator.h" | ||
|
||
UpdateLogicalOperator::UpdateLogicalOperator(Table *table, Value value) : table_(table), value_(value) | ||
{} | ||
|
||
// UpdateLogicalOperator::~UpdateLogicalOperator() { | ||
// if (update_map_ != nullptr) { | ||
// delete update_map_; | ||
// } | ||
// } |
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,41 @@ | ||
#ifndef MINIOB_SQL_OPERATOR_UPDATE_LOGICAL_OPERATOR_H | ||
#define MINIOB_SQL_OPERATOR_UPDATE_LOGICAL_OPERATOR_H | ||
|
||
#include "sql/operator/logical_operator.h" | ||
#include "sql/parser/parse_defs.h" | ||
#include <unordered_map> | ||
|
||
/** | ||
* @brief 逻辑算子,用于执行delete语句 | ||
* @ingroup LogicalOperator | ||
*/ | ||
class UpdateLogicalOperator : public LogicalOperator { | ||
|
||
public: | ||
UpdateLogicalOperator(Table *table, Value value); | ||
|
||
~UpdateLogicalOperator() = default; | ||
|
||
LogicalOperatorType type() const override { | ||
return LogicalOperatorType::UPDATE; | ||
} | ||
|
||
inline Table * table() const { | ||
return table_; | ||
} | ||
|
||
inline Value& value() { | ||
return value_; | ||
} | ||
|
||
// const Value* find_value_by_field(const FieldMeta& field_meta) { | ||
// return &update_map_->at(field_meta); | ||
// } | ||
|
||
private: | ||
Table * table_ = nullptr; | ||
// std::unordered_map<FieldMeta, Value> *update_map_ = nullptr; // TODO 多字段更新 | ||
Value value_; | ||
}; | ||
|
||
#endif |
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,56 @@ | ||
#include "sql/operator/update_physical_operator.h" | ||
#include "storage/trx/trx.h" | ||
#include "storage/record/record.h" | ||
|
||
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::close() { | ||
if (!children_.empty()) { | ||
children_[0]->close(); | ||
} | ||
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; | ||
} |
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 @@ | ||
#ifndef MINIOB_UPDATE_PHYSICAL_OPERATOR_H | ||
#define MINIOB_UPDATE_PHYSICAL_OPERATOR_H | ||
|
||
#include "sql/operator/physical_operator.h" | ||
#include "sql/parser/parse.h" | ||
|
||
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_; | ||
Trx *trx_ = nullptr; | ||
}; | ||
|
||
#endif |
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
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
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
Oops, something went wrong.