From cd892de3007b9d2211b10c18439ec9edc63cb707 Mon Sep 17 00:00:00 2001 From: hnwyllmm Date: Tue, 5 Jul 2022 13:38:36 +0800 Subject: [PATCH] use Field instead of FieldDesc in select_stmt --- src/observer/sql/executor/execute_stage.cpp | 4 ++-- src/observer/sql/operator/project_operator.h | 2 +- src/observer/sql/stmt/select_stmt.cpp | 10 +++++----- src/observer/sql/stmt/select_stmt.h | 15 +++------------ 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/observer/sql/executor/execute_stage.cpp b/src/observer/sql/executor/execute_stage.cpp index dfdc4f0..acbd040 100644 --- a/src/observer/sql/executor/execute_stage.cpp +++ b/src/observer/sql/executor/execute_stage.cpp @@ -266,8 +266,8 @@ RC ExecuteStage::do_select(SQLStageEvent *sql_event) pred_oper.add_child(&table_scan_operator); ProjectOperator project_oper; project_oper.add_child(&pred_oper); - for (const FieldDesc &field : select_stmt->query_fields()) { - project_oper.add_projection(field.table_, field.field_meta_); + for (const Field &field : select_stmt->query_fields()) { + project_oper.add_projection(field.table(), field.meta()); } rc = project_oper.open(); if (rc != RC::SUCCESS) { diff --git a/src/observer/sql/operator/project_operator.h b/src/observer/sql/operator/project_operator.h index 64e9d99..b0fefea 100644 --- a/src/observer/sql/operator/project_operator.h +++ b/src/observer/sql/operator/project_operator.h @@ -25,7 +25,7 @@ public: virtual ~ProjectOperator() = default; - void add_projection(const Table *table, const FieldMeta *field); // TODO how to handle the memory in tupleCellSpec? + void add_projection(const Table *table, const FieldMeta *field); RC open() override; RC next() override; diff --git a/src/observer/sql/stmt/select_stmt.cpp b/src/observer/sql/stmt/select_stmt.cpp index 4bc7dfe..a8eca82 100644 --- a/src/observer/sql/stmt/select_stmt.cpp +++ b/src/observer/sql/stmt/select_stmt.cpp @@ -27,12 +27,12 @@ SelectStmt::~SelectStmt() } } -static void wildcard_fields(Table *table, std::vector &field_metas) +static void wildcard_fields(Table *table, std::vector &field_metas) { const TableMeta &table_meta = table->table_meta(); const int field_num = table_meta.field_num(); for (int i = table_meta.sys_field_num(); i < field_num; i++) { - field_metas.push_back(FieldDesc(table, table_meta.field(i))); + field_metas.push_back(Field(table, table_meta.field(i))); } } @@ -64,7 +64,7 @@ RC SelectStmt::create(Db *db, const Selects &select_sql, Stmt *&stmt) } // collect query fields in `select` statement - std::vector query_fields; + std::vector query_fields; for (int i = select_sql.attr_num - 1; i >= 0; i--) { const RelAttr &relation_attr = select_sql.attributes[i]; @@ -102,7 +102,7 @@ RC SelectStmt::create(Db *db, const Selects &select_sql, Stmt *&stmt) return RC::SCHEMA_FIELD_MISSING; } - query_fields.push_back(FieldDesc(table, field_meta)); + query_fields.push_back(Field(table, field_meta)); } } } else { @@ -118,7 +118,7 @@ RC SelectStmt::create(Db *db, const Selects &select_sql, Stmt *&stmt) return RC::SCHEMA_FIELD_MISSING; } - query_fields.push_back(FieldDesc(table, field_meta)); + query_fields.push_back(Field(table, field_meta)); } } diff --git a/src/observer/sql/stmt/select_stmt.h b/src/observer/sql/stmt/select_stmt.h index 6d8fa3c..6d18bc7 100644 --- a/src/observer/sql/stmt/select_stmt.h +++ b/src/observer/sql/stmt/select_stmt.h @@ -18,22 +18,13 @@ See the Mulan PSL v2 for more details. */ #include "rc.h" #include "sql/stmt/stmt.h" +#include "storage/common/field.h" class FieldMeta; class FilterStmt; class Db; class Table; -// TODO better to create a field class -struct FieldDesc -{ - Table *table_ = nullptr; - const FieldMeta *field_meta_ = nullptr; - - FieldDesc() = default; - FieldDesc(Table *table, const FieldMeta *field_meta) : table_(table), field_meta_(field_meta) {} -}; - class SelectStmt : public Stmt { public: @@ -47,11 +38,11 @@ public: public: const std::vector &tables() const { return tables_; } - const std::vector &query_fields() const { return query_fields_; } + const std::vector &query_fields() const { return query_fields_; } FilterStmt *filter_stmt() const { return filter_stmt_; } private: - std::vector query_fields_; + std::vector query_fields_; std::vector
tables_; FilterStmt *filter_stmt_ = nullptr; }; -- GitLab