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


##########
be/src/pipeline/exec/hierarchical_spill_partition.h:
##########
@@ -0,0 +1,76 @@
+// 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.
+//
+// A small shared helper for hierarchical spill partitioning (multi-level 
split).
+
+#pragma once
+
+#include <cstdint>
+#include <string>
+
+namespace doris::pipeline {
+
+// Fixed 8-way fanout (3 bits per level), same as partitioned hash join spill.
+// This keeps the hierarchy bounded and makes the path encoding compact and 
stable.
+static constexpr uint32_t kSpillFanout = 8;
+static constexpr uint32_t kSpillBitsPerLevel = 3;
+static constexpr uint32_t kSpillMaxDepth = 6;
+
+struct SpillPartitionId {
+    uint32_t level = 0;
+    uint32_t path = 0;
+
+    // Pack (level,path) into a compact key for unordered_map lookup.
+    // Assumes max depth is small; level is stored in high 8 bits.
+    uint32_t key() const { return (level << 24) | path; }
+
+    SpillPartitionId child(uint32_t child_index) const {
+        return {.level = level + 1,
+                .path = path | (child_index << ((level + 1) * 
kSpillBitsPerLevel))};
+    }
+
+    std::string to_string() const {
+        return "partition(" + std::to_string(level) + ", " + 
std::to_string(path) + ")";
+    }
+};
+
+inline uint32_t spill_partition_index(uint32_t hash, uint32_t level) {

Review Comment:
   能否移动到一个类里,不要这种直接的全局函数



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