yiguolei commented on code in PR #66472:
URL: https://github.com/apache/doris/pull/66472#discussion_r3763174114


##########
be/src/storage/schema.cpp:
##########
@@ -17,90 +17,143 @@
 
 #include "storage/schema.h"
 
-#include <glog/logging.h>
-
-#include <boost/iterator/iterator_facade.hpp>
-#include <ostream>
-#include <unordered_set>
 #include <utility>
 
 #include "common/config.h"
-#include "core/column/column_array.h"
-#include "core/column/column_decimal.h"
+#include "common/logging.h"
+#include "core/block/block.h"
 #include "core/column/column_dictionary.h"
-#include "core/column/column_map.h"
+#include "core/column/column_nothing.h"
 #include "core/column/column_nullable.h"
-#include "core/column/column_string.h"
-#include "core/column/column_struct.h"
-#include "core/column/column_vector.h"
-#include "core/data_type/data_type.h"
-#include "core/data_type/data_type_factory.hpp"
-#include "core/data_type/define_primitive_type.h"
-#include "core/types.h"
-#include "storage/olap_common.h"
-#include "util/trace.h"
+#include "storage/binlog.h"
 
 namespace doris {
 
-Schema::Schema(const Schema& other) {
-    _copy_from(other);
+ReadSchema::ReadSchema(std::vector<TabletColumnPtr> columns)
+        : _read_columns(std::move(columns)), 
_num_block_columns(_read_columns.size()) {
+    _init_read_types();
+    _init_descriptors();
 }
 
-Schema& Schema::operator=(const Schema& other) {
-    if (this != &other) {
-        _copy_from(other);
+ReadSchema::ReadSchema(const std::vector<TabletColumnPtr>& columns,
+                       const std::vector<ColumnId>& cids)
+        : _num_block_columns(cids.size()) {
+    _read_columns.reserve(cids.size());
+    for (auto cid : cids) {
+        _read_columns.emplace_back(columns[cid]);
     }
-    return *this;
+    _init_read_types();
+    _init_descriptors();
+}
+
+ReadSchema::ReadSchema(std::vector<TabletColumnPtr> columns, 
std::vector<DataTypePtr> read_types)
+        : _read_columns(std::move(columns)),
+          _read_types(std::move(read_types)),
+          _num_block_columns(_read_types.size()) {
+    _init_descriptors();
 }
 
-void Schema::_copy_from(const Schema& other) {
-    _col_ids = other._col_ids;
-    _column_id_to_index = other._column_id_to_index;
-    _num_key_columns = other._num_key_columns;
-    _delete_sign_idx = other._delete_sign_idx;
-    _has_sequence_col = other._has_sequence_col;
-    _rowid_col_idx = other._rowid_col_idx;
-    _version_col_idx = other._version_col_idx;
-    _commit_tso_col_idx = other._commit_tso_col_idx;
-    _tso_col_idx = other._tso_col_idx;
-    _lsn_col_idx = other._lsn_col_idx;
-    _op_col_idx = other._op_col_idx;
-
-    _cols.resize(other._cols.size());
-    for (auto cid : _col_ids) {
-        _cols[cid] = other._cols[cid];
+void ReadSchema::_init_read_types() {
+    _read_types.reserve(_read_columns.size());
+    for (const auto& column : _read_columns) {
+        auto data_type = column->get_vec_type();
+        DORIS_CHECK(data_type != nullptr);
+        _read_types.emplace_back(std::move(data_type));
     }
 }
 
-void Schema::_init(const std::vector<TabletColumnPtr>& cols, const 
std::vector<ColumnId>& col_ids,
-                   size_t num_key_columns) {
-    _col_ids = col_ids;
-    _num_key_columns = num_key_columns;
+void ReadSchema::_init_before_column_ordinals() {
+    std::unordered_map<std::string_view, ColumnId> name_to_ordinal;
+    name_to_ordinal.reserve(_num_block_columns);
+    for (ColumnId ordinal = 0; ordinal < _num_block_columns; ++ordinal) {
+        name_to_ordinal.emplace(_read_columns[ordinal]->name(), ordinal);
+    }
 
-    _cols.resize(cols.size());
+    _before_column_ordinals.resize(_num_block_columns);
+    for (ColumnId ordinal = 0; ordinal < _num_block_columns; ++ordinal) {
+        auto read_ordinal = static_cast<int32_t>(ordinal);
+        if (read_ordinal == _tso_ordinal || read_ordinal == _lsn_ordinal ||
+            read_ordinal == _op_ordinal) {
+            _before_column_ordinals[ordinal] = ordinal;
+            continue;
+        }
+        auto before_name = 
binlog::build_before_column_name(_read_columns[ordinal]->name());
+        auto before = name_to_ordinal.find(before_name);
+        _before_column_ordinals[ordinal] =
+                before == name_to_ordinal.end() ? ordinal : before->second;
+    }
+}
 
-    std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end());
-    _column_id_to_index.assign(cols.size(), -1);
-    for (size_t i = 0; i < col_ids.size(); ++i) {
-        _column_id_to_index[col_ids[i]] = static_cast<int>(i);
+Block ReadSchema::create_read_block() const {
+    Block block;
+    for (size_t ordinal = 0; ordinal < _num_block_columns; ++ordinal) {
+        const auto& data_type = _read_types[ordinal];
+        DORIS_CHECK(data_type != nullptr);
+        MutableColumnPtr column;
+        if 
(_read_columns[ordinal]->name().starts_with(BeConsts::VIRTUAL_COLUMN_PREFIX)) {

Review Comment:
   我们为什么是通过name prefix 来区分virtual column的? 为什么不是tablet column 中有一个标识?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to