diff --git a/src/observer/sql/executor/execute_stage.cpp b/src/observer/sql/executor/execute_stage.cpp index dfdc4f0267b1c00c0e821fa5bf586f73b4ee4fd6..acbd0409a464e76aee90ec8d7c1a707d0aba53bd 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 64e9d99b784f689caf1dd584111c97f7d2f4cc94..b0fefea3d72e665c3a89ea117037b4fbf70f9776 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 4bc7dfe9dc24bc0735a43379a5d3ce93cca4a7dd..a8eca8204142f6fbabd1a5e54f1bddc044d6fe89 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 6d8fa3c6a2f482eb5a83614edcae97529f7cea57..6d18bc74cbb3b3a030655a4b62a419baccd789c9 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; };