Gabriel39 commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r2986062897


##########
be/src/storage/segment/adaptive_block_size_predictor.cpp:
##########
@@ -0,0 +1,138 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "storage/segment/adaptive_block_size_predictor.h"
+
+#include <algorithm>
+#include <cstddef>
+
+#include "core/block/block.h"
+#include "storage/segment/segment.h"
+#include "storage/tablet/tablet_schema.h"
+
+namespace doris::segment_v2 {
+
+AdaptiveBlockSizePredictor::AdaptiveBlockSizePredictor(size_t 
preferred_block_size_bytes,
+                                                       size_t 
preferred_max_col_bytes,
+                                                       const Segment& segment,
+                                                       const 
std::vector<ColumnId>& output_columns)
+        : _block_size_bytes(preferred_block_size_bytes), 
_max_col_bytes(preferred_max_col_bytes) {
+    // Compute metadata hint from cached per-column raw_data_bytes in Segment.
+    // Segment::column_raw_data_bytes() is a read-only map lookup, thread-safe.
+    uint32_t seg_rows = segment.num_rows();
+    if (seg_rows > 0) {
+        const auto& ts = segment.tablet_schema();
+        if (ts) {
+            double total_bytes = 0.0;
+            uint64_t matched_cols = 0;
+            for (ColumnId cid : output_columns) {
+                if (static_cast<size_t>(cid) < ts->num_columns()) {
+                    int32_t uid = ts->column(cid).unique_id();
+                    uint64_t raw_bytes = segment.column_raw_data_bytes(uid);
+                    if (uid >= 0 && raw_bytes > 0) {
+                        double col_bpr =
+                                static_cast<double>(raw_bytes) / 
static_cast<double>(seg_rows);
+                        _col_bytes_per_row[cid] = col_bpr;
+                        total_bytes += static_cast<double>(raw_bytes);
+                        matched_cols++;
+                    }
+                }
+            }
+            if (matched_cols > 0 && total_bytes > 0.0) {
+                _metadata_hint_bytes_per_row = (total_bytes / 
static_cast<double>(seg_rows)) * 1.2;

Review Comment:
   What does `1.2` mean?



-- 
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