You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2026/03/25 05:32:13 UTC

(doris) branch branch-4.1 updated: [branch-4.1](spill) Support multi-level partition spilling (#61212) (#61677)

This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new 7291eff5ea0 [branch-4.1](spill) Support multi-level partition spilling (#61212) (#61677)
7291eff5ea0 is described below

commit 7291eff5ea0480a77e56dd8773f88cd57e5685aa
Author: Jerry Hu <hu...@selectdb.com>
AuthorDate: Wed Mar 25 13:32:06 2026 +0800

    [branch-4.1](spill) Support multi-level partition spilling (#61212) (#61677)
    
    Pick #61212
    
    This PR adds support for spill repartition in partitioned operators.
    
    When memory is still insufficient after a partition has been spilled,
    the spilled partition can be repartitioned into smaller sub-partitions,
    which further reduces peak memory usage. The repartitioner is made
    level-aware so repartition can be applied recursively when needed.
    
    This PR also integrates the new spill repartition flow into partitioned
    hash join and partitioned aggregation, adds force-spill logic in the
    join sink operator, refactors spill file interfaces, improves spill
    metadata maintenance and memory-pressure handling, and fixes several
    spill-related issues such as revocable memory accounting and profile
    updates.
    
    Related PR: #xxx
    
    Problem Summary:
    
    None
    
    - Test <!-- At least one of them must be included. -->
        - [ ] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
    - [ ] Previous test can cover this change. - [ ] No code files have been
    changed. - [ ] Other reason <!-- Add your reason? -->
    
    - Behavior changed:
        - [ ] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [ ] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
    
    ---------
    
    ### What problem does this PR solve?
    
    Issue Number: close #xxx
    
    Related PR: #xxx
    
    Problem Summary:
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [ ] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
            - [ ] Previous test can cover this change.
            - [ ] No code files have been changed.
            - [ ] Other reason <!-- Add your reason?  -->
    
    - Behavior changed:
        - [ ] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [ ] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
    
    Co-authored-by: yiguolei <gu...@selectdb.com>
---
 be/benchmark/benchmark_main.cpp                    |    2 +-
 be/src/common/config.cpp                           |    7 +-
 be/src/common/config.h                             |    2 +
 be/src/exec/operator/aggregation_sink_operator.cpp |   15 +-
 be/src/exec/operator/aggregation_sink_operator.h   |    7 +-
 .../exec/operator/aggregation_source_operator.cpp  |    6 +
 be/src/exec/operator/aggregation_source_operator.h |    7 +
 .../exec/operator/multi_cast_data_stream_sink.cpp  |    1 -
 be/src/exec/operator/multi_cast_data_streamer.cpp  |   75 +-
 be/src/exec/operator/multi_cast_data_streamer.h    |    9 +-
 be/src/exec/operator/operator.h                    |  137 +-
 .../partitioned_aggregation_sink_operator.cpp      |  432 +++---
 .../partitioned_aggregation_sink_operator.h        |   52 +-
 .../partitioned_aggregation_source_operator.cpp    |  502 ++++---
 .../partitioned_aggregation_source_operator.h      |   89 +-
 .../partitioned_hash_join_probe_operator.cpp       | 1029 ++++++++-------
 .../partitioned_hash_join_probe_operator.h         |  154 ++-
 .../partitioned_hash_join_sink_operator.cpp        |  520 +++-----
 .../operator/partitioned_hash_join_sink_operator.h |   42 +-
 .../operator/spill_iceberg_table_sink_operator.cpp |   22 +-
 .../operator/spill_iceberg_table_sink_operator.h   |    5 +-
 be/src/exec/operator/spill_sort_sink_operator.cpp  |  137 +-
 be/src/exec/operator/spill_sort_sink_operator.h    |   12 +-
 .../exec/operator/spill_sort_source_operator.cpp   |  226 ++--
 be/src/exec/operator/spill_sort_source_operator.h  |   13 +-
 be/src/exec/operator/spill_utils.h                 |  170 +--
 be/src/exec/partitioner/partitioner.cpp            |    1 +
 be/src/exec/partitioner/partitioner.h              |   11 +
 be/src/exec/pipeline/dependency.cpp                |   81 +-
 be/src/exec/pipeline/dependency.h                  |  107 +-
 be/src/exec/pipeline/pipeline_fragment_context.cpp |   25 +-
 be/src/exec/pipeline/pipeline_task.cpp             |  235 +++-
 be/src/exec/pipeline/pipeline_task.h               |    1 +
 be/src/exec/pipeline/revokable_task.h              |    1 +
 be/src/exec/scan/split_source_connector.h          |   15 +-
 .../sink/writer/iceberg/viceberg_sort_writer.cpp   |  110 +-
 .../sink/writer/iceberg/viceberg_sort_writer.h     |   15 +-
 be/src/exec/sort/sort_cursor.h                     |    2 +
 be/src/exec/sort/sorter.h                          |    2 +
 be/src/exec/spill/spill_file.cpp                   |   95 ++
 be/src/exec/spill/spill_file.h                     |  114 ++
 ...l_stream_manager.cpp => spill_file_manager.cpp} |   77 +-
 ...spill_stream_manager.h => spill_file_manager.h} |   29 +-
 be/src/exec/spill/spill_file_reader.cpp            |  237 ++++
 be/src/exec/spill/spill_file_reader.h              |  111 ++
 be/src/exec/spill/spill_file_writer.cpp            |  273 ++++
 be/src/exec/spill/spill_file_writer.h              |  114 ++
 be/src/exec/spill/spill_reader.cpp                 |  168 ---
 be/src/exec/spill/spill_reader.h                   |   99 --
 be/src/exec/spill/spill_repartitioner.cpp          |  371 ++++++
 be/src/exec/spill/spill_repartitioner.h            |  161 +++
 be/src/exec/spill/spill_stream.cpp                 |  173 ---
 be/src/exec/spill/spill_stream.h                   |  108 --
 be/src/exec/spill/spill_writer.cpp                 |  178 ---
 be/src/exec/spill/spill_writer.h                   |  103 --
 be/src/format/parquet/byte_array_dict_decoder.cpp  |    6 +-
 be/src/format/parquet/byte_array_dict_decoder.h    |    4 +-
 be/src/format/parquet/fix_length_dict_decoder.hpp  |    2 +-
 be/src/runtime/exec_env.h                          |    9 +-
 be/src/runtime/exec_env_init.cpp                   |   12 +-
 be/src/runtime/query_context.cpp                   |    2 +-
 be/src/runtime/runtime_state.h                     |   92 +-
 be/test/exec/operator/agg_operator_test.cpp        |    2 +-
 be/test/exec/operator/join_test_helper.h           |    2 +-
 .../partitioned_aggregation_sink_operator_test.cpp |  326 ++++-
 ...artitioned_aggregation_source_operator_test.cpp |  646 ++++++++-
 .../partitioned_aggregation_test_helper.cpp        |    9 +-
 .../operator/partitioned_aggregation_test_helper.h |    4 +-
 .../partitioned_hash_join_probe_operator_test.cpp  | 1389 +++++++++++++++-----
 .../partitioned_hash_join_sink_operator_test.cpp   |   79 +-
 .../operator/partitioned_hash_join_test_helper.cpp |   46 +-
 .../operator/partitioned_hash_join_test_helper.h   |   14 +-
 .../operator/spill_sort_sink_operator_test.cpp     |  137 +-
 .../operator/spill_sort_source_operator_test.cpp   |  749 ++++++++++-
 be/test/exec/operator/spill_sort_test_helper.cpp   |   41 +-
 be/test/exec/operator/spill_sort_test_helper.h     |    2 +-
 .../operator/spillable_operator_test_helper.cpp    |   22 +-
 .../exec/operator/spillable_operator_test_helper.h |   11 +-
 .../pipeline/multi_cast_data_streamer_test.cpp     |   15 +-
 .../pipeline/partitioned_agg_shared_state_test.cpp |  221 ++++
 be/test/exec/pipeline/pipeline_task_test.cpp       |  387 +++++-
 .../workload_group/workload_group_manager_test.cpp |    7 +-
 be/test/vec/spill/spill_file_test.cpp              | 1090 +++++++++++++++
 be/test/vec/spill/spill_repartitioner_test.cpp     |  410 ++++++
 .../java/org/apache/doris/qe/SessionVariable.java  |   77 +-
 gensrc/thrift/PaloInternalService.thrift           |   26 +
 86 files changed, 9028 insertions(+), 3501 deletions(-)

diff --git a/be/benchmark/benchmark_main.cpp b/be/benchmark/benchmark_main.cpp
index ed77fa6e79e..32add5a1662 100644
--- a/be/benchmark/benchmark_main.cpp
+++ b/be/benchmark/benchmark_main.cpp
@@ -21,8 +21,8 @@
 #include "benchmark_fastunion.hpp"
 #include "benchmark_hll_merge.hpp"
 #include "binary_cast_benchmark.hpp"
+#include "core/block/block.h"
 #include "vec/columns/column_string.h"
-#include "vec/core/block.h"
 #include "vec/data_types/data_type.h"
 #include "vec/data_types/data_type_string.h"
 
diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp
index 6865b28a4eb..51b7c44a854 100644
--- a/be/src/common/config.cpp
+++ b/be/src/common/config.cpp
@@ -1434,9 +1434,10 @@ DEFINE_mDouble(high_disk_avail_level_diff_usages, "0.15");
 DEFINE_Int32(partition_disk_index_lru_size, "10000");
 // limit the storage space that query spill files can use
 DEFINE_String(spill_storage_root_path, "");
-DEFINE_String(spill_storage_limit, "20%");    // 20%
-DEFINE_mInt32(spill_gc_interval_ms, "2000");  // 2s
-DEFINE_mInt32(spill_gc_work_time_ms, "2000"); // 2s
+DEFINE_String(spill_storage_limit, "20%");               // 20%
+DEFINE_mInt32(spill_gc_interval_ms, "2000");             // 2s
+DEFINE_mInt32(spill_gc_work_time_ms, "2000");            // 2s
+DEFINE_mInt64(spill_file_part_size_bytes, "1073741824"); // 1GB
 
 // paused query in queue timeout(ms) will be resumed or canceled
 DEFINE_Int64(spill_in_paused_queue_timeout_ms, "60000");
diff --git a/be/src/common/config.h b/be/src/common/config.h
index 60a3cdaca32..42ddcdd3ff9 100644
--- a/be/src/common/config.h
+++ b/be/src/common/config.h
@@ -1538,6 +1538,8 @@ DECLARE_String(spill_storage_root_path);
 DECLARE_String(spill_storage_limit);
 DECLARE_mInt32(spill_gc_interval_ms);
 DECLARE_mInt32(spill_gc_work_time_ms);
+// Maximum size of each spill part file before rotation (bytes). Default 1GB.
+DECLARE_mInt64(spill_file_part_size_bytes);
 DECLARE_Int64(spill_in_paused_queue_timeout_ms);
 DECLARE_Int64(wait_cancel_release_memory_ms);
 
diff --git a/be/src/exec/operator/aggregation_sink_operator.cpp b/be/src/exec/operator/aggregation_sink_operator.cpp
index 35f1c49ef04..39414e37aa0 100644
--- a/be/src/exec/operator/aggregation_sink_operator.cpp
+++ b/be/src/exec/operator/aggregation_sink_operator.cpp
@@ -202,7 +202,7 @@ Status AggSinkLocalState::_merge_with_serialized_key(Block* block) {
 }
 
 size_t AggSinkLocalState::_memory_usage() const {
-    if (0 == _get_hash_table_size()) {
+    if (0 == get_hash_table_size()) {
         return 0;
     }
     size_t usage = 0;
@@ -380,7 +380,7 @@ Status AggSinkLocalState::_merge_with_serialized_key_helper(Block* block) {
         }
 
         if (!limit && _should_limit_output) {
-            const size_t hash_table_size = _get_hash_table_size();
+            const size_t hash_table_size = get_hash_table_size();
             _shared_state->reach_limit =
                     hash_table_size >= Base::_parent->template cast<AggSinkOperatorX>()._limit;
             if (_shared_state->do_sort_limit && _shared_state->reach_limit) {
@@ -499,7 +499,7 @@ Status AggSinkLocalState::_execute_with_serialized_key_helper(Block* block) {
             RETURN_IF_ERROR(do_aggregate_evaluators());
 
             if (_should_limit_output && !Base::_shared_state->enable_spill) {
-                const size_t hash_table_size = _get_hash_table_size();
+                const size_t hash_table_size = get_hash_table_size();
 
                 _shared_state->reach_limit =
                         hash_table_size >=
@@ -516,7 +516,7 @@ Status AggSinkLocalState::_execute_with_serialized_key_helper(Block* block) {
     return Status::OK();
 }
 
-size_t AggSinkLocalState::_get_hash_table_size() const {
+size_t AggSinkLocalState::get_hash_table_size() const {
     return std::visit(Overload {[&](std::monostate& arg) -> size_t { return 0; },
                                 [&](auto& agg_method) { return agg_method.hash_table->size(); }},
                       _agg_data->method_variant);
@@ -872,7 +872,7 @@ Status AggSinkOperatorX::sink(doris::RuntimeState* state, Block* in_block, bool
         RETURN_IF_ERROR(local_state._executor->execute(&local_state, in_block));
         local_state._executor->update_memusage(&local_state);
         COUNTER_SET(local_state._hash_table_size_counter,
-                    (int64_t)local_state._get_hash_table_size());
+                    (int64_t)local_state.get_hash_table_size());
     }
     if (eos) {
         local_state._dependency->set_ready_to_read();
@@ -899,6 +899,11 @@ size_t AggSinkOperatorX::get_reserve_mem_size(RuntimeState* state, bool eos) {
     return local_state.get_reserve_mem_size(state, eos);
 }
 
+size_t AggSinkOperatorX::get_hash_table_size(RuntimeState* state) const {
+    auto& local_state = get_local_state(state);
+    return local_state.get_hash_table_size();
+}
+
 Status AggSinkLocalState::close(RuntimeState* state, Status exec_status) {
     SCOPED_TIMER(Base::exec_time_counter());
     SCOPED_TIMER(Base::_close_timer);
diff --git a/be/src/exec/operator/aggregation_sink_operator.h b/be/src/exec/operator/aggregation_sink_operator.h
index f90671cb465..9774d2b95e5 100644
--- a/be/src/exec/operator/aggregation_sink_operator.h
+++ b/be/src/exec/operator/aggregation_sink_operator.h
@@ -38,6 +38,7 @@ public:
     Status open(RuntimeState* state) override;
     Status close(RuntimeState* state, Status exec_status) override;
     bool is_blockable() const override;
+    size_t get_hash_table_size() const;
 
 protected:
     friend class AggSinkOperatorX;
@@ -81,6 +82,7 @@ protected:
     Status _merge_with_serialized_key(Block* block);
     void _update_memusage_with_serialized_key();
     template <bool limit>
+
     Status _execute_with_serialized_key_helper(Block* block);
     void _find_in_hash_table(AggregateDataPtr* places, ColumnRawPtrs& key_columns,
                              uint32_t num_rows);
@@ -89,7 +91,6 @@ protected:
     bool _emplace_into_hash_table_limit(AggregateDataPtr* places, Block* block,
                                         const std::vector<int>& key_locs,
                                         ColumnRawPtrs& key_columns, uint32_t num_rows);
-    size_t _get_hash_table_size() const;
 
     template <bool limit, bool for_spill = false>
     Status _merge_with_serialized_key_helper(Block* block);
@@ -119,7 +120,7 @@ protected:
     PODArray<AggregateDataPtr> _places;
     std::vector<char> _deserialize_buffer;
 
-    Block _preagg_block = Block();
+    Block _preagg_block;
 
     AggregatedDataVariants* _agg_data = nullptr;
 
@@ -178,6 +179,8 @@ public:
 
     size_t get_reserve_mem_size(RuntimeState* state, bool eos) override;
 
+    size_t get_hash_table_size(RuntimeState* state) const;
+
     using DataSinkOperatorX<AggSinkLocalState>::node_id;
     using DataSinkOperatorX<AggSinkLocalState>::operator_id;
     using DataSinkOperatorX<AggSinkLocalState>::get_local_state;
diff --git a/be/src/exec/operator/aggregation_source_operator.cpp b/be/src/exec/operator/aggregation_source_operator.cpp
index 1042e5cc732..a00a48a0300 100644
--- a/be/src/exec/operator/aggregation_source_operator.cpp
+++ b/be/src/exec/operator/aggregation_source_operator.cpp
@@ -541,6 +541,12 @@ Status AggSourceOperatorX::reset_hash_table(RuntimeState* state) {
     return Status::OK();
 }
 
+Status AggSourceOperatorX::get_serialized_block(RuntimeState* state, Block* block, bool* eos) {
+    auto& local_state = get_local_state(state);
+    // Always use the serialized intermediate output path, regardless of _needs_finalize.
+    return local_state._get_results_with_serialized_key(state, block, eos);
+}
+
 void AggLocalState::_emplace_into_hash_table(AggregateDataPtr* places, ColumnRawPtrs& key_columns,
                                              uint32_t num_rows) {
     std::visit(
diff --git a/be/src/exec/operator/aggregation_source_operator.h b/be/src/exec/operator/aggregation_source_operator.h
index e2306a2a081..e6443b2a77e 100644
--- a/be/src/exec/operator/aggregation_source_operator.h
+++ b/be/src/exec/operator/aggregation_source_operator.h
@@ -113,6 +113,13 @@ public:
 
     Status reset_hash_table(RuntimeState* state);
 
+    /// Get a block of serialized intermediate aggregate states from the hash table.
+    /// Unlike get_block() which may finalize, this always outputs the serialized
+    /// intermediate format (key columns + serialized agg state columns), which is
+    /// the same format as the spill block. This is needed for repartitioning during
+    /// multi-level spill recovery: the data must be re-mergeable after repartitioning.
+    Status get_serialized_block(RuntimeState* state, Block* block, bool* eos);
+
 private:
     friend class AggLocalState;
 
diff --git a/be/src/exec/operator/multi_cast_data_stream_sink.cpp b/be/src/exec/operator/multi_cast_data_stream_sink.cpp
index fbfb66482bc..437416b1b23 100644
--- a/be/src/exec/operator/multi_cast_data_stream_sink.cpp
+++ b/be/src/exec/operator/multi_cast_data_stream_sink.cpp
@@ -52,7 +52,6 @@ std::shared_ptr<BasicSharedState> MultiCastDataStreamSinkOperatorX::create_share
 Status MultiCastDataStreamSinkLocalState::open(RuntimeState* state) {
     RETURN_IF_ERROR(Base::open(state));
     _shared_state->multi_cast_data_streamer->set_sink_profile(operator_profile());
-    _shared_state->setup_shared_profile(custom_profile());
     _shared_state->multi_cast_data_streamer->set_write_dependency(_dependency);
     return Status::OK();
 }
diff --git a/be/src/exec/operator/multi_cast_data_streamer.cpp b/be/src/exec/operator/multi_cast_data_streamer.cpp
index 4511f42ae3c..142f7800338 100644
--- a/be/src/exec/operator/multi_cast_data_streamer.cpp
+++ b/be/src/exec/operator/multi_cast_data_streamer.cpp
@@ -32,7 +32,9 @@
 #include "exec/operator/multi_cast_data_stream_source.h"
 #include "exec/operator/spill_utils.h"
 #include "exec/pipeline/dependency.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
 #include "runtime/exec_env.h"
 #include "runtime/runtime_state.h"
 #include "util/pretty_printer.h"
@@ -77,14 +79,14 @@ Status MultiCastDataStreamer::pull(RuntimeState* state, int sender_idx, Block* b
 
         if (!_spill_readers[sender_idx].empty()) {
             auto reader_item = _spill_readers[sender_idx].front();
-            if (!reader_item->stream->ready_for_reading()) {
+            if (!reader_item->spill_file->ready_for_reading()) {
                 return Status::OK();
             }
 
             auto& reader = reader_item->reader;
             RETURN_IF_ERROR(reader->open());
             if (reader_item->block_offset != 0) {
-                reader->seek(reader_item->block_offset);
+                RETURN_IF_ERROR(reader->seek(reader_item->block_offset));
                 reader_item->block_offset = 0;
             }
 
@@ -117,9 +119,9 @@ Status MultiCastDataStreamer::pull(RuntimeState* state, int sender_idx, Block* b
             };
 
             l.unlock();
-            SpillRecoverRunnable spill_runnable(state, _source_operator_profiles[sender_idx],
-                                                catch_exception_func);
-            return spill_runnable.run();
+            // spill is synchronous; the profile passed to the runnable was only
+            // used for counters that are now tracked externally, so call helper
+            return run_spill_task(state, catch_exception_func);
         }
 
         auto& pos_to_pull = _sender_pos_to_read[sender_idx];
@@ -179,7 +181,7 @@ Status MultiCastDataStreamer::_trigger_spill_if_need(RuntimeState* state, bool*
         return Status::OK();
     }
 
-    SpillStreamSPtr spill_stream;
+    SpillFileSPtr spill_file;
     *triggered = false;
     if (_cumulative_mem_size.load() >= config::exchg_node_buffer_size_bytes &&
         _multi_cast_blocks.size() >= 4) {
@@ -205,25 +207,32 @@ Status MultiCastDataStreamer::_trigger_spill_if_need(RuntimeState* state, bool*
         }
 
         if (has_reached_end) {
-            RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-                    state, spill_stream, print_id(state->query_id()), "MultiCastSender", _node_id,
-                    std::numeric_limits<int32_t>::max(), std::numeric_limits<size_t>::max(),
-                    _sink_operator_profile));
+            auto relative_path = fmt::format("{}/{}-{}-{}-{}", print_id(state->query_id()),
+                                             "MultiCastSender", _node_id, state->task_id(),
+                                             ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+            RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(
+                    relative_path, spill_file));
+
+            // Block all senders while spilling.
+            for (int i = 0; i < _sender_pos_to_read.size(); ++i) {
+                _block_reading(i);
+            }
+
+            // Write blocks to disk. _start_spill_task updates spill_file->_part_count.
+            RETURN_IF_ERROR(_start_spill_task(state, spill_file));
+            DCHECK_EQ(_multi_cast_blocks.size(), 0);
+
+            // Create readers AFTER writing so that _part_count is valid.
             for (int i = 0; i < _sender_pos_to_read.size(); ++i) {
                 if (distances[i] < total_count) {
-                    auto reader = spill_stream->create_separate_reader();
-                    reader->set_counters(_source_operator_profiles[i]);
+                    auto reader = spill_file->create_reader(state, _source_operator_profiles[i]);
                     auto reader_item = std::make_shared<SpillingReader>(
-                            std::move(reader), spill_stream, distances[i], false);
+                            std::move(reader), spill_file, distances[i], false);
                     _spill_readers[i].emplace_back(std::move(reader_item));
                 }
-
-                _block_reading(i);
+                _set_ready_for_read(i);
             }
 
-            RETURN_IF_ERROR(_start_spill_task(state, spill_stream));
-            DCHECK_EQ(_multi_cast_blocks.size(), 0);
-
             for (auto& pos : _sender_pos_to_read) {
                 pos = _multi_cast_blocks.end();
             }
@@ -235,7 +244,7 @@ Status MultiCastDataStreamer::_trigger_spill_if_need(RuntimeState* state, bool*
     return Status::OK();
 }
 
-Status MultiCastDataStreamer::_start_spill_task(RuntimeState* state, SpillStreamSPtr spill_stream) {
+Status MultiCastDataStreamer::_start_spill_task(RuntimeState* state, SpillFileSPtr spill_file) {
     std::vector<Block> blocks;
     for (auto& block : _multi_cast_blocks) {
         DCHECK_GT(block._block->rows(), 0);
@@ -244,18 +253,20 @@ Status MultiCastDataStreamer::_start_spill_task(RuntimeState* state, SpillStream
 
     _multi_cast_blocks.clear();
 
-    auto spill_func = [state, blocks = std::move(blocks),
-                       spill_stream = std::move(spill_stream)]() mutable {
+    auto* sink_profile = _sink_operator_profile;
+    auto spill_func = [state, blocks = std::move(blocks), spill_file = std::move(spill_file),
+                       sink_profile]() mutable {
         const auto blocks_count = blocks.size();
-        while (!blocks.empty() && !state->is_cancelled()) {
-            auto block = std::move(blocks.front());
-            blocks.erase(blocks.begin());
-
-            RETURN_IF_ERROR(spill_stream->spill_block(state, block, false));
+        SpillFileWriterSPtr writer;
+        RETURN_IF_ERROR(spill_file->create_writer(state, sink_profile, writer));
+        for (auto& block : blocks) {
+            if (state->is_cancelled()) break;
+            RETURN_IF_ERROR(writer->write_block(state, block));
         }
+        RETURN_IF_ERROR(writer->close());
         VLOG_DEBUG << "Query: " << print_id(state->query_id()) << " multi cast write "
                    << blocks_count << " blocks";
-        return spill_stream->spill_eof();
+        return Status::OK();
     };
 
     auto exception_catch_func = [spill_func = std::move(spill_func),
@@ -266,15 +277,13 @@ Status MultiCastDataStreamer::_start_spill_task(RuntimeState* state, SpillStream
         if (!status.ok()) {
             LOG(WARNING) << "Query: " << query_id
                          << " multi cast write failed: " << status.to_string();
-        } else {
-            for (int i = 0; i < _sender_pos_to_read.size(); ++i) {
-                _set_ready_for_read(i);
-            }
         }
+        // _set_ready_for_read is called by _trigger_spill_if_need after readers
+        // are created with the correct part_count.
         return status;
     };
 
-    return SpillSinkRunnable(state, nullptr, _sink_operator_profile, exception_catch_func).run();
+    return run_spill_task(state, exception_catch_func);
 }
 
 Status MultiCastDataStreamer::push(RuntimeState* state, doris::Block* block, bool eos) {
diff --git a/be/src/exec/operator/multi_cast_data_streamer.h b/be/src/exec/operator/multi_cast_data_streamer.h
index b9dc9112cfb..773576fb2b9 100644
--- a/be/src/exec/operator/multi_cast_data_streamer.h
+++ b/be/src/exec/operator/multi_cast_data_streamer.h
@@ -25,7 +25,7 @@
 #include "core/block/block.h"
 #include "exec/exchange/vdata_stream_sender.h"
 #include "exec/pipeline/dependency.h"
-#include "exec/spill/spill_stream.h"
+#include "exec/spill/spill_file.h"
 #include "runtime/runtime_profile.h"
 
 namespace doris {
@@ -45,8 +45,9 @@ struct MultiCastBlock {
 };
 
 struct SpillingReader {
-    SpillReaderUPtr reader;
-    SpillStreamSPtr stream;
+    SpillFileReaderSPtr reader;
+    SpillFileSPtr spill_file;
+
     int64_t block_offset {0};
     bool all_data_read {false};
 };
@@ -99,7 +100,7 @@ private:
     Status _copy_block(RuntimeState* state, int32_t sender_idx, Block* block,
                        MultiCastBlock& multi_cast_block);
 
-    Status _start_spill_task(RuntimeState* state, SpillStreamSPtr spill_stream);
+    Status _start_spill_task(RuntimeState* state, SpillFileSPtr spill_file);
 
     Status _trigger_spill_if_need(RuntimeState* state, bool* triggered);
 
diff --git a/be/src/exec/operator/operator.h b/be/src/exec/operator/operator.h
index f8226eca714..e354aa26a32 100644
--- a/be/src/exec/operator/operator.h
+++ b/be/src/exec/operator/operator.h
@@ -130,10 +130,7 @@ public:
 
     virtual size_t revocable_mem_size(RuntimeState* state) const { return 0; }
 
-    virtual Status revoke_memory(RuntimeState* state,
-                                 const std::shared_ptr<SpillContext>& spill_context) {
-        return Status::OK();
-    }
+    virtual Status revoke_memory(RuntimeState* state) { return Status::OK(); }
 
     virtual bool is_hash_join_probe() const { return false; }
 
@@ -375,15 +372,6 @@ public:
     }
 
     void init_spill_write_counters() {
-        _spill_write_timer = ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillWriteTime", 1);
-
-        _spill_write_wait_in_queue_task_count = ADD_COUNTER_WITH_LEVEL(
-                Base::custom_profile(), "SpillWriteTaskWaitInQueueCount", TUnit::UNIT, 1);
-        _spill_writing_task_count = ADD_COUNTER_WITH_LEVEL(Base::custom_profile(),
-                                                           "SpillWriteTaskCount", TUnit::UNIT, 1);
-        _spill_write_wait_in_queue_timer =
-                ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillWriteTaskWaitInQueueTime", 1);
-
         _spill_write_file_timer =
                 ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillWriteFileTime", 1);
 
@@ -397,23 +385,12 @@ public:
                 Base::custom_profile(), "SpillWriteFileBytes", TUnit::BYTES, 1);
         _spill_write_rows_count =
                 ADD_COUNTER_WITH_LEVEL(Base::custom_profile(), "SpillWriteRows", TUnit::UNIT, 1);
-        _spill_file_total_count = ADD_COUNTER_WITH_LEVEL(
+        _spill_write_file_total_count = ADD_COUNTER_WITH_LEVEL(
                 Base::custom_profile(), "SpillWriteFileTotalCount", TUnit::UNIT, 1);
     }
 
     void init_spill_read_counters() {
-        _spill_total_timer = ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillTotalTime", 1);
-
         // Spill read counters
-        _spill_recover_time = ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillRecoverTime", 1);
-
-        _spill_read_wait_in_queue_task_count = ADD_COUNTER_WITH_LEVEL(
-                Base::custom_profile(), "SpillReadTaskWaitInQueueCount", TUnit::UNIT, 1);
-        _spill_reading_task_count = ADD_COUNTER_WITH_LEVEL(Base::custom_profile(),
-                                                           "SpillReadTaskCount", TUnit::UNIT, 1);
-        _spill_read_wait_in_queue_timer =
-                ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillReadTaskWaitInQueueTime", 1);
-
         _spill_read_file_time =
                 ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillReadFileTime", 1);
         _spill_read_deserialize_block_timer =
@@ -436,35 +413,7 @@ public:
                 Base::custom_profile(), "SpillWriteFileCurrentCount", TUnit::UNIT, 1);
     }
 
-    // These two counters are shared to spill source operators as the initial value
-    // Initialize values of counters 'SpillWriteFileCurrentBytes' and 'SpillWriteFileCurrentCount'
-    // from spill sink operators' "SpillWriteFileTotalCount" and "SpillWriteFileBytes"
-    void copy_shared_spill_profile() {
-        if (_copy_shared_spill_profile) {
-            _copy_shared_spill_profile = false;
-            const auto* spill_shared_state = (const BasicSpillSharedState*)Base::_shared_state;
-            COUNTER_UPDATE(_spill_file_current_size,
-                           spill_shared_state->_spill_write_file_total_size->value());
-            COUNTER_UPDATE(_spill_file_current_count,
-                           spill_shared_state->_spill_file_total_count->value());
-            Base::_shared_state->update_spill_stream_profiles(Base::custom_profile());
-        }
-    }
-
-    // Total time of spill, including spill task scheduling time,
-    // serialize block time, write disk file time,
-    // and read disk file time, deserialize block time etc.
-    RuntimeProfile::Counter* _spill_total_timer = nullptr;
-
     // Spill write counters
-    // Total time of spill write, including serialize block time, write disk file,
-    // and wait in queue time, etc.
-    RuntimeProfile::Counter* _spill_write_timer = nullptr;
-
-    RuntimeProfile::Counter* _spill_write_wait_in_queue_task_count = nullptr;
-    RuntimeProfile::Counter* _spill_writing_task_count = nullptr;
-    RuntimeProfile::Counter* _spill_write_wait_in_queue_timer = nullptr;
-
     // Total time of writing file
     RuntimeProfile::Counter* _spill_write_file_timer = nullptr;
     RuntimeProfile::Counter* _spill_write_serialize_block_timer = nullptr;
@@ -476,21 +425,13 @@ public:
     // Total bytes of spill data written to disk file(after serialized)
     RuntimeProfile::Counter* _spill_write_file_total_size = nullptr;
     RuntimeProfile::Counter* _spill_write_rows_count = nullptr;
-    RuntimeProfile::Counter* _spill_file_total_count = nullptr;
+    RuntimeProfile::Counter* _spill_write_file_total_count = nullptr;
     RuntimeProfile::Counter* _spill_file_current_count = nullptr;
     // Spilled file total size
     RuntimeProfile::Counter* _spill_file_total_size = nullptr;
     // Current spilled file size
     RuntimeProfile::Counter* _spill_file_current_size = nullptr;
 
-    // Spill read counters
-    // Total time of recovring spilled data, including read file time, deserialize time, etc.
-    RuntimeProfile::Counter* _spill_recover_time = nullptr;
-
-    RuntimeProfile::Counter* _spill_read_wait_in_queue_task_count = nullptr;
-    RuntimeProfile::Counter* _spill_reading_task_count = nullptr;
-    RuntimeProfile::Counter* _spill_read_wait_in_queue_timer = nullptr;
-
     RuntimeProfile::Counter* _spill_read_file_time = nullptr;
     RuntimeProfile::Counter* _spill_read_deserialize_block_timer = nullptr;
     RuntimeProfile::Counter* _spill_read_block_count = nullptr;
@@ -500,8 +441,6 @@ public:
     RuntimeProfile::Counter* _spill_read_file_size = nullptr;
     RuntimeProfile::Counter* _spill_read_rows_count = nullptr;
     RuntimeProfile::Counter* _spill_read_file_count = nullptr;
-
-    bool _copy_shared_spill_profile = true;
 };
 
 class DataSinkOperatorXBase;
@@ -666,6 +605,8 @@ public:
     [[nodiscard]] virtual Status setup_local_state(RuntimeState* state,
                                                    LocalSinkStateInfo& info) = 0;
 
+    // Returns the memory this sink operator expects to allocate in the next
+    // execution round (sink only — pipeline task sums all operators + sink).
     [[nodiscard]] virtual size_t get_reserve_mem_size(RuntimeState* state, bool eos) {
         return state->minimum_operator_memory_required_bytes();
     }
@@ -779,17 +720,10 @@ public:
     }
 
     void init_spill_counters() {
-        _spill_total_timer = ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillTotalTime", 1);
-
-        _spill_write_timer = ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillWriteTime", 1);
-
-        _spill_write_wait_in_queue_task_count = ADD_COUNTER_WITH_LEVEL(
-                Base::custom_profile(), "SpillWriteTaskWaitInQueueCount", TUnit::UNIT, 1);
-        _spill_writing_task_count = ADD_COUNTER_WITH_LEVEL(Base::custom_profile(),
-                                                           "SpillWriteTaskCount", TUnit::UNIT, 1);
-        _spill_write_wait_in_queue_timer =
-                ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillWriteTaskWaitInQueueTime", 1);
-
+        _spill_write_file_total_count = ADD_COUNTER_WITH_LEVEL(
+                Base::custom_profile(), "SpillWriteFileTotalCount", TUnit::UNIT, 1);
+        _spill_write_file_total_size = ADD_COUNTER_WITH_LEVEL(
+                Base::custom_profile(), "SpillWriteFileBytes", TUnit::BYTES, 1);
         _spill_write_file_timer =
                 ADD_TIMER_WITH_LEVEL(Base::custom_profile(), "SpillWriteFileTime", 1);
 
@@ -831,22 +765,10 @@ public:
     }
 
     std::vector<int64_t> _rows_in_partitions;
-
-    // Total time of spill, including spill task scheduling time,
-    // serialize block time, write disk file time,
-    // and read disk file time, deserialize block time etc.
-    RuntimeProfile::Counter* _spill_total_timer = nullptr;
-
     // Spill write counters
-    // Total time of spill write, including serialize block time, write disk file,
-    // and wait in queue time, etc.
-    RuntimeProfile::Counter* _spill_write_timer = nullptr;
-
-    RuntimeProfile::Counter* _spill_write_wait_in_queue_task_count = nullptr;
-    RuntimeProfile::Counter* _spill_writing_task_count = nullptr;
-    RuntimeProfile::Counter* _spill_write_wait_in_queue_timer = nullptr;
-
     // Total time of writing file
+    RuntimeProfile::Counter* _spill_write_file_total_size = nullptr;
+    RuntimeProfile::Counter* _spill_write_file_total_count = nullptr;
     RuntimeProfile::Counter* _spill_write_file_timer = nullptr;
     RuntimeProfile::Counter* _spill_write_serialize_block_timer = nullptr;
     // Original count of spilled Blocks
@@ -944,11 +866,13 @@ public:
         }
     }
 
-    size_t revocable_mem_size(RuntimeState* state) const override {
-        return (_child and !is_source()) ? _child->revocable_mem_size(state) : 0;
-    }
-
-    // If this method is not overwrite by child, its default value is 1MB
+    // Returns the memory this single operator expects to allocate in the next
+    // execution round.  Each operator reports only its OWN requirement — the
+    // pipeline task is responsible for summing all operators + sink.
+    // After the value is consumed the caller should invoke
+    // reset_reserve_mem_size() so the next round starts from zero.
+    // If this method is not overridden by a subclass, its default value is the
+    // minimum operator memory (typically 1 MB).
     [[nodiscard]] virtual size_t get_reserve_mem_size(RuntimeState* state) {
         return state->minimum_operator_memory_required_bytes();
     }
@@ -1007,6 +931,9 @@ public:
     // To keep compatibility with older FE
     void set_serial_operator() { _is_serial_operator = true; }
 
+    // Resets this operator's estimated memory usage to zero so that the next
+    // call to get_reserve_mem_size() starts fresh.  The pipeline task calls
+    // this after consuming the reserve size for all operators in a round.
     virtual void reset_reserve_mem_size(RuntimeState* state) {}
 
 protected:
@@ -1074,27 +1001,21 @@ public:
         return state->get_local_state(operator_id())->template cast<LocalState>();
     }
 
+    // Returns memory this single operator expects to allocate in the next round.
+    // Does NOT include child operators — the pipeline task iterates all
+    // operators itself.
     size_t get_reserve_mem_size(RuntimeState* state) override {
         auto& local_state = get_local_state(state);
         auto estimated_size = local_state.estimate_memory_usage();
         if (estimated_size < state->minimum_operator_memory_required_bytes()) {
             estimated_size = state->minimum_operator_memory_required_bytes();
         }
-        if (!is_source() && _child) {
-            auto child_reserve_size = _child->get_reserve_mem_size(state);
-            estimated_size +=
-                    std::max(state->minimum_operator_memory_required_bytes(), child_reserve_size);
-        }
         return estimated_size;
     }
 
     void reset_reserve_mem_size(RuntimeState* state) override {
         auto& local_state = get_local_state(state);
         local_state.reset_estimate_memory_usage();
-
-        if (!is_source() && _child) {
-            _child->reset_reserve_mem_size(state);
-        }
     }
 };
 
@@ -1229,6 +1150,10 @@ public:
                        ? 0
                        : OperatorX<DummyOperatorLocalState>::get_reserve_mem_size(state);
     }
+    Status revoke_memory(RuntimeState* state) override {
+        _revoke_called = true;
+        return Status::OK();
+    }
 
 private:
     friend class AssertNumRowsLocalState;
@@ -1237,6 +1162,7 @@ private:
     bool _terminated = false;
     size_t _revocable_mem_size = 0;
     bool _disable_reserve_mem = false;
+    bool _revoke_called = false;
 };
 
 class DummySinkLocalState final : public PipelineXSinkLocalState<BasicSharedState> {
@@ -1279,6 +1205,10 @@ public:
                        ? 0
                        : DataSinkOperatorX<DummySinkLocalState>::get_reserve_mem_size(state, eos);
     }
+    Status revoke_memory(RuntimeState* state) override {
+        _revoke_called = true;
+        return Status::OK();
+    }
 
 private:
     bool _low_memory_mode = false;
@@ -1286,6 +1216,7 @@ private:
     std::atomic_bool _return_eof = false;
     size_t _revocable_mem_size = 0;
     bool _disable_reserve_mem = false;
+    bool _revoke_called = false;
 };
 #endif
 
diff --git a/be/src/exec/operator/partitioned_aggregation_sink_operator.cpp b/be/src/exec/operator/partitioned_aggregation_sink_operator.cpp
index 004c010e4b3..82d29ca4bb8 100644
--- a/be/src/exec/operator/partitioned_aggregation_sink_operator.cpp
+++ b/be/src/exec/operator/partitioned_aggregation_sink_operator.cpp
@@ -20,7 +20,6 @@
 #include <gen_cpp/Types_types.h>
 
 #include <cstdint>
-#include <limits>
 #include <memory>
 
 #include "common/status.h"
@@ -28,8 +27,8 @@
 #include "exec/operator/spill_utils.h"
 #include "exec/pipeline/dependency.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
 #include "runtime/fragment_mgr.h"
 #include "runtime/runtime_profile.h"
 #include "util/pretty_printer.h"
@@ -50,27 +49,24 @@ Status PartitionedAggSinkLocalState::init(doris::RuntimeState* state,
     _init_counters();
 
     auto& parent = Base::_parent->template cast<Parent>();
-    Base::_shared_state->init_spill_params(parent._spill_partition_count);
+    _spill_writers.resize(parent._partition_count);
+    RETURN_IF_ERROR(_setup_in_memory_agg_op(state));
 
-    RETURN_IF_ERROR(setup_in_memory_agg_op(state));
-
-    for (const auto& probe_expr_ctx : Base::_shared_state->in_mem_shared_state->probe_expr_ctxs) {
-        key_columns_.emplace_back(probe_expr_ctx->root()->data_type()->create_column());
+    for (const auto& probe_expr_ctx : Base::_shared_state->_in_mem_shared_state->probe_expr_ctxs) {
+        _key_columns.emplace_back(probe_expr_ctx->root()->data_type()->create_column());
     }
     for (const auto& aggregate_evaluator :
-         Base::_shared_state->in_mem_shared_state->aggregate_evaluators) {
-        value_data_types_.emplace_back(aggregate_evaluator->function()->get_serialized_type());
-        value_columns_.emplace_back(aggregate_evaluator->function()->create_serialize_column());
+         Base::_shared_state->_in_mem_shared_state->aggregate_evaluators) {
+        _value_data_types.emplace_back(aggregate_evaluator->function()->get_serialized_type());
+        _value_columns.emplace_back(aggregate_evaluator->function()->create_serialize_column());
     }
-
-    _rows_in_partitions.assign(Base::_shared_state->partition_count, 0);
+    _rows_in_partitions.assign(parent._partition_count, 0);
     return Status::OK();
 }
 
 Status PartitionedAggSinkLocalState::open(RuntimeState* state) {
     SCOPED_TIMER(Base::exec_time_counter());
     SCOPED_TIMER(Base::_open_timer);
-    _shared_state->setup_shared_profile(custom_profile());
     return Base::open(state);
 }
 
@@ -80,7 +76,24 @@ Status PartitionedAggSinkLocalState::close(RuntimeState* state, Status exec_stat
     if (Base::_closed) {
         return Status::OK();
     }
-    return Base::close(state, exec_status);
+
+    Status first_error;
+    for (auto& writer : _spill_writers) {
+        if (writer) {
+            auto st = writer->close();
+            if (!st.ok() && first_error.ok()) {
+                first_error = st;
+            }
+            writer.reset();
+        }
+    }
+    _spill_writers.clear();
+
+    auto st = Base::close(state, exec_status);
+    if (!first_error.ok()) {
+        return first_error;
+    }
+    return st;
 }
 
 void PartitionedAggSinkLocalState::_init_counters() {
@@ -96,7 +109,7 @@ void PartitionedAggSinkLocalState::_init_counters() {
     update_profile_from_inner_profile<spilled>(name, custom_profile(), child_profile)
 
 template <bool spilled>
-void PartitionedAggSinkLocalState::update_profile(RuntimeProfile* child_profile) {
+void PartitionedAggSinkLocalState::_update_profile(RuntimeProfile* child_profile) {
     UPDATE_PROFILE("MemoryUsageHashTable");
     UPDATE_PROFILE("MemoryUsageSerializeKeyArena");
     UPDATE_PROFILE("BuildTime");
@@ -124,7 +137,12 @@ PartitionedAggSinkOperatorX::PartitionedAggSinkOperatorX(ObjectPool* pool, int o
 Status PartitionedAggSinkOperatorX::init(const TPlanNode& tnode, RuntimeState* state) {
     RETURN_IF_ERROR(DataSinkOperatorX<PartitionedAggSinkLocalState>::init(tnode, state));
     _name = "PARTITIONED_AGGREGATION_SINK_OPERATOR";
-    _spill_partition_count = state->spill_aggregation_partition_count();
+    _partition_count = state->spill_aggregation_partition_count();
+    if (_partition_count < 2 || _partition_count > 32) {
+        return Status::InvalidArgument(fmt::format(
+                "Invalid partition count {} for PartitionedAggSinkOperatorX, should be in [2, 32]",
+                _partition_count));
+    }
     return _agg_sink_operator->init(tnode, state);
 }
 
@@ -136,65 +154,67 @@ Status PartitionedAggSinkOperatorX::sink(doris::RuntimeState* state, Block* in_b
     auto& local_state = get_local_state(state);
     SCOPED_TIMER(local_state.exec_time_counter());
     COUNTER_UPDATE(local_state.rows_input_counter(), (int64_t)in_block->rows());
-    local_state._eos = eos;
+
     auto* runtime_state = local_state._runtime_state.get();
     DBUG_EXECUTE_IF("fault_inject::partitioned_agg_sink::sink", {
         return Status::Error<INTERNAL_ERROR>("fault_inject partitioned_agg_sink sink failed");
     });
     RETURN_IF_ERROR(_agg_sink_operator->sink(runtime_state, in_block, false));
 
-    size_t revocable_size = 0;
-    int64_t query_mem_limit = 0;
+    // handle spill condition first, independent of eos
+    if (local_state._shared_state->_is_spilled) {
+        if (revocable_mem_size(state) >= state->spill_aggregation_sink_mem_limit_bytes()) {
+            RETURN_IF_ERROR(revoke_memory(state));
+            DCHECK(local_state._shared_state->_in_mem_shared_state->aggregate_data_container
+                           ->total_count() == 0);
+        }
+    } else {
+        auto* sink_local_state = local_state._runtime_state->get_sink_local_state();
+        local_state._update_profile<false>(sink_local_state->custom_profile());
+    }
+
+    // finally perform EOS bookkeeping
     if (eos) {
-        revocable_size = revocable_mem_size(state);
-        query_mem_limit = state->get_query_ctx()->resource_ctx()->memory_context()->mem_limit();
-        LOG(INFO) << fmt::format(
-                "Query:{}, agg sink:{}, task:{}, eos, need spill:{}, query mem limit:{}, "
-                "revocable memory:{}",
-                print_id(state->query_id()), node_id(), state->task_id(),
-                local_state._shared_state->is_spilled, PrettyPrinter::print_bytes(query_mem_limit),
-                PrettyPrinter::print_bytes(revocable_size));
-
-        if (local_state._shared_state->is_spilled) {
-            if (revocable_mem_size(state) > 0) {
-                RETURN_IF_ERROR(revoke_memory(state, nullptr));
-            } else {
-                for (auto& partition : local_state._shared_state->spill_partitions) {
-                    RETURN_IF_ERROR(partition->finish_current_spilling(eos));
+        if (local_state._shared_state->_is_spilled) {
+            // If there are still memory aggregation data, revoke memory, it is a flush operation.
+            if (_agg_sink_operator->get_hash_table_size(runtime_state) > 0) {
+                RETURN_IF_ERROR(revoke_memory(state));
+                DCHECK(local_state._shared_state->_in_mem_shared_state->aggregate_data_container
+                               ->total_count() == 0);
+            }
+            // Close all writers (finalizes SpillFile metadata)
+            for (auto& writer : local_state._spill_writers) {
+                if (writer) {
+                    RETURN_IF_ERROR(writer->close());
                 }
-                local_state._dependency->set_ready_to_read();
             }
-        } else {
-            local_state._dependency->set_ready_to_read();
+            local_state._clear_tmp_data();
         }
-    } else if (local_state._shared_state->is_spilled) {
-        if (revocable_mem_size(state) >= SpillStream::MAX_SPILL_WRITE_BATCH_MEM) {
-            return revoke_memory(state, nullptr);
-        }
-    }
-
-    if (!local_state._shared_state->is_spilled) {
-        auto* sink_local_state = local_state._runtime_state->get_sink_local_state();
-        local_state.update_profile<false>(sink_local_state->custom_profile());
+        // Should set here, not at the beginning, because revoke memory will check eos flag.
+        local_state._eos = eos;
+        local_state._dependency->set_ready_to_read();
     }
 
     return Status::OK();
 }
 
-Status PartitionedAggSinkOperatorX::revoke_memory(
-        RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context) {
+Status PartitionedAggSinkOperatorX::revoke_memory(RuntimeState* state) {
     auto& local_state = get_local_state(state);
-    return local_state.revoke_memory(state, spill_context);
+    return local_state._revoke_memory(state);
 }
 
 size_t PartitionedAggSinkOperatorX::revocable_mem_size(RuntimeState* state) const {
     auto& local_state = get_local_state(state);
+    // If the agg sink already has all data, then not able to spill.
+    if (local_state._eos) {
+        return 0;
+    }
     auto* runtime_state = local_state._runtime_state.get();
     auto size = _agg_sink_operator->get_revocable_mem_size(runtime_state);
-    return size;
+    return size > state->spill_min_revocable_mem() ? size : 0;
 }
 
-Status PartitionedAggSinkLocalState::setup_in_memory_agg_op(RuntimeState* state) {
+Status PartitionedAggSinkLocalState::_setup_in_memory_agg_op(RuntimeState* state) {
     _runtime_state = RuntimeState::create_unique(
             state->fragment_instance_id(), state->query_id(), state->fragment_id(),
             state->query_options(), TQueryGlobals {}, state->exec_env(), state->get_query_ctx());
@@ -206,16 +226,16 @@ Status PartitionedAggSinkLocalState::setup_in_memory_agg_op(RuntimeState* state)
     _runtime_state->set_task_id(state->task_id());
 
     auto& parent = Base::_parent->template cast<Parent>();
-    Base::_shared_state->in_mem_shared_state_sptr =
+    Base::_shared_state->_in_mem_shared_state_sptr =
             parent._agg_sink_operator->create_shared_state();
-    Base::_shared_state->in_mem_shared_state =
-            static_cast<AggSharedState*>(Base::_shared_state->in_mem_shared_state_sptr.get());
-    Base::_shared_state->in_mem_shared_state->enable_spill = true;
+    Base::_shared_state->_in_mem_shared_state =
+            static_cast<AggSharedState*>(Base::_shared_state->_in_mem_shared_state_sptr.get());
+    Base::_shared_state->_in_mem_shared_state->enable_spill = true;
 
     LocalSinkStateInfo info {.task_idx = 0,
                              .parent_profile = _internal_runtime_profile.get(),
                              .sender_id = -1,
-                             .shared_state = Base::_shared_state->in_mem_shared_state_sptr.get(),
+                             .shared_state = Base::_shared_state->_in_mem_shared_state_sptr.get(),
                              .shared_state_map = {},
                              .tsink = {}};
     RETURN_IF_ERROR(parent._agg_sink_operator->setup_local_state(_runtime_state.get(), info));
@@ -234,71 +254,67 @@ size_t PartitionedAggSinkOperatorX::get_reserve_mem_size(RuntimeState* state, bo
 }
 
 template <typename HashTableCtxType, typename KeyType>
-Status PartitionedAggSinkLocalState::to_block(HashTableCtxType& context, std::vector<KeyType>& keys,
-                                              std::vector<AggregateDataPtr>& values,
-                                              const AggregateDataPtr null_key_data) {
+Status PartitionedAggSinkLocalState::_to_block(HashTableCtxType& context,
+                                               std::vector<KeyType>& keys,
+                                               std::vector<AggregateDataPtr>& values,
+                                               const AggregateDataPtr null_key_data) {
     SCOPED_TIMER(_spill_serialize_hash_table_timer);
-    context.insert_keys_into_columns(keys, key_columns_, (uint32_t)keys.size());
+    context.insert_keys_into_columns(keys, _key_columns, (uint32_t)keys.size());
 
     if (null_key_data) {
         // only one key of group by support wrap null key
         // here need additional processing logic on the null key / value
-        CHECK(key_columns_.size() == 1);
-        CHECK(key_columns_[0]->is_nullable());
-        key_columns_[0]->insert_data(nullptr, 0);
+        CHECK(_key_columns.size() == 1);
+        CHECK(_key_columns[0]->is_nullable());
+        _key_columns[0]->insert_data(nullptr, 0);
 
         values.emplace_back(null_key_data);
     }
 
-    for (size_t i = 0; i < Base::_shared_state->in_mem_shared_state->aggregate_evaluators.size();
+    for (size_t i = 0; i < Base::_shared_state->_in_mem_shared_state->aggregate_evaluators.size();
          ++i) {
-        Base::_shared_state->in_mem_shared_state->aggregate_evaluators[i]
+        Base::_shared_state->_in_mem_shared_state->aggregate_evaluators[i]
                 ->function()
                 ->serialize_to_column(
                         values,
-                        Base::_shared_state->in_mem_shared_state->offsets_of_aggregate_states[i],
-                        value_columns_[i], values.size());
+                        Base::_shared_state->_in_mem_shared_state->offsets_of_aggregate_states[i],
+                        _value_columns[i], values.size());
     }
 
     ColumnsWithTypeAndName key_columns_with_schema;
-    for (int i = 0; i < key_columns_.size(); ++i) {
+    for (int i = 0; i < _key_columns.size(); ++i) {
         key_columns_with_schema.emplace_back(
-                std::move(key_columns_[i]),
-                Base::_shared_state->in_mem_shared_state->probe_expr_ctxs[i]->root()->data_type(),
-                Base::_shared_state->in_mem_shared_state->probe_expr_ctxs[i]->root()->expr_name());
+                std::move(_key_columns[i]),
+                Base::_shared_state->_in_mem_shared_state->probe_expr_ctxs[i]->root()->data_type(),
+                Base::_shared_state->_in_mem_shared_state->probe_expr_ctxs[i]->root()->expr_name());
     }
-    key_block_ = key_columns_with_schema;
+    _key_block = key_columns_with_schema;
 
     ColumnsWithTypeAndName value_columns_with_schema;
-    for (int i = 0; i < value_columns_.size(); ++i) {
+    for (int i = 0; i < _value_columns.size(); ++i) {
         value_columns_with_schema.emplace_back(
-                std::move(value_columns_[i]), value_data_types_[i],
-                Base::_shared_state->in_mem_shared_state->aggregate_evaluators[i]
+                std::move(_value_columns[i]), _value_data_types[i],
+                Base::_shared_state->_in_mem_shared_state->aggregate_evaluators[i]
                         ->function()
                         ->get_name());
     }
-    value_block_ = value_columns_with_schema;
+    _value_block = value_columns_with_schema;
 
-    for (const auto& column : key_block_.get_columns_with_type_and_name()) {
-        block_.insert(column);
+    for (const auto& column : _key_block.get_columns_with_type_and_name()) {
+        _block.insert(column);
     }
-    for (const auto& column : value_block_.get_columns_with_type_and_name()) {
-        block_.insert(column);
+    for (const auto& column : _value_block.get_columns_with_type_and_name()) {
+        _block.insert(column);
     }
     return Status::OK();
 }
 
 template <typename HashTableCtxType, typename KeyType>
 Status PartitionedAggSinkLocalState::_spill_partition(
-        RuntimeState* state, HashTableCtxType& context, AggSpillPartitionSPtr& spill_partition,
+        RuntimeState* state, HashTableCtxType& context, size_t partition_idx,
         std::vector<KeyType>& keys, std::vector<AggregateDataPtr>& values,
         const AggregateDataPtr null_key_data, bool is_last) {
-    SpillStreamSPtr spill_stream;
-    auto status = spill_partition->get_spill_stream(state, Base::_parent->node_id(),
-                                                    Base::operator_profile(), spill_stream);
-    RETURN_IF_ERROR(status);
-
-    status = to_block(context, keys, values, null_key_data);
+    auto status = _to_block(context, keys, values, null_key_data);
     RETURN_IF_ERROR(status);
 
     if (is_last) {
@@ -306,17 +322,33 @@ Status PartitionedAggSinkLocalState::_spill_partition(
         std::vector<AggregateDataPtr> tmp_values;
         keys.swap(tmp_keys);
         values.swap(tmp_values);
-
     } else {
         keys.clear();
         values.clear();
     }
-    status = spill_stream->spill_block(state, block_, false);
-    RETURN_IF_ERROR(status);
 
-    status = spill_partition->flush_if_full();
+    // Ensure _spill_partitions is initialized to correct size
+    auto& partitions = Base::_shared_state->_spill_partitions;
+    auto& parent = Base::_parent->template cast<Parent>();
+    if (partitions.size() == 0) {
+        partitions.resize(parent._partition_count);
+    }
+
+    // Lazy-create SpillFile + writer on first write for this partition
+    auto& spill_file = partitions[partition_idx];
+    auto& writer = _spill_writers[partition_idx];
+    if (!writer) {
+        auto relative_path = fmt::format("{}/agg_{}-{}-{}-{}", print_id(state->query_id()),
+                                         partition_idx, parent.node_id(), state->task_id(),
+                                         ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+        RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(relative_path,
+                                                                                    spill_file));
+        RETURN_IF_ERROR(spill_file->create_writer(state, Base::operator_profile(), writer));
+    }
+
+    RETURN_IF_ERROR(writer->write_block(state, _block));
     _reset_tmp_data();
-    return status;
+    return Status::OK();
 }
 
 template <typename HashTableCtxType, typename HashTableType>
@@ -325,149 +357,93 @@ Status PartitionedAggSinkLocalState::_spill_hash_table(RuntimeState* state,
                                                        HashTableType& hash_table,
                                                        const size_t size_to_revoke, bool eos) {
     Status status;
-    Defer defer {[&]() {
-        if (!status.ok()) {
-            Base::_shared_state->close();
-        }
-    }};
 
     context.init_iterator();
+    auto& parent = _parent->template cast<PartitionedAggSinkOperatorX>();
 
-    Base::_shared_state->in_mem_shared_state->aggregate_data_container->init_once();
+    Base::_shared_state->_in_mem_shared_state->aggregate_data_container->init_once();
 
-    const auto total_rows =
-            Base::_shared_state->in_mem_shared_state->aggregate_data_container->total_count();
+    const auto total_rows = parent._agg_sink_operator->get_hash_table_size(_runtime_state.get());
+
+    if (total_rows == 0) {
+        return Status::OK();
+    }
 
     const size_t size_to_revoke_ = std::max<size_t>(size_to_revoke, 1);
 
     // `spill_batch_rows` will be between 4k and 1M
     // and each block to spill will not be larger than 32MB(`MAX_SPILL_WRITE_BATCH_MEM`)
+    // TODO: yiguolei, should review this logic
     const auto spill_batch_rows = std::min<size_t>(
-            1024 * 1024, std::max<size_t>(4096, SpillStream::MAX_SPILL_WRITE_BATCH_MEM *
-                                                        total_rows / size_to_revoke_));
+
+            1024 * 1024, std::max<size_t>(4096, SpillFile::MAX_SPILL_WRITE_BATCH_MEM * total_rows /
+                                                        size_to_revoke_));
 
     VLOG_DEBUG << "Query: " << print_id(state->query_id()) << ", node: " << _parent->node_id()
-               << ", spill_batch_rows: " << spill_batch_rows << ", total rows: " << total_rows;
+               << ", spill_batch_rows: " << spill_batch_rows << ", total rows: " << total_rows
+               << ", size_to_revoke: " << size_to_revoke;
     size_t row_count = 0;
 
     std::vector<TmpSpillInfo<typename HashTableType::key_type>> spill_infos(
-            Base::_shared_state->partition_count);
-    auto& iter = Base::_shared_state->in_mem_shared_state->aggregate_data_container->iterator;
-    while (iter != Base::_shared_state->in_mem_shared_state->aggregate_data_container->end() &&
+            parent._partition_count);
+    auto& iter = Base::_shared_state->_in_mem_shared_state->aggregate_data_container->iterator;
+    while (iter != Base::_shared_state->_in_mem_shared_state->aggregate_data_container->end() &&
            !state->is_cancelled()) {
         const auto& key = iter.template get_key<typename HashTableType::key_type>();
-        auto partition_index = Base::_shared_state->get_partition_index(hash_table.hash(key));
+        auto partition_index = hash_table.hash(key) % parent._partition_count;
         spill_infos[partition_index].keys_.emplace_back(key);
         spill_infos[partition_index].values_.emplace_back(iter.get_aggregate_data());
 
         if (++row_count == spill_batch_rows) {
             row_count = 0;
-            for (int i = 0; i < Base::_shared_state->partition_count && !state->is_cancelled();
-                 ++i) {
+            for (int i = 0; i < parent._partition_count && !state->is_cancelled(); ++i) {
                 if (spill_infos[i].keys_.size() >= spill_batch_rows) {
                     _rows_in_partitions[i] += spill_infos[i].keys_.size();
-                    status = _spill_partition(
-                            state, context, Base::_shared_state->spill_partitions[i],
-                            spill_infos[i].keys_, spill_infos[i].values_, nullptr, false);
+                    status = _spill_partition(state, context, i, spill_infos[i].keys_,
+                                              spill_infos[i].values_, nullptr, false);
                     RETURN_IF_ERROR(status);
+                    spill_infos[i].keys_.clear();
+                    spill_infos[i].values_.clear();
                 }
             }
         }
 
         ++iter;
     }
-    auto hash_null_key_data = hash_table.has_null_key_data();
-    for (int i = 0; i < Base::_shared_state->partition_count && !state->is_cancelled(); ++i) {
-        auto spill_null_key_data =
-                (hash_null_key_data && i == Base::_shared_state->partition_count - 1);
+    const auto has_null_key_data = hash_table.has_null_key_data();
+    for (int i = 0; i < parent._partition_count && !state->is_cancelled(); ++i) {
+        auto spill_null_key_data = (has_null_key_data && i == parent._partition_count - 1);
         if (spill_infos[i].keys_.size() > 0 || spill_null_key_data) {
             _rows_in_partitions[i] += spill_infos[i].keys_.size();
             status = _spill_partition(
-                    state, context, Base::_shared_state->spill_partitions[i], spill_infos[i].keys_,
-                    spill_infos[i].values_,
+                    state, context, i, spill_infos[i].keys_, spill_infos[i].values_,
                     spill_null_key_data ? hash_table.template get_null_key_data<AggregateDataPtr>()
                                         : nullptr,
                     true);
             RETURN_IF_ERROR(status);
         }
     }
-
-    for (auto& partition : Base::_shared_state->spill_partitions) {
-        status = partition->finish_current_spilling(eos);
-        RETURN_IF_ERROR(status);
-    }
-    if (eos) {
-        _clear_tmp_data();
-    }
     return Status::OK();
 }
 
-Status PartitionedAggSinkLocalState::_execute_spill_process(RuntimeState* state,
-                                                            size_t size_to_revoke) {
-    Status status;
-    auto& parent = Base::_parent->template cast<Parent>();
-    auto query_id = state->query_id();
-
-    DBUG_EXECUTE_IF("fault_inject::partitioned_agg_sink::revoke_memory_cancel", {
-        status = Status::InternalError("fault_inject partitioned_agg_sink revoke_memory canceled");
-        state->get_query_ctx()->cancel(status);
-        return status;
-    });
-
-    Defer defer {[&]() {
-        if (!status.ok() || state->is_cancelled()) {
-            if (!status.ok()) {
-                LOG(WARNING) << fmt::format(
-                        "Query:{}, agg sink:{}, task:{}, revoke_memory error:{}",
-                        print_id(query_id), Base::_parent->node_id(), state->task_id(), status);
-            }
-            _shared_state->close();
-        } else {
-            LOG(INFO) << fmt::format(
-                    "Query:{}, agg sink:{}, task:{}, revoke_memory finish, eos:{}, revocable "
-                    "memory:{}",
-                    print_id(state->query_id()), _parent->node_id(), state->task_id(), _eos,
-                    PrettyPrinter::print_bytes(_parent->revocable_mem_size(state)));
-        }
-
-        if (_eos) {
-            Base::_dependency->set_ready_to_read();
-        }
-        state->get_query_ctx()->resource_ctx()->task_controller()->decrease_revoking_tasks_count();
-    }};
-
-    auto* runtime_state = _runtime_state.get();
-    auto* agg_data = parent._agg_sink_operator->get_agg_data(runtime_state);
-    status = std::visit(Overload {[&](std::monostate& arg) -> Status {
-                                      return Status::InternalError("Unit hash table");
-                                  },
-                                  [&](auto& agg_method) -> Status {
-                                      auto& hash_table = *agg_method.hash_table;
-                                      RETURN_IF_CATCH_EXCEPTION(return _spill_hash_table(
-                                              state, agg_method, hash_table, size_to_revoke, _eos));
-                                  }},
-                        agg_data->method_variant);
-    RETURN_IF_ERROR(status);
-    status = parent._agg_sink_operator->reset_hash_table(runtime_state);
-    return status;
-}
+Status PartitionedAggSinkLocalState::_revoke_memory(RuntimeState* state) {
+    if (_eos) {
+        return Status::OK();
+    }
 
-Status PartitionedAggSinkLocalState::revoke_memory(
-        RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context) {
     const auto size_to_revoke = _parent->revocable_mem_size(state);
-    LOG(INFO) << fmt::format(
-            "Query:{}, agg sink:{}, task:{}, revoke_memory, eos:{}, need spill:{}, revocable "
+    VLOG_DEBUG << fmt::format(
+            "Query:{}, agg sink:{}, task:{}, revoke_memory, eos:{}, is_spilled:{}, revocable "
             "memory:{}",
             print_id(state->query_id()), _parent->node_id(), state->task_id(), _eos,
-            _shared_state->is_spilled,
-            PrettyPrinter::print_bytes(_parent->revocable_mem_size(state)));
+            _shared_state->_is_spilled, PrettyPrinter::print_bytes(size_to_revoke));
     auto* sink_local_state = _runtime_state->get_sink_local_state();
-    if (!_shared_state->is_spilled) {
-        _shared_state->is_spilled = true;
+    if (!_shared_state->_is_spilled) {
+        _shared_state->_is_spilled = true;
         custom_profile()->add_info_string("Spilled", "true");
-        update_profile<false>(sink_local_state->custom_profile());
+        _update_profile<false>(sink_local_state->custom_profile());
     } else {
-        update_profile<true>(sink_local_state->custom_profile());
+        _update_profile<false>(sink_local_state->custom_profile());
     }
 
     DBUG_EXECUTE_IF("fault_inject::partitioned_agg_sink::revoke_memory_submit_func", {
@@ -477,52 +453,98 @@ Status PartitionedAggSinkLocalState::revoke_memory(
 
     state->get_query_ctx()->resource_ctx()->task_controller()->increase_revoking_tasks_count();
 
-    SpillSinkRunnable spill_runnable(state, spill_context, operator_profile(),
-                                     [this, state, size_to_revoke] {
-                                         return _execute_spill_process(state, size_to_revoke);
-                                     });
+    auto& parent = Base::_parent->template cast<Parent>();
+    auto query_id = state->query_id();
+
+    auto spill_func = [this, state, &parent, query_id, size_to_revoke]() -> Status {
+        Status status;
+
+        DBUG_EXECUTE_IF("fault_inject::partitioned_agg_sink::revoke_memory_cancel", {
+            status = Status::InternalError(
+                    "fault_inject partitioned_agg_sink revoke_memory canceled");
+            state->get_query_ctx()->cancel(status);
+            return status;
+        });
+
+        Defer defer {[&]() {
+            if (!status.ok()) {
+                LOG(WARNING) << fmt::format(
+                        "Query:{}, agg sink:{}, task:{}, revoke_memory error:{}",
+                        print_id(query_id), Base::_parent->node_id(), state->task_id(), status);
+            } else {
+                VLOG_DEBUG << fmt::format(
+                        "Query:{}, agg sink:{}, task:{}, revoke_memory finish, eos:{}, "
+                        "revocable "
+                        "memory:{}",
+                        print_id(state->query_id()), _parent->node_id(), state->task_id(), _eos,
+                        PrettyPrinter::print_bytes(_parent->revocable_mem_size(state)));
+            }
+            state->get_query_ctx()
+                    ->resource_ctx()
+                    ->task_controller()
+                    ->decrease_revoking_tasks_count();
+        }};
+
+        auto* runtime_state = _runtime_state.get();
+        auto* agg_data = parent._agg_sink_operator->get_agg_data(runtime_state);
+        status = std::visit(
+                Overload {[&](std::monostate& arg) -> Status {
+                              return Status::InternalError("Unit hash table");
+                          },
+                          [&](auto& agg_method) -> Status {
+                              auto& hash_table = *agg_method.hash_table;
+                              RETURN_IF_CATCH_EXCEPTION(return _spill_hash_table(
+                                      state, agg_method, hash_table, size_to_revoke, _eos));
+                          }},
+                agg_data->method_variant);
+        RETURN_IF_ERROR(status);
+        status = parent._agg_sink_operator->reset_hash_table(runtime_state);
+        return status;
+    };
 
-    return spill_runnable.run();
+    // old code used SpillSinkRunnable, but spills are synchronous and counters
+    // are tracked externally.  Call the spill function directly.
+    return run_spill_task(state, std::move(spill_func));
 }
 
 void PartitionedAggSinkLocalState::_reset_tmp_data() {
-    block_.clear();
-    key_columns_.clear();
-    value_columns_.clear();
-    key_block_.clear_column_data();
-    value_block_.clear_column_data();
-    key_columns_ = key_block_.mutate_columns();
-    value_columns_ = value_block_.mutate_columns();
+    _block.clear();
+    _key_columns.clear();
+    _value_columns.clear();
+    _key_block.clear_column_data();
+    _value_block.clear_column_data();
+    _key_columns = _key_block.mutate_columns();
+    _value_columns = _value_block.mutate_columns();
 }
 
 void PartitionedAggSinkLocalState::_clear_tmp_data() {
     {
         Block empty_block;
-        block_.swap(empty_block);
+        _block.swap(empty_block);
     }
     {
         Block empty_block;
-        key_block_.swap(empty_block);
+        _key_block.swap(empty_block);
     }
     {
         Block empty_block;
-        value_block_.swap(empty_block);
+        _value_block.swap(empty_block);
     }
     {
         MutableColumns cols;
-        key_columns_.swap(cols);
+        _key_columns.swap(cols);
     }
     {
         MutableColumns cols;
-        value_columns_.swap(cols);
+        _value_columns.swap(cols);
     }
 
     DataTypes tmp_value_data_types;
-    value_data_types_.swap(tmp_value_data_types);
+    _value_data_types.swap(tmp_value_data_types);
 }
 
 bool PartitionedAggSinkLocalState::is_blockable() const {
-    return _shared_state->is_spilled;
+    return _shared_state->_is_spilled;
 }
 
 #include "common/compile_check_end.h"
diff --git a/be/src/exec/operator/partitioned_aggregation_sink_operator.h b/be/src/exec/operator/partitioned_aggregation_sink_operator.h
index 2130ec9471d..0ca4817eb9f 100644
--- a/be/src/exec/operator/partitioned_aggregation_sink_operator.h
+++ b/be/src/exec/operator/partitioned_aggregation_sink_operator.h
@@ -22,11 +22,11 @@
 #include "exec/operator/aggregation_sink_operator.h"
 #include "exec/operator/operator.h"
 #include "exec/pipeline/dependency.h"
-#include "exec/spill/spill_stream.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_writer.h"
 #include "exprs/vectorized_agg_fn.h"
 #include "exprs/vexpr.h"
-#include "util/pretty_printer.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -41,22 +41,21 @@ public:
     PartitionedAggSinkLocalState(DataSinkOperatorXBase* parent, RuntimeState* state);
     ~PartitionedAggSinkLocalState() override = default;
 
-    friend class PartitionedAggSinkOperatorX;
-
     Status init(RuntimeState* state, LocalSinkStateInfo& info) override;
     Status open(RuntimeState* state) override;
     Status close(RuntimeState* state, Status exec_status) override;
 
-    Status revoke_memory(RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context);
+    bool is_blockable() const override;
 
-    Status _execute_spill_process(RuntimeState* state, size_t size_to_revoke);
+private:
+    friend class PartitionedAggSinkOperatorX;
 
-    Status setup_in_memory_agg_op(RuntimeState* state);
+    Status _revoke_memory(RuntimeState* state);
 
-    template <bool spilled>
-    void update_profile(RuntimeProfile* child_profile);
+    Status _setup_in_memory_agg_op(RuntimeState* state);
 
-    bool is_blockable() const override;
+    template <bool spilled>
+    void _update_profile(RuntimeProfile* child_profile);
 
     template <typename KeyType>
     struct TmpSpillInfo {
@@ -69,14 +68,14 @@ public:
                              HashTableType& hash_table, const size_t size_to_revoke, bool eos);
 
     template <typename HashTableCtxType, typename KeyType>
-    Status _spill_partition(RuntimeState* state, HashTableCtxType& context,
-                            AggSpillPartitionSPtr& spill_partition, std::vector<KeyType>& keys,
-                            std::vector<AggregateDataPtr>& values,
+
+    Status _spill_partition(RuntimeState* state, HashTableCtxType& context, size_t partition_idx,
+                            std::vector<KeyType>& keys, std::vector<AggregateDataPtr>& values,
                             const AggregateDataPtr null_key_data, bool is_last);
 
     template <typename HashTableCtxType, typename KeyType>
-    Status to_block(HashTableCtxType& context, std::vector<KeyType>& keys,
-                    std::vector<AggregateDataPtr>& values, const AggregateDataPtr null_key_data);
+    Status _to_block(HashTableCtxType& context, std::vector<KeyType>& keys,
+                     std::vector<AggregateDataPtr>& values, const AggregateDataPtr null_key_data);
 
     void _reset_tmp_data();
     void _clear_tmp_data();
@@ -85,18 +84,20 @@ public:
     std::unique_ptr<RuntimeState> _runtime_state;
 
     // temp structures during spilling
-    MutableColumns key_columns_;
-    MutableColumns value_columns_;
-    DataTypes value_data_types_;
-    Block block_;
-    Block key_block_;
-    Block value_block_;
+    MutableColumns _key_columns;
+    MutableColumns _value_columns;
+    DataTypes _value_data_types;
+    Block _block;
+    Block _key_block;
+    Block _value_block;
 
     std::unique_ptr<RuntimeProfile> _internal_runtime_profile;
     RuntimeProfile::Counter* _memory_usage_reserved = nullptr;
 
     RuntimeProfile::Counter* _spill_serialize_hash_table_timer = nullptr;
 
+    std::vector<SpillFileWriterSPtr> _spill_writers;
+
     std::atomic<bool> _eos = false;
 };
 
@@ -139,16 +140,15 @@ public:
     }
     size_t revocable_mem_size(RuntimeState* state) const override;
 
-    Status revoke_memory(RuntimeState* state,
-                         const std::shared_ptr<SpillContext>& spill_context) override;
+    Status revoke_memory(RuntimeState* state) override;
 
     size_t get_reserve_mem_size(RuntimeState* state, bool eos) override;
 
 private:
     friend class PartitionedAggSinkLocalState;
     std::unique_ptr<AggSinkOperatorX> _agg_sink_operator;
-
-    size_t _spill_partition_count = 32;
+    // each operator tracks its own partition count for spilling
+    size_t _partition_count = 32;
 };
 #include "common/compile_check_end.h"
 } // namespace doris
\ No newline at end of file
diff --git a/be/src/exec/operator/partitioned_aggregation_source_operator.cpp b/be/src/exec/operator/partitioned_aggregation_source_operator.cpp
index 0d27dacefb9..bfefcfb9af2 100644
--- a/be/src/exec/operator/partitioned_aggregation_source_operator.cpp
+++ b/be/src/exec/operator/partitioned_aggregation_source_operator.cpp
@@ -19,6 +19,7 @@
 
 #include <glog/logging.h>
 
+#include <limits>
 #include <string>
 
 #include "common/exception.h"
@@ -28,12 +29,14 @@
 #include "exec/operator/operator.h"
 #include "exec/operator/spill_utils.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_repartitioner.h"
 #include "runtime/fragment_mgr.h"
 #include "runtime/runtime_profile.h"
 
 namespace doris {
+
 #include "common/compile_check_begin.h"
 
 PartitionedAggLocalState::PartitionedAggLocalState(RuntimeState* state, OperatorXBase* parent)
@@ -44,6 +47,14 @@ Status PartitionedAggLocalState::init(RuntimeState* state, LocalStateInfo& info)
     SCOPED_TIMER(exec_time_counter());
     SCOPED_TIMER(_init_timer);
     _internal_runtime_profile = std::make_unique<RuntimeProfile>("internal_profile");
+    // Counters for partition spill metrics
+    _max_partition_level = ADD_COUNTER(custom_profile(), "SpillMaxPartitionLevel", TUnit::UNIT);
+    _total_partition_spills = ADD_COUNTER(custom_profile(), "SpillTotalPartitions", TUnit::UNIT);
+
+    init_spill_write_counters();
+
+    // Nothing else to init for repartitioner here; fanout is configured when
+    // repartitioner is initialized with key columns during actual repartition.
     return Status::OK();
 }
 
@@ -54,7 +65,8 @@ Status PartitionedAggLocalState::open(RuntimeState* state) {
         return Status::OK();
     }
     _opened = true;
-    RETURN_IF_ERROR(setup_in_memory_agg_op(state));
+    RETURN_IF_ERROR(_setup_in_memory_agg_op(state));
+
     return Status::OK();
 }
 
@@ -62,7 +74,7 @@ Status PartitionedAggLocalState::open(RuntimeState* state) {
     update_profile_from_inner_profile<spilled>(name, custom_profile(), child_profile)
 
 template <bool spilled>
-void PartitionedAggLocalState::update_profile(RuntimeProfile* child_profile) {
+void PartitionedAggLocalState::_update_profile(RuntimeProfile* child_profile) {
     UPDATE_COUNTER_FROM_INNER("GetResultsTime");
     UPDATE_COUNTER_FROM_INNER("HashTableIterateTime");
     UPDATE_COUNTER_FROM_INNER("InsertKeysToColumnTime");
@@ -86,7 +98,33 @@ Status PartitionedAggLocalState::close(RuntimeState* state) {
     if (_closed) {
         return Status::OK();
     }
-    return Base::close(state);
+
+    Status first_error;
+    if (_current_reader) {
+        auto st = _current_reader->close();
+        if (!st.ok() && first_error.ok()) {
+            first_error = st;
+        }
+        _current_reader.reset();
+    }
+
+    // Clean up partition queue resources.
+    for (auto& partition : _partition_queue) {
+        if (partition.spill_file) {
+            ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(partition.spill_file);
+        }
+    }
+    _partition_queue.clear();
+    if (_current_partition.spill_file) {
+        ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(_current_partition.spill_file);
+    }
+    _current_partition.spill_file.reset();
+
+    auto st = Base::close(state);
+    if (!first_error.ok()) {
+        return first_error;
+    }
+    return st;
 }
 PartitionedAggSourceOperatorX::PartitionedAggSourceOperatorX(ObjectPool* pool,
                                                              const TPlanNode& tnode,
@@ -99,6 +137,11 @@ PartitionedAggSourceOperatorX::PartitionedAggSourceOperatorX(ObjectPool* pool,
 Status PartitionedAggSourceOperatorX::init(const TPlanNode& tnode, RuntimeState* state) {
     RETURN_IF_ERROR(OperatorXBase::init(tnode, state));
     _op_name = "PARTITIONED_AGGREGATION_OPERATOR";
+    // copy partition count from session variable so source knows how many
+    // spill partitions to expect (used by local states during spill).
+    _partition_count = state->spill_aggregation_partition_count();
+    // default repartition max depth; can be overridden from session variable
+    _repartition_max_depth = state->spill_repartition_max_depth();
     return _agg_source_operator->init(tnode, state);
 }
 
@@ -109,6 +152,14 @@ Status PartitionedAggSourceOperatorX::prepare(RuntimeState* state) {
 
 Status PartitionedAggSourceOperatorX::close(RuntimeState* state) {
     RETURN_IF_ERROR(OperatorXBase::close(state));
+
+    // Centralize shared_state cleanup here so resources are released when
+    // the pipeline task finishes, matching the Sort operator pattern.
+    auto& local_state = get_local_state(state);
+    if (local_state._shared_state) {
+        local_state._shared_state->close();
+    }
+
     return _agg_source_operator->close(state);
 }
 
@@ -135,79 +186,218 @@ bool PartitionedAggSourceOperatorX::is_shuffled_operator() const {
     return _agg_source_operator->is_shuffled_operator();
 }
 
+size_t PartitionedAggSourceOperatorX::revocable_mem_size(RuntimeState* state) const {
+    auto& local_state = get_local_state(state);
+    if (!local_state._shared_state->_is_spilled || !local_state._current_partition.spill_file) {
+        return 0;
+    }
+
+    size_t bytes = 0;
+    for (const auto& block : local_state._blocks) {
+        bytes += block.allocated_bytes();
+    }
+    if (local_state._shared_state->_in_mem_shared_state != nullptr &&
+        local_state._shared_state->_in_mem_shared_state->agg_data != nullptr) {
+        auto* agg_data = local_state._shared_state->_in_mem_shared_state->agg_data.get();
+        bytes += std::visit(Overload {[&](std::monostate& arg) -> size_t { return 0; },
+                                      [&](auto& agg_method) -> size_t {
+                                          return agg_method.hash_table->get_buffer_size_in_bytes();
+                                      }},
+                            agg_data->method_variant);
+
+        if (auto& aggregate_data_container =
+                    local_state._shared_state->_in_mem_shared_state->aggregate_data_container;
+            aggregate_data_container) {
+            bytes += aggregate_data_container->memory_usage();
+        }
+    }
+    return bytes > state->spill_min_revocable_mem() ? bytes : 0;
+}
+
+Status PartitionedAggSourceOperatorX::revoke_memory(RuntimeState* state) {
+    auto& local_state = get_local_state(state);
+    if (!local_state._shared_state->_is_spilled) {
+        return Status::OK();
+    }
+    VLOG_DEBUG << fmt::format("Query:{}, agg source:{}, task:{}, revoke_memory, hash table size:{}",
+                              print_id(state->query_id()), node_id(), state->task_id(),
+                              PrettyPrinter::print_bytes(local_state._estimate_memory_usage));
+
+    // Flush hash table + repartition remaining spill files of the current partition.
+    RETURN_IF_ERROR(local_state._flush_and_repartition(state));
+    local_state._current_partition = AggSpillPartitionInfo {};
+    local_state._need_to_setup_partition = true;
+    return Status::OK();
+}
+
 Status PartitionedAggSourceOperatorX::get_block(RuntimeState* state, Block* block, bool* eos) {
     auto& local_state = get_local_state(state);
-    local_state.copy_shared_spill_profile();
     Status status;
-    Defer defer {[&]() {
-        if (!status.ok() || *eos) {
-            local_state._shared_state->close();
-        }
-    }};
 
     SCOPED_TIMER(local_state.exec_time_counter());
 
-    if (local_state._shared_state->is_spilled &&
-        local_state._need_to_merge_data_for_current_partition) {
-        if (local_state._blocks.empty() && !local_state._current_partition_eos) {
-            bool has_recovering_data = false;
-            status = local_state.recover_blocks_from_disk(state, has_recovering_data);
-            RETURN_IF_ERROR(status);
-            *eos = !has_recovering_data;
+    // ── Fast path: not spilled ─────────────────────────────────────────
+    if (!local_state._shared_state->_is_spilled) {
+        auto* runtime_state = local_state._runtime_state.get();
+        local_state._shared_state->_in_mem_shared_state->aggregate_data_container->init_once();
+        status = _agg_source_operator->get_block(runtime_state, block, eos);
+        RETURN_IF_ERROR(status);
+        if (*eos) {
+            auto* source_local_state =
+                    runtime_state->get_local_state(_agg_source_operator->operator_id());
+            local_state._update_profile<false>(source_local_state->custom_profile());
+        }
+        local_state.reached_limit(block, eos);
+        return Status::OK();
+    }
+
+    // ── Spilled path ───────────────────────────────────────────────────
+    // One-time: move original spill_partitions from shared state into unified queue.
+    if (local_state._partition_queue.empty() && local_state._need_to_setup_partition &&
+        !local_state._shared_state->_spill_partitions.empty()) {
+        local_state._init_partition_queue();
+    }
+
+    // Phase 1: Pop next partition from queue if needed.
+    if (local_state._need_to_setup_partition) {
+        if (local_state._partition_queue.empty()) {
+            *eos = true;
             return Status::OK();
-        } else if (!local_state._blocks.empty()) {
-            size_t merged_rows = 0;
-            while (!local_state._blocks.empty()) {
-                auto block_ = std::move(local_state._blocks.front());
-                merged_rows += block_.rows();
-                local_state._blocks.erase(local_state._blocks.begin());
-                status = _agg_source_operator->merge_with_serialized_key_helper(
-                        local_state._runtime_state.get(), &block_);
-                RETURN_IF_ERROR(status);
-            }
-            local_state._estimate_memory_usage +=
-                    _agg_source_operator->get_estimated_memory_size_for_merging(
-                            local_state._runtime_state.get(), merged_rows);
+        }
 
-            if (!local_state._current_partition_eos) {
-                return Status::OK();
+        local_state._current_partition = std::move(local_state._partition_queue.front());
+        local_state._partition_queue.pop_front();
+        local_state._blocks.clear();
+        local_state._estimate_memory_usage = 0;
+
+        VLOG_DEBUG << fmt::format(
+                "Query:{}, agg source:{}, task:{}, setup partition level:{}, "
+                "queue remaining:{}",
+                print_id(state->query_id()), node_id(), state->task_id(),
+                local_state._current_partition.level, local_state._partition_queue.size());
+        local_state._need_to_setup_partition = false;
+    }
+
+    // Phase 2: Recover blocks from disk into _blocks (batch of ~8MB).
+    if (local_state._blocks.empty() && local_state._current_partition.spill_file) {
+        RETURN_IF_ERROR(
+                local_state._recover_blocks_from_partition(state, local_state._current_partition));
+        // Return empty block to yield to pipeline scheduler.
+        // Pipeline task will check memory and call revoke_memory if needed.
+        *eos = false;
+        return Status::OK();
+    }
+
+    auto* memory_sufficient_dependency = state->get_query_ctx()->get_memory_sufficient_dependency();
+    // Phase 3: Merge recovered blocks into hash table.
+    if (!local_state._blocks.empty()) {
+        size_t merged_rows = 0;
+        while (!local_state._blocks.empty()) {
+            auto blk = std::move(local_state._blocks.front());
+            merged_rows += blk.rows();
+            local_state._blocks.erase(local_state._blocks.begin());
+            status = _agg_source_operator->merge_with_serialized_key_helper(
+                    local_state._runtime_state.get(), &blk);
+            RETURN_IF_ERROR(status);
+
+            if (memory_sufficient_dependency && !memory_sufficient_dependency->ready()) {
+                break;
             }
         }
 
-        local_state._need_to_merge_data_for_current_partition = false;
+        local_state._estimate_memory_usage +=
+                _agg_source_operator->get_estimated_memory_size_for_merging(
+                        local_state._runtime_state.get(), merged_rows);
+
+        // Return empty block to yield — pipeline task will check memory pressure
+        // and call revoke_memory() if the hash table grew too large.
+        *eos = false;
+        return Status::OK();
     }
 
-    // not spilled in sink or current partition still has data
+    // Phase 4: All spill files consumed and merged — output aggregated results from hash table.
     auto* runtime_state = local_state._runtime_state.get();
-    local_state._shared_state->in_mem_shared_state->aggregate_data_container->init_once();
-    status = _agg_source_operator->get_block(runtime_state, block, eos);
-    if (!local_state._shared_state->is_spilled) {
+    local_state._shared_state->_in_mem_shared_state->aggregate_data_container->init_once();
+    bool inner_eos = false;
+    RETURN_IF_ERROR(_agg_source_operator->get_block(runtime_state, block, &inner_eos));
+
+    if (inner_eos) {
         auto* source_local_state =
-                local_state._runtime_state->get_local_state(_agg_source_operator->operator_id());
-        local_state.update_profile<false>(source_local_state->custom_profile());
+                runtime_state->get_local_state(_agg_source_operator->operator_id());
+        local_state._update_profile<true>(source_local_state->custom_profile());
+
+        // Current partition fully output. Reset hash table, pop next partition.
+        RETURN_IF_ERROR(_agg_source_operator->reset_hash_table(runtime_state));
+
+        local_state._current_partition = AggSpillPartitionInfo {};
+        local_state._estimate_memory_usage = 0;
+        local_state._need_to_setup_partition = true;
+
+        if (local_state._partition_queue.empty()) {
+            *eos = true;
+        }
     }
 
-    RETURN_IF_ERROR(status);
-    if (*eos) {
-        if (local_state._shared_state->is_spilled) {
-            auto* source_local_state = local_state._runtime_state->get_local_state(
-                    _agg_source_operator->operator_id());
-            local_state.update_profile<true>(source_local_state->custom_profile());
-
-            if (!local_state._shared_state->spill_partitions.empty()) {
-                local_state._current_partition_eos = false;
-                local_state._need_to_merge_data_for_current_partition = true;
-                status = _agg_source_operator->reset_hash_table(runtime_state);
-                RETURN_IF_ERROR(status);
-                *eos = false;
+    local_state.reached_limit(block, eos);
+    return Status::OK();
+}
+
+// ════════════════════════════════════════════════════════════════════════
+// PartitionedAggLocalState implementation
+// ════════════════════════════════════════════════════════════════════════
+
+void PartitionedAggLocalState::_init_partition_queue() {
+    for (auto& spill_file : _shared_state->_spill_partitions) {
+        _partition_queue.emplace_back(std::move(spill_file), /*level=*/0);
+        // Track metrics: each queued partition counts as one spill at level 0
+        COUNTER_UPDATE(_total_partition_spills, 1);
+        _max_partition_level_seen = 0;
+        COUNTER_SET(_max_partition_level, int64_t(_max_partition_level_seen));
+    }
+    _shared_state->_spill_partitions.clear();
+}
+
+Status PartitionedAggLocalState::_recover_blocks_from_partition(RuntimeState* state,
+                                                                AggSpillPartitionInfo& partition) {
+    size_t accumulated_bytes = 0;
+    if (!partition.spill_file || state->is_cancelled()) {
+        return Status::OK();
+    }
+
+    // Create or reuse a persistent reader for this file
+    if (!_current_reader) {
+        _current_reader = partition.spill_file->create_reader(state, operator_profile());
+        RETURN_IF_ERROR(_current_reader->open());
+    }
+
+    bool eos = false;
+
+    while (!eos && !state->is_cancelled()) {
+        Block block;
+        DBUG_EXECUTE_IF("fault_inject::partitioned_agg_source::recover_spill_data", {
+            return Status::Error<INTERNAL_ERROR>(
+                    "fault_inject partitioned_agg_source recover_spill_data failed");
+        });
+        RETURN_IF_ERROR(_current_reader->read(&block, &eos));
+
+        if (!block.empty()) {
+            accumulated_bytes += block.allocated_bytes();
+            _blocks.emplace_back(std::move(block));
+
+            if (accumulated_bytes >= state->spill_buffer_size_bytes()) {
+                return Status::OK();
             }
         }
     }
-    local_state.reached_limit(block, eos);
+
+    if (eos) {
+        _current_reader.reset();
+        partition.spill_file.reset();
+    }
     return Status::OK();
 }
 
-Status PartitionedAggLocalState::setup_in_memory_agg_op(RuntimeState* state) {
+Status PartitionedAggLocalState::_setup_in_memory_agg_op(RuntimeState* state) {
     _runtime_state = RuntimeState::create_unique(
             state->fragment_instance_id(), state->query_id(), state->fragment_id(),
             state->query_options(), TQueryGlobals {}, state->exec_env(), state->get_query_ctx());
@@ -220,10 +410,10 @@ Status PartitionedAggLocalState::setup_in_memory_agg_op(RuntimeState* state) {
 
     auto& parent = Base::_parent->template cast<Parent>();
 
-    DCHECK(Base::_shared_state->in_mem_shared_state);
+    DCHECK(Base::_shared_state->_in_mem_shared_state);
     LocalStateInfo state_info {.parent_profile = _internal_runtime_profile.get(),
                                .scan_ranges = {},
-                               .shared_state = Base::_shared_state->in_mem_shared_state,
+                               .shared_state = Base::_shared_state->_in_mem_shared_state,
                                .shared_state_map = {},
                                .task_idx = 0};
 
@@ -236,115 +426,129 @@ Status PartitionedAggLocalState::setup_in_memory_agg_op(RuntimeState* state) {
     return source_local_state->open(state);
 }
 
-Status PartitionedAggLocalState::_recover_spill_data_from_disk(RuntimeState* state,
-                                                               const UniqueId& query_id) {
-    Status status;
-    Defer defer {[&]() {
-        if (!status.ok() || state->is_cancelled()) {
-            if (!status.ok()) {
-                LOG(WARNING) << fmt::format(
-                        "Query:{}, agg probe:{}, task:{}, recover agg data error:{}",
-                        print_id(query_id), _parent->node_id(), state->task_id(), status);
-            }
-            _shared_state->close();
+Status PartitionedAggLocalState::_flush_hash_table_to_sub_spill_files(RuntimeState* state) {
+    auto* runtime_state = _runtime_state.get();
+    auto& p = _parent->cast<PartitionedAggSourceOperatorX>();
+    auto* in_mem_state = _shared_state->_in_mem_shared_state;
+
+    // setup_output must have been called by the caller (_flush_and_repartition)
+    // before calling this function. The repartitioner writes to the persistent output writers.
+
+    in_mem_state->aggregate_data_container->init_once();
+    bool inner_eos = false;
+    while (!inner_eos && !state->is_cancelled()) {
+        Block block;
+        RETURN_IF_ERROR(
+                p._agg_source_operator->get_serialized_block(runtime_state, &block, &inner_eos));
+        if (!block.empty()) {
+            RETURN_IF_ERROR(_repartitioner.route_block(state, block));
         }
-    }};
-    bool has_agg_data = false;
-    size_t accumulated_blocks_size = 0;
-    while (!state->is_cancelled() && !has_agg_data && !_shared_state->spill_partitions.empty()) {
-        while (!_shared_state->spill_partitions[0]->spill_streams_.empty() &&
-               !state->is_cancelled() && !has_agg_data) {
-            auto& stream = _shared_state->spill_partitions[0]->spill_streams_[0];
-            stream->set_read_counters(operator_profile());
-            Block block;
-            bool eos = false;
-            while (!eos && !state->is_cancelled()) {
-                {
-                    DBUG_EXECUTE_IF("fault_inject::partitioned_agg_source::recover_spill_data", {
-                        status = Status::Error<INTERNAL_ERROR>(
-                                "fault_inject partitioned_agg_source "
-                                "recover_spill_data failed");
-                    });
-                    if (status.ok()) {
-                        status = stream->read_next_block_sync(&block, &eos);
-                    }
-                }
-                RETURN_IF_ERROR(status);
-
-                if (!block.empty()) {
-                    has_agg_data = true;
-                    accumulated_blocks_size += block.allocated_bytes();
-                    _blocks.emplace_back(std::move(block));
-
-                    if (accumulated_blocks_size >= SpillStream::MAX_SPILL_WRITE_BATCH_MEM) {
-                        break;
-                    }
-                }
-            }
+    }
 
-            _current_partition_eos = eos;
+    RETURN_IF_ERROR(p._agg_source_operator->reset_hash_table(runtime_state));
+    return Status::OK();
+}
 
-            if (_current_partition_eos) {
-                ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
-                _shared_state->spill_partitions[0]->spill_streams_.pop_front();
-            }
-        }
+Status PartitionedAggLocalState::_flush_and_repartition(RuntimeState* state) {
+    auto& p = _parent->cast<PartitionedAggSourceOperatorX>();
+    const int new_level = _current_partition.level + 1;
 
-        if (_shared_state->spill_partitions[0]->spill_streams_.empty()) {
-            _shared_state->spill_partitions.pop_front();
-        }
+    if (new_level >= p._repartition_max_depth) {
+        return Status::InternalError(
+                "query:{}, node:{}, Agg spill repartition exceeded max depth {} during "
+                "_flush_and_repartition. Likely due to extreme data skew.",
+                print_id(state->query_id()), p.node_id(), p._repartition_max_depth);
     }
 
     VLOG_DEBUG << fmt::format(
-            "Query:{}, agg probe:{}, task:{}, recover partitioned finished, partitions "
-            "left:{}, bytes read:{}",
-            print_id(query_id), _parent->node_id(), state->task_id(),
-            _shared_state->spill_partitions.size(), accumulated_blocks_size);
-    return status;
-}
+            "Query:{}, agg source:{}, task:{}, _flush_and_repartition: "
+            "flushing hash table and repartitioning remaining spill file at level {} -> {}",
+            print_id(state->query_id()), p.node_id(), state->task_id(), _current_partition.level,
+            new_level);
 
-Status PartitionedAggLocalState::recover_blocks_from_disk(RuntimeState* state, bool& has_data) {
-    const auto query_id = state->query_id();
+    {
+        auto* source_local_state =
+                _runtime_state->get_local_state(p._agg_source_operator->operator_id());
+        _update_profile<true>(source_local_state->custom_profile());
+    }
 
-    if (_shared_state->spill_partitions.empty()) {
-        _shared_state->close();
-        has_data = false;
-        return Status::OK();
+    // 1. Create FANOUT output sub-spill-files.
+    std::vector<SpillFileSPtr> output_spill_files;
+    RETURN_IF_ERROR(SpillRepartitioner::create_output_spill_files(
+            state, p.node_id(), fmt::format("agg_repart_l{}", new_level),
+            static_cast<int>(p._partition_count), output_spill_files));
+
+    auto* in_mem_state = _shared_state->_in_mem_shared_state;
+    size_t num_keys = in_mem_state->probe_expr_ctxs.size();
+    std::vector<size_t> key_column_indices(num_keys);
+    std::vector<DataTypePtr> key_data_types(num_keys);
+    for (size_t i = 0; i < num_keys; ++i) {
+        key_column_indices[i] = i;
+        key_data_types[i] = in_mem_state->probe_expr_ctxs[i]->root()->data_type();
     }
 
-    has_data = true;
-    auto exception_catch_func = [this, state, query_id]() {
-        DBUG_EXECUTE_IF("fault_inject::partitioned_agg_source::merge_spill_data_cancel", {
-            auto st = Status::InternalError(
-                    "fault_inject partitioned_agg_source "
-                    "merge spill data canceled");
-            state->get_query_ctx()->cancel(st);
-            return st;
-        });
+    _repartitioner.init_with_key_columns(std::move(key_column_indices), std::move(key_data_types),
+                                         operator_profile(), static_cast<int>(p._partition_count),
+                                         new_level);
 
-        auto status = [&]() {
-            RETURN_IF_CATCH_EXCEPTION({ return _recover_spill_data_from_disk(state, query_id); });
-        }();
-        LOG_IF(INFO, !status.ok()) << fmt::format(
-                "Query:{}, agg probe:{}, task:{}, recover exception:{}", print_id(query_id),
-                _parent->node_id(), state->task_id(), status.to_string());
-        return status;
-    };
+    // Setup persistent output writers for the repartitioner.
+    RETURN_IF_ERROR(_repartitioner.setup_output(state, output_spill_files));
 
-    DBUG_EXECUTE_IF("fault_inject::partitioned_agg_source::submit_func", {
-        return Status::Error<INTERNAL_ERROR>(
-                "fault_inject partitioned_agg_source submit_func failed");
-    });
+    // 2. Flush the in-memory hash table into the sub-spill-files.
+    RETURN_IF_ERROR(_flush_hash_table_to_sub_spill_files(state));
 
-    VLOG_DEBUG << fmt::format(
-            "Query:{}, agg probe:{}, task:{}, begin to recover, partitions left:{}, ",
-            print_id(query_id), _parent->node_id(), state->task_id(),
-            _shared_state->spill_partitions.size());
-    return SpillRecoverRunnable(state, operator_profile(), exception_catch_func).run();
+    // 3. Route any in-memory blocks that were recovered but not yet merged
+    //    into the hash table. These blocks were already read from the file
+    //    by _current_reader and must not be re-read.
+    for (auto& blk : _blocks) {
+        if (!blk.empty()) {
+            RETURN_IF_ERROR(_repartitioner.route_block(state, blk));
+        }
+    }
+    _blocks.clear();
+
+    // 4. Repartition remaining unread data from the spill file.
+    //
+    // If _current_reader exists, the file has been partially read. Pass
+    // the existing reader to repartitioner so it continues from the current
+    // position. This avoids re-reading from block 0 and duplicating data
+    // already represented by the hash table flush + _blocks routed above.
+    if (_current_reader) {
+        bool done = false;
+        while (!done && !state->is_cancelled()) {
+            RETURN_IF_ERROR(_repartitioner.repartition(state, _current_reader, &done));
+        }
+        // reader is reset by repartitioner on completion
+    } else if (_current_partition.spill_file) {
+        // No partial read — repartition the entire file from scratch.
+        bool done = false;
+        while (!done && !state->is_cancelled()) {
+            RETURN_IF_ERROR(
+                    _repartitioner.repartition(state, _current_partition.spill_file, &done));
+        }
+    }
+    _current_reader.reset();
+    _current_partition.spill_file.reset();
+
+    RETURN_IF_ERROR(_repartitioner.finalize());
+
+    // 4. Push non-empty sub-partitions into the work queue.
+    for (int i = 0; i < static_cast<int>(p._partition_count); ++i) {
+        _partition_queue.emplace_back(std::move(output_spill_files[i]), new_level);
+        // Metrics
+        COUNTER_UPDATE(_total_partition_spills, 1);
+        if (new_level > _max_partition_level_seen) {
+            _max_partition_level_seen = new_level;
+            COUNTER_SET(_max_partition_level, int64_t(_max_partition_level_seen));
+        }
+    }
+
+    _estimate_memory_usage = 0;
+    return Status::OK();
 }
 
 bool PartitionedAggLocalState::is_blockable() const {
-    return _shared_state->is_spilled;
+    return _shared_state->_is_spilled;
 }
 
 #include "common/compile_check_end.h"
diff --git a/be/src/exec/operator/partitioned_aggregation_source_operator.h b/be/src/exec/operator/partitioned_aggregation_source_operator.h
index f91e6c1bd5d..d59fea263b0 100644
--- a/be/src/exec/operator/partitioned_aggregation_source_operator.h
+++ b/be/src/exec/operator/partitioned_aggregation_source_operator.h
@@ -16,10 +16,15 @@
 // under the License.
 #pragma once
 
+#include <deque>
 #include <memory>
+#include <vector>
 
 #include "common/status.h"
-#include "exec/operator/operator.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_repartitioner.h"
+#include "operator.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -28,6 +33,19 @@ class RuntimeState;
 class PartitionedAggSourceOperatorX;
 class PartitionedAggLocalState;
 
+/// Represents one partition in the multi-level spill queue for aggregation.
+/// Unlike Join (which has build + probe), Agg only has a single data flow:
+/// spilled aggregation intermediate results stored in one SpillFile.
+struct AggSpillPartitionInfo {
+    // The spill file for this partition.
+    SpillFileSPtr spill_file;
+    // The depth level in the repartition tree (level-0 = original).
+    int level = 0;
+
+    AggSpillPartitionInfo() = default;
+    AggSpillPartitionInfo(SpillFileSPtr s, int lvl) : spill_file(std::move(s)), level(lvl) {}
+};
+
 class PartitionedAggLocalState MOCK_REMOVE(final)
         : public PipelineXSpillLocalState<PartitionedAggSharedState> {
 public:
@@ -41,30 +59,58 @@ public:
     Status open(RuntimeState* state) override;
     Status close(RuntimeState* state) override;
 
-    Status recover_blocks_from_disk(RuntimeState* state, bool& has_data);
-    Status setup_in_memory_agg_op(RuntimeState* state);
+    bool is_blockable() const override;
+
+private:
+    friend class PartitionedAggSourceOperatorX;
+
+    Status _setup_in_memory_agg_op(RuntimeState* state);
 
     template <bool spilled>
-    void update_profile(RuntimeProfile* child_profile);
+    void _update_profile(RuntimeProfile* child_profile);
 
-    bool is_blockable() const override;
+    /// Flush the current in-memory hash table by draining it as blocks and routing
+    /// each block through the repartitioner into the output sub-spill-files.
+    Status _flush_hash_table_to_sub_spill_files(RuntimeState* state);
 
-private:
-    Status _recover_spill_data_from_disk(RuntimeState* state, const UniqueId& query_id);
+    /// Flush the in-memory hash table into FANOUT sub-spill-files, repartition remaining
+    /// unread spill files from `remaining_spill_files`, and push resulting sub-partitions into
+    /// `_partition_queue`. After this call the hash table is reset and
+    /// `remaining_spill_files` is cleared.
+    Status _flush_and_repartition(RuntimeState* state);
 
-protected:
-    friend class PartitionedAggSourceOperatorX;
-    std::unique_ptr<RuntimeState> _runtime_state;
+    /// Move all original spill_partitions from shared state into `_partition_queue`.
+    /// Called once when spilled get_block is first entered.
+    void _init_partition_queue();
+
+    /// Read up to SpillFile::MAX_SPILL_WRITE_BATCH_MEM bytes from `partition.spill_files` into
+    /// `_blocks`. Returns has_data=true if any blocks were read.
+    /// Consumes and deletes exhausted spill files from the partition.
+    Status _recover_blocks_from_partition(RuntimeState* state, AggSpillPartitionInfo& partition);
 
+    // ── State ──────────────────────────────────────────────────────────
+    std::unique_ptr<RuntimeState> _runtime_state;
     bool _opened = false;
-    std::unique_ptr<std::promise<Status>> _spill_merge_promise;
-    std::future<Status> _spill_merge_future;
-    bool _current_partition_eos = true;
-    bool _need_to_merge_data_for_current_partition = true;
+    std::unique_ptr<RuntimeProfile> _internal_runtime_profile;
+
+    // ── Partition queue (unified for original + repartitioned) ────────
+    std::deque<AggSpillPartitionInfo> _partition_queue;
+    AggSpillPartitionInfo _current_partition;
+    // True when we need to pop the next partition from `_partition_queue`.
+    bool _need_to_setup_partition = true;
 
+    // Blocks recovered from disk, pending merge into hash table.
     std::vector<Block> _blocks;
 
-    std::unique_ptr<RuntimeProfile> _internal_runtime_profile;
+    // Counters to track spill partition metrics
+    RuntimeProfile::Counter* _max_partition_level = nullptr;
+    RuntimeProfile::Counter* _total_partition_spills = nullptr;
+    int _max_partition_level_seen = 0;
+
+    SpillRepartitioner _repartitioner;
+
+    // Persistent reader for _recover_blocks_from_partition (survives across yield calls)
+    SpillFileReaderSPtr _current_reader;
 };
 
 class AggSourceOperatorX;
@@ -93,10 +139,23 @@ public:
     bool is_colocated_operator() const override;
     bool is_shuffled_operator() const override;
 
+    // Returns the current in-memory hash table size for the active partition.
+    // The scheduler uses this to decide whether to trigger revoke_memory.
+    size_t revocable_mem_size(RuntimeState* state) const override;
+
+    // Called by the pipeline task scheduler under memory pressure. Flushes the
+    // current in-memory aggregation hash table to sub-spill-files and repartitions,
+    // freeing the hash table memory so it can be recovered in smaller slices.
+    Status revoke_memory(RuntimeState* state) override;
+
 private:
     friend class PartitionedAggLocalState;
 
     std::unique_ptr<AggSourceOperatorX> _agg_source_operator;
+    // number of spill partitions configured for this operator
+    size_t _partition_count = 0;
+    // max repartition depth (configured from session variable in FE)
+    int _repartition_max_depth = SpillRepartitioner::MAX_DEPTH;
 };
 #include "common/compile_check_end.h"
 } // namespace doris
diff --git a/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp b/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp
index 69950ad41a7..d5267969cd4 100644
--- a/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp
+++ b/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp
@@ -20,6 +20,7 @@
 #include <gen_cpp/Metrics_types.h>
 #include <glog/logging.h>
 
+#include <limits>
 #include <memory>
 #include <utility>
 
@@ -28,12 +29,16 @@
 #include "common/status.h"
 #include "core/block/block.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
+#include "exec/spill/spill_repartitioner.h"
 #include "runtime/fragment_mgr.h"
 #include "runtime/runtime_profile.h"
 
 namespace doris {
+
 #include "common/compile_check_begin.h"
 
 PartitionedHashJoinProbeLocalState::PartitionedHashJoinProbeLocalState(RuntimeState* state,
@@ -50,19 +55,24 @@ Status PartitionedHashJoinProbeLocalState::init(RuntimeState* state, LocalStateI
     auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
 
     _partitioned_blocks.resize(p._partition_count);
-    _probe_spilling_streams.resize(p._partition_count);
+    _probe_spilling_groups.resize(p._partition_count);
+    _probe_writers.resize(p._partition_count);
+    // The repartitioner fanout will be configured when the repartitioner is
+    // initialized with a fanout-sized partitioner clone in the repartition path.
     init_counters();
     return Status::OK();
 }
 
 void PartitionedHashJoinProbeLocalState::init_counters() {
-    _partition_timer = ADD_TIMER(custom_profile(), "SpillPartitionTime");
-    _partition_shuffle_timer = ADD_TIMER(custom_profile(), "SpillPartitionShuffleTime");
+    _partition_shuffle_timer = ADD_TIMER(custom_profile(), "SpillRePartitionTime");
     _spill_build_rows = ADD_COUNTER(custom_profile(), "SpillBuildRows", TUnit::UNIT);
     _spill_build_timer = ADD_TIMER_WITH_LEVEL(custom_profile(), "SpillBuildTime", 1);
     _recovery_build_rows = ADD_COUNTER(custom_profile(), "SpillRecoveryBuildRows", TUnit::UNIT);
+    _recovery_level0_build_rows =
+            ADD_COUNTER(custom_profile(), "SpillRecoveryLevel0BuildRows", TUnit::UNIT);
     _recovery_build_timer = ADD_TIMER_WITH_LEVEL(custom_profile(), "SpillRecoveryBuildTime", 1);
     _spill_probe_rows = ADD_COUNTER(custom_profile(), "SpillProbeRows", TUnit::UNIT);
+    _build_rows = ADD_COUNTER(custom_profile(), "BuildRows", TUnit::UNIT);
     _recovery_probe_rows = ADD_COUNTER(custom_profile(), "SpillRecoveryProbeRows", TUnit::UNIT);
     _spill_build_blocks = ADD_COUNTER(custom_profile(), "SpillBuildBlocks", TUnit::UNIT);
     _recovery_build_blocks = ADD_COUNTER(custom_profile(), "SpillRecoveryBuildBlocks", TUnit::UNIT);
@@ -73,9 +83,13 @@ void PartitionedHashJoinProbeLocalState::init_counters() {
     _get_child_next_timer = ADD_TIMER_WITH_LEVEL(custom_profile(), "GetChildNextTime", 1);
 
     _probe_blocks_bytes =
-            ADD_COUNTER_WITH_LEVEL(custom_profile(), "ProbeBloksBytesInMem", TUnit::BYTES, 1);
+            ADD_COUNTER_WITH_LEVEL(custom_profile(), "ProbeBlocksBytesInMem", TUnit::BYTES, 1);
     _memory_usage_reserved =
             ADD_COUNTER_WITH_LEVEL(custom_profile(), "MemoryUsageReserved", TUnit::BYTES, 1);
+
+    // Counters for partition spill metrics
+    _max_partition_level = ADD_COUNTER(custom_profile(), "SpillMaxPartitionLevel", TUnit::UNIT);
+    _total_partition_spills = ADD_COUNTER(custom_profile(), "SpillTotalPartitions", TUnit::UNIT);
 }
 
 template <bool spilled>
@@ -131,11 +145,11 @@ void PartitionedHashJoinProbeLocalState::update_probe_common_profile(
 
 void PartitionedHashJoinProbeLocalState::update_profile_from_inner() {
     auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
-    if (_shared_state->inner_runtime_state) {
-        auto* sink_local_state = _shared_state->inner_runtime_state->get_sink_local_state();
-        auto* probe_local_state = _shared_state->inner_runtime_state->get_local_state(
+    if (_shared_state->_inner_runtime_state) {
+        auto* sink_local_state = _shared_state->_inner_runtime_state->get_sink_local_state();
+        auto* probe_local_state = _shared_state->_inner_runtime_state->get_local_state(
                 p._inner_probe_operator->operator_id());
-        if (_shared_state->is_spilled) {
+        if (_shared_state->_is_spilled) {
             update_build_custom_profile<true>(sink_local_state->custom_profile());
             update_probe_custom_profile<true>(probe_local_state->custom_profile());
             update_build_common_profile<true>(sink_local_state->common_profile());
@@ -151,8 +165,24 @@ void PartitionedHashJoinProbeLocalState::update_profile_from_inner() {
 
 Status PartitionedHashJoinProbeLocalState::open(RuntimeState* state) {
     RETURN_IF_ERROR(PipelineXSpillLocalState::open(state));
-    return _parent->cast<PartitionedHashJoinProbeOperatorX>()._partitioner->clone(state,
-                                                                                  _partitioner);
+    auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
+    RETURN_IF_ERROR(p._partitioner->clone(state, _partitioner));
+
+    // Create a fanout-sized partitioner for repartitioning.
+    // Use operator-configured partition count instead of static FANOUT.
+    _fanout_partitioner =
+            std::make_unique<SpillRePartitionerType>(static_cast<int>(p._partition_count));
+    RETURN_IF_ERROR(_fanout_partitioner->init(p._probe_exprs));
+    RETURN_IF_ERROR(_fanout_partitioner->prepare(state, p._child->row_desc()));
+    RETURN_IF_ERROR(_fanout_partitioner->open(state));
+
+    _build_fanout_partitioner =
+            std::make_unique<SpillRePartitionerType>(static_cast<int>(p._partition_count));
+    RETURN_IF_ERROR(_build_fanout_partitioner->init(p._build_exprs));
+    RETURN_IF_ERROR(_build_fanout_partitioner->prepare(state, p._build_side_child->row_desc()));
+    RETURN_IF_ERROR(_build_fanout_partitioner->open(state));
+
+    return Status::OK();
 }
 Status PartitionedHashJoinProbeLocalState::close(RuntimeState* state) {
     SCOPED_TIMER(exec_time_counter());
@@ -160,334 +190,340 @@ Status PartitionedHashJoinProbeLocalState::close(RuntimeState* state) {
     if (_closed) {
         return Status::OK();
     }
-    RETURN_IF_ERROR(PipelineXSpillLocalState::close(state));
-    return Status::OK();
-}
 
-Status PartitionedHashJoinProbeLocalState::_execute_spill_probe_blocks(RuntimeState* state,
-                                                                       const UniqueId& query_id) {
-    SCOPED_TIMER(_spill_probe_timer);
-
-    size_t not_revoked_size = 0;
-    auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
-    for (uint32_t partition_index = 0; partition_index != p._partition_count; ++partition_index) {
-        auto& blocks = _probe_blocks[partition_index];
-        auto& partitioned_block = _partitioned_blocks[partition_index];
-        if (partitioned_block) {
-            const auto size = partitioned_block->allocated_bytes();
-            if (size >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
-                blocks.emplace_back(partitioned_block->to_block());
-                partitioned_block.reset();
-            } else {
-                not_revoked_size += size;
+    Status first_error;
+    for (auto& writer : _probe_writers) {
+        if (writer) {
+            auto st = writer->close();
+            if (!st.ok() && first_error.ok()) {
+                first_error = st;
             }
+            writer.reset();
         }
+    }
+    _probe_writers.clear();
 
-        if (blocks.empty()) {
-            continue;
+    if (_current_build_reader) {
+        auto st = _current_build_reader->close();
+        if (!st.ok() && first_error.ok()) {
+            first_error = st;
         }
-
-        auto& spilling_stream = _probe_spilling_streams[partition_index];
-        if (!spilling_stream) {
-            RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-                    state, spilling_stream, print_id(state->query_id()), "hash_probe",
-                    _parent->node_id(), std::numeric_limits<int32_t>::max(),
-                    std::numeric_limits<size_t>::max(), operator_profile()));
+        _current_build_reader.reset();
+    }
+    if (_current_probe_reader) {
+        auto st = _current_probe_reader->close();
+        if (!st.ok() && first_error.ok()) {
+            first_error = st;
         }
+        _current_probe_reader.reset();
+    }
 
-        auto merged_block = MutableBlock::create_unique(std::move(blocks.back()));
-        blocks.pop_back();
-
-        while (!blocks.empty() && !state->is_cancelled()) {
-            auto block = std::move(blocks.back());
-            blocks.pop_back();
-
-            RETURN_IF_ERROR(merged_block->merge(std::move(block)));
-            DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::spill_probe_blocks", {
-                return Status::Error<INTERNAL_ERROR>(
-                        "fault_inject partitioned_hash_join_probe "
-                        "spill_probe_blocks failed");
-            });
+    // Clean up any remaining spill partition queue entries
+    for (auto& entry : _spill_partition_queue) {
+        if (entry.build_file) {
+            ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(entry.build_file);
         }
-
-        if (!merged_block->empty()) [[likely]] {
-            COUNTER_UPDATE(_spill_probe_rows, merged_block->rows());
-            RETURN_IF_ERROR(spilling_stream->spill_block(state, merged_block->to_block(), false));
-            COUNTER_UPDATE(_spill_probe_blocks, 1);
+        if (entry.probe_file) {
+            ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(entry.probe_file);
         }
     }
+    _spill_partition_queue.clear();
+    if (_current_partition.build_file) {
+        ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(_current_partition.build_file);
+    }
+    if (_current_partition.probe_file) {
+        ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(_current_partition.probe_file);
+    }
+    _current_partition = JoinSpillPartitionInfo {};
+    _queue_probe_blocks.clear();
 
-    COUNTER_SET(_probe_blocks_bytes, int64_t(not_revoked_size));
-
-    VLOG_DEBUG << fmt::format(
-            "Query:{}, hash join probe:{}, task:{},"
-            " spill_probe_blocks done",
-            print_id(query_id), p.node_id(), state->task_id());
-    return Status::OK();
-}
-
-Status PartitionedHashJoinProbeLocalState::spill_probe_blocks(RuntimeState* state) {
-    auto query_id = state->query_id();
-
-    auto exception_catch_func = [this, query_id, state]() {
-        DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::spill_probe_blocks_cancel", {
-            auto status = Status::InternalError(
-                    "fault_inject partitioned_hash_join_probe "
-                    "spill_probe_blocks canceled");
-            state->get_query_ctx()->cancel(status);
-            return status;
-        });
-
-        auto status = [&]() {
-            RETURN_IF_CATCH_EXCEPTION({ return _execute_spill_probe_blocks(state, query_id); });
-        }();
-        return status;
-    };
-
-    DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::spill_probe_blocks_submit_func", {
-        return Status::Error<INTERNAL_ERROR>(
-                "fault_inject partitioned_hash_join_probe spill_probe_blocks "
-                "submit_func failed");
-    });
-
-    SpillNonSinkRunnable spill_runnable(state, operator_profile(), exception_catch_func);
-    return spill_runnable.run();
+    auto st = PipelineXSpillLocalState::close(state);
+    if (!first_error.ok()) {
+        return first_error;
+    }
+    return st;
 }
 
-Status PartitionedHashJoinProbeLocalState::finish_spilling(uint32_t partition_index) {
-    auto& probe_spilling_stream = _probe_spilling_streams[partition_index];
-
-    if (probe_spilling_stream) {
-        RETURN_IF_ERROR(probe_spilling_stream->spill_eof());
-        probe_spilling_stream->set_read_counters(operator_profile());
+Status PartitionedHashJoinProbeLocalState::acquire_spill_writer(RuntimeState* state,
+                                                                int partition_index,
+                                                                SpillFileWriterSPtr& writer) {
+    if (!_probe_writers[partition_index]) {
+        auto& spill_file = _probe_spilling_groups[partition_index];
+        auto relative_path = fmt::format("{}/{}-{}-{}-{}", print_id(state->query_id()),
+                                         "hash_probe", _parent->node_id(), state->task_id(),
+                                         ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+        RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(relative_path,
+                                                                                    spill_file));
+        RETURN_IF_ERROR(spill_file->create_writer(state, operator_profile(),
+                                                  _probe_writers[partition_index]));
     }
-
+    writer = _probe_writers[partition_index];
     return Status::OK();
 }
 
-Status PartitionedHashJoinProbeLocalState::recover_build_blocks_from_disk(RuntimeState* state,
-                                                                          uint32_t partition_index,
-                                                                          bool& has_data) {
-    VLOG_DEBUG << fmt::format(
-            "Query:{}, hash join probe:{}, task:{},"
-            " partition:{}, recover_build_blocks_from_disk",
-            print_id(state->query_id()), _parent->node_id(), state->task_id(), partition_index);
-    auto& spilled_stream = _shared_state->spilled_streams[partition_index];
-    has_data = false;
-    if (!spilled_stream) {
-        return Status::OK();
-    }
-    spilled_stream->set_read_counters(operator_profile());
-
+Status PartitionedHashJoinProbeLocalState::spill_probe_blocks(RuntimeState* state, bool flush_all) {
     auto query_id = state->query_id();
+    SCOPED_TIMER(_spill_probe_timer);
 
-    auto read_func = [this, query_id, state, spilled_stream = spilled_stream, partition_index] {
-        SCOPED_TIMER(_recovery_build_timer);
-
-        bool eos = false;
-        VLOG_DEBUG << fmt::format(
-                "Query:{}, hash join probe:{}, task:{},"
-                " partition:{}, recoverying build data",
-                print_id(state->query_id()), _parent->node_id(), state->task_id(), partition_index);
-        Status status;
-        while (!eos) {
-            Block block;
-            DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::recover_build_blocks", {
-                status = Status::Error<INTERNAL_ERROR>(
-                        "fault_inject partitioned_hash_join_probe "
-                        "recover_build_blocks failed");
-            });
-            if (status.ok()) {
-                status = spilled_stream->read_next_block_sync(&block, &eos);
-            }
-            if (!status.ok()) {
-                break;
-            }
-            COUNTER_UPDATE(_recovery_build_rows, block.rows());
-            COUNTER_UPDATE(_recovery_build_blocks, 1);
-
-            if (block.empty()) {
-                continue;
-            }
-
-            if (UNLIKELY(state->is_cancelled())) {
-                LOG(INFO) << fmt::format(
-                        "Query:{}, hash join probe:{}, task:{},"
-                        " partition:{}, recovery build data canceled",
-                        print_id(state->query_id()), _parent->node_id(), state->task_id(),
-                        partition_index);
-                break;
-            }
-
-            if (!_recovered_build_block) {
-                _recovered_build_block = MutableBlock::create_unique(std::move(block));
-            } else {
-                DCHECK_EQ(_recovered_build_block->columns(), block.columns());
-                status = _recovered_build_block->merge(std::move(block));
-                if (!status.ok()) {
-                    break;
-                }
-            }
-
-            if (_recovered_build_block->allocated_bytes() >=
-                SpillStream::MAX_SPILL_WRITE_BATCH_MEM) {
-                break;
-            }
+    DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::spill_probe_blocks_cancel", {
+        return Status::InternalError(
+                "fault_inject partitioned_hash_join_probe "
+                "spill_probe_blocks canceled");
+    });
+    auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
+    for (uint32_t partition_index = 0; partition_index != p._partition_count; ++partition_index) {
+        auto& partitioned_block = _partitioned_blocks[partition_index];
+        if (!partitioned_block || partitioned_block->empty()) {
+            continue;
         }
 
-        if (eos) {
-            ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(spilled_stream);
-            _shared_state->spilled_streams[partition_index].reset();
-            VLOG_DEBUG << fmt::format(
-                    "Query:{}, hash join probe:{}, task:{},"
-                    " partition:{}, recovery build data eos",
-                    print_id(state->query_id()), _parent->node_id(), state->task_id(),
-                    partition_index);
+        if (!flush_all &&
+            partitioned_block->allocated_bytes() < SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
+            continue;
         }
-        return status;
-    };
 
-    auto exception_catch_func = [read_func, state, query_id]() {
-        DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::recover_build_blocks_cancel", {
-            auto status = Status::InternalError(
-                    "fault_inject partitioned_hash_join_probe "
-                    "recover_build_blocks canceled");
+        SpillFileWriterSPtr writer;
+        RETURN_IF_ERROR(acquire_spill_writer(state, partition_index, writer));
 
-            state->get_query_ctx()->cancel(status);
-            return status;
+        DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::spill_probe_blocks", {
+            return Status::Error<INTERNAL_ERROR>(
+                    "fault_inject partitioned_hash_join_probe "
+                    "spill_probe_blocks failed");
         });
 
-        auto status = [&]() {
-            RETURN_IF_ERROR_OR_CATCH_EXCEPTION(read_func());
-            return Status::OK();
-        }();
-
-        return status;
-    };
-
-    has_data = true;
-    DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::recovery_build_blocks_submit_func",
-                    {
-                        return Status::Error<INTERNAL_ERROR>(
-                                "fault_inject partitioned_hash_join_probe "
-                                "recovery_build_blocks submit_func failed");
-                    });
+        COUNTER_UPDATE(_spill_probe_rows, partitioned_block->rows());
+        RETURN_IF_ERROR(writer->write_block(state, partitioned_block->to_block()));
+        COUNTER_UPDATE(_spill_probe_blocks, 1);
+        partitioned_block.reset();
+    }
 
-    SpillRecoverRunnable spill_runnable(state, operator_profile(), exception_catch_func);
-    return spill_runnable.run();
+    VLOG_DEBUG << fmt::format(
+            "Query:{}, hash join probe:{}, task:{},"
+            " spill_probe_blocks done",
+            print_id(query_id), p.node_id(), state->task_id());
+    return Status::OK();
 }
 
 std::string PartitionedHashJoinProbeLocalState::debug_string(int indentation_level) const {
     auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
     bool need_more_input_data;
-    if (_shared_state->is_spilled) {
+    if (_shared_state->_is_spilled) {
         need_more_input_data = !_child_eos;
-    } else if (_shared_state->inner_runtime_state) {
+    } else if (_shared_state->_inner_runtime_state) {
         need_more_input_data = p._inner_probe_operator->need_more_input_data(
-                _shared_state->inner_runtime_state.get());
+                _shared_state->_inner_runtime_state.get());
     } else {
         need_more_input_data = true;
     }
     fmt::memory_buffer debug_string_buffer;
     fmt::format_to(debug_string_buffer,
                    "{}, short_circuit_for_probe: {}, is_spilled: {}, child_eos: {}, "
-                   "_shared_state->inner_runtime_state: {}, need_more_input_data: {}",
+                   "_shared_state->_inner_runtime_state: {}, need_more_input_data: {}",
                    PipelineXSpillLocalState<PartitionedHashJoinSharedState>::debug_string(
                            indentation_level),
                    _shared_state ? std::to_string(_shared_state->short_circuit_for_probe) : "NULL",
-                   _shared_state->is_spilled, _child_eos,
-                   _shared_state->inner_runtime_state != nullptr, need_more_input_data);
+                   _shared_state->_is_spilled, _child_eos,
+                   _shared_state->_inner_runtime_state != nullptr, need_more_input_data);
     return fmt::to_string(debug_string_buffer);
 }
 
-Status PartitionedHashJoinProbeLocalState::recover_probe_blocks_from_disk(RuntimeState* state,
-                                                                          uint32_t partition_index,
-                                                                          bool& has_data) {
-    auto& spilled_stream = _probe_spilling_streams[partition_index];
-    has_data = false;
-    if (!spilled_stream) {
+bool PartitionedHashJoinProbeLocalState::is_blockable() const {
+    return _shared_state->_is_spilled;
+}
+
+Status PartitionedHashJoinProbeLocalState::recover_build_blocks_from_partition(
+        RuntimeState* state, JoinSpillPartitionInfo& partition_info) {
+    if (!partition_info.build_file) {
+        // Build file is already exhausted for this partition.
         return Status::OK();
     }
+    SCOPED_TIMER(_recovery_build_timer);
+    DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::recover_build_blocks", {
+        return Status::InternalError(
+                "fault_inject partitioned_hash_join_probe "
+                "recover_build_blocks failed");
+    });
+    // Create reader if needed (persistent across scheduling slices)
+    if (!_current_build_reader) {
+        _current_build_reader = partition_info.build_file->create_reader(state, operator_profile());
+        RETURN_IF_ERROR(_current_build_reader->open());
+    }
+    bool eos = false;
+    while (!eos) {
+        Block block;
+        RETURN_IF_ERROR(_current_build_reader->read(&block, &eos));
+        COUNTER_UPDATE(_recovery_build_rows, block.rows());
+        if (partition_info.level == 0) {
+            COUNTER_UPDATE(_recovery_level0_build_rows, block.rows());
+        }
+        if (block.empty()) {
+            continue;
+        }
+        COUNTER_UPDATE(_recovery_build_blocks, 1);
+        if (UNLIKELY(state->is_cancelled())) {
+            return state->cancel_reason();
+        }
+        if (!_recovered_build_block) {
+            // This will merge the block to recover build block, so that has to use else here.
+            _recovered_build_block = MutableBlock::create_unique(std::move(block));
+        } else {
+            RETURN_IF_ERROR(_recovered_build_block->merge(std::move(block)));
+        }
+        if (_recovered_build_block->allocated_bytes() >= state->spill_buffer_size_bytes()) {
+            return Status::OK(); // yield — buffer full, more data may remain
+        }
+    }
+    // Build file fully consumed.
+    RETURN_IF_ERROR(_current_build_reader->close());
+    _current_build_reader.reset();
+    partition_info.build_file.reset();
+    return Status::OK();
+}
 
-    spilled_stream->set_read_counters(operator_profile());
-    auto& blocks = _probe_blocks[partition_index];
+Status PartitionedHashJoinProbeLocalState::recover_probe_blocks_from_partition(
+        RuntimeState* state, JoinSpillPartitionInfo& partition_info) {
+    if (!partition_info.probe_file) {
+        // Probe file is already exhausted for this partition.
+        return Status::OK();
+    }
 
-    auto query_id = state->query_id();
+    // For multi-level queue partitions, store recovered probe blocks in _queue_probe_blocks.
+    SCOPED_TIMER(_recovery_probe_timer);
+    size_t read_size = 0;
+    // Create reader if needed
+    if (!_current_probe_reader) {
+        _current_probe_reader = partition_info.probe_file->create_reader(state, operator_profile());
+        RETURN_IF_ERROR(_current_probe_reader->open());
+    }
+    bool eos = false;
+    while (!eos && !state->is_cancelled()) {
+        Block block;
+        RETURN_IF_ERROR(_current_probe_reader->read(&block, &eos));
+        if (!block.empty()) {
+            COUNTER_UPDATE(_recovery_probe_rows, block.rows());
+            COUNTER_UPDATE(_recovery_probe_blocks, 1);
+            read_size += block.allocated_bytes();
+            _queue_probe_blocks.emplace_back(std::move(block));
+        }
+        if (read_size >= state->spill_buffer_size_bytes()) {
+            return Status::OK(); // yield — enough data read
+        }
+    }
+    // Probe file fully consumed.
+    RETURN_IF_ERROR(_current_probe_reader->close());
+    _current_probe_reader.reset();
+    partition_info.probe_file.reset();
+    return Status::OK();
+}
 
-    auto read_func = [this, query_id, partition_index, &spilled_stream, &blocks] {
-        SCOPED_TIMER(_recovery_probe_timer);
+Status PartitionedHashJoinProbeLocalState::repartition_current_partition(
+        RuntimeState* state, JoinSpillPartitionInfo& partition) {
+    auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
+    const int new_level = partition.level + 1;
 
-        Block block;
-        bool eos = false;
-        Status st;
-        DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::recover_probe_blocks", {
-            st = Status::Error<INTERNAL_ERROR>(
-                    "fault_inject partitioned_hash_join_probe recover_probe_blocks failed");
-        });
+    if (new_level >= p._repartition_max_depth) {
+        return Status::InternalError(
+                "query:{}, node:{}, Hash join spill repartition exceeded max depth {}. "
+                "Likely due to extreme data skew.",
+                print_id(state->query_id()), p.node_id(), p._repartition_max_depth);
+    }
 
-        size_t read_size = 0;
-        while (!eos && !_state->is_cancelled() && st.ok()) {
-            st = spilled_stream->read_next_block_sync(&block, &eos);
-            if (!st.ok()) {
-                break;
-            } else if (!block.empty()) {
-                COUNTER_UPDATE(_recovery_probe_rows, block.rows());
-                COUNTER_UPDATE(_recovery_probe_blocks, 1);
-                read_size += block.allocated_bytes();
-                blocks.emplace_back(std::move(block));
-            }
+    VLOG_DEBUG << fmt::format(
+            "Query:{}, hash join probe:{}, task:{}, repartitioning partition at level {} to "
+            "level {}",
+            print_id(state->query_id()), p.node_id(), state->task_id(), partition.level, new_level);
+
+    // Create a partitioner for repartitioning build data.
+    std::unique_ptr<PartitionerBase> build_fanout_clone;
+    RETURN_IF_ERROR(_build_fanout_partitioner->clone(state, build_fanout_clone));
+    _repartitioner.init(std::move(build_fanout_clone), operator_profile(),
+                        static_cast<int>(p._partition_count), new_level);
+
+    // Repartition build files
+    std::vector<SpillFileSPtr> build_output_spill_files;
+    RETURN_IF_ERROR(SpillRepartitioner::create_output_spill_files(
+            state, p.node_id(), fmt::format("hash_build_repart_l{}", new_level),
+            static_cast<int>(p._partition_count), build_output_spill_files));
+
+    RETURN_IF_ERROR(_repartitioner.setup_output(state, build_output_spill_files));
+
+    // Route already-recovered in-memory build data first — these rows have
+    // already been read from the file by _current_build_reader and must not
+    // be re-read by the repartitioner.
+    if (_recovered_build_block && _recovered_build_block->rows() > 0) {
+        auto recovered_block = _recovered_build_block->to_block();
+        RETURN_IF_ERROR(_repartitioner.route_block(state, recovered_block));
+    }
 
-            if (read_size >= SpillStream::MAX_SPILL_WRITE_BATCH_MEM) {
-                break;
-            }
+    // Repartition the remaining unread portion of the build file.
+    // If _current_build_reader exists the file was partially read; pass the
+    // reader directly so the repartitioner continues from the current
+    // position instead of re-reading from block 0 (which would duplicate
+    // the rows already routed above).
+    if (_current_build_reader) {
+        bool done = false;
+        while (!done && !state->is_cancelled()) {
+            RETURN_IF_ERROR(_repartitioner.repartition(state, _current_build_reader, &done));
         }
-        if (eos) {
-            VLOG_DEBUG << fmt::format(
-                    "Query:{}, hash join probe:{}, task:{},"
-                    " partition:{}, recovery probe data done",
-                    print_id(query_id), _parent->node_id(), _state->task_id(), partition_index);
-            ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(spilled_stream);
-            spilled_stream.reset();
+        // reader is reset by repartitioner on completion
+    } else if (partition.build_file) {
+        // No partial read — repartition the entire file from scratch.
+        bool done = false;
+        while (!done && !state->is_cancelled()) {
+            RETURN_IF_ERROR(_repartitioner.repartition(state, partition.build_file, &done));
+        }
+    }
+    RETURN_IF_ERROR(_repartitioner.finalize());
+    _recovered_build_block.reset();
+    _current_build_reader.reset(); // clear any leftover reader state
+    partition.build_file.reset();
+
+    // Repartition probe files
+    std::vector<SpillFileSPtr> probe_output_spill_files;
+    RETURN_IF_ERROR(SpillRepartitioner::create_output_spill_files(
+            state, p.node_id(), fmt::format("hash_probe_repart_l{}", new_level),
+            static_cast<int>(p._partition_count), probe_output_spill_files));
+
+    if (partition.probe_file) {
+        // Re-init repartitioner with a fresh FANOUT partitioner clone for probe data
+        std::unique_ptr<PartitionerBase> probe_fanout_clone;
+        RETURN_IF_ERROR(_fanout_partitioner->clone(state, probe_fanout_clone));
+        _repartitioner.init(std::move(probe_fanout_clone), operator_profile(),
+                            static_cast<int>(p._partition_count), new_level);
+
+        RETURN_IF_ERROR(_repartitioner.setup_output(state, probe_output_spill_files));
+
+        bool done = false;
+        while (!done && !state->is_cancelled()) {
+            RETURN_IF_ERROR(_repartitioner.repartition(state, partition.probe_file, &done));
         }
-        return st;
-    };
+        partition.probe_file.reset();
 
-    auto exception_catch_func = [read_func, state, query_id]() {
-        DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::recover_probe_blocks_cancel", {
-            auto status = Status::InternalError(
-                    "fault_inject partitioned_hash_join_probe "
-                    "recover_probe_blocks canceled");
-            state->get_query_ctx()->cancel(status);
-            return status;
-        });
+        RETURN_IF_ERROR(_repartitioner.finalize());
+        _current_probe_reader.reset();
+    }
 
-        auto status = [&]() {
-            RETURN_IF_ERROR_OR_CATCH_EXCEPTION(read_func());
-            return Status::OK();
-        }();
-
-        return status;
-    };
-
-    has_data = true;
-    DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::recovery_probe_blocks_submit_func",
-                    {
-                        return Status::Error<INTERNAL_ERROR>(
-                                "fault_inject partitioned_hash_join_probe "
-                                "recovery_probe_blocks submit_func failed");
-                    });
-    return SpillRecoverRunnable(state, operator_profile(), exception_catch_func).run();
-}
+    // Push all sub-partitions into work queue; build/probe emptiness is handled
+    // later during recovery.  New sub-partitions start with build_finished =
+    // probe_finished = false (via constructor).
+    for (int i = 0; i < static_cast<int>(p._partition_count); ++i) {
+        _spill_partition_queue.emplace_back(std::move(build_output_spill_files[i]),
+                                            std::move(probe_output_spill_files[i]), new_level);
+        // Metrics
+        COUNTER_UPDATE(_total_partition_spills, 1);
+        if (new_level > _max_partition_level_seen) {
+            _max_partition_level_seen = new_level;
+            COUNTER_SET(_max_partition_level, int64_t(_max_partition_level_seen));
+        }
+    }
 
-bool PartitionedHashJoinProbeLocalState::is_blockable() const {
-    return _shared_state->is_spilled;
+    return Status::OK();
 }
 
 PartitionedHashJoinProbeOperatorX::PartitionedHashJoinProbeOperatorX(ObjectPool* pool,
                                                                      const TPlanNode& tnode,
                                                                      int operator_id,
-                                                                     const DescriptorTbl& descs,
-                                                                     uint32_t partition_count)
+                                                                     const DescriptorTbl& descs)
         : JoinProbeOperatorX<PartitionedHashJoinProbeLocalState>(pool, tnode, operator_id, descs),
           _join_distribution(tnode.hash_join_node.__isset.dist_type ? tnode.hash_join_node.dist_type
                                                                     : TJoinDistributionType::NONE),
@@ -495,10 +531,18 @@ PartitionedHashJoinProbeOperatorX::PartitionedHashJoinProbeOperatorX(ObjectPool*
                                                 ? tnode.distribute_expr_lists[0]
                                                 : std::vector<TExpr> {}),
           _tnode(tnode),
-          _descriptor_tbl(descs),
-          _partition_count(partition_count) {}
+          _descriptor_tbl(descs) {}
 
 Status PartitionedHashJoinProbeOperatorX::init(const TPlanNode& tnode, RuntimeState* state) {
+    _partition_count = state->spill_hash_join_partition_count();
+    if (_partition_count < 2 || _partition_count > 32) {
+        return Status::InternalError(
+                "query:{}, node:{}, invalid partition count {}. Must be between 2 and 32.",
+                print_id(state->query_id()), node_id(), _partition_count);
+    }
+
+    // default repartition max depth; can be overridden from session variable
+    _repartition_max_depth = state->spill_repartition_max_depth();
     RETURN_IF_ERROR(JoinProbeOperatorX::init(tnode, state));
     _op_name = "PARTITIONED_HASH_JOIN_PROBE_OPERATOR";
     auto tnode_ = _tnode;
@@ -506,6 +550,7 @@ Status PartitionedHashJoinProbeOperatorX::init(const TPlanNode& tnode, RuntimeSt
 
     for (const auto& conjunct : tnode.hash_join_node.eq_join_conjuncts) {
         _probe_exprs.emplace_back(conjunct.left);
+        _build_exprs.emplace_back(conjunct.right);
     }
     _partitioner = std::make_unique<SpillPartitionerType>(_partition_count);
     RETURN_IF_ERROR(_partitioner->init(_probe_exprs));
@@ -535,20 +580,11 @@ Status PartitionedHashJoinProbeOperatorX::push(RuntimeState* state, Block* input
     const auto rows = input_block->rows();
     auto& partitioned_blocks = local_state._partitioned_blocks;
     if (rows == 0) {
-        if (eos) {
-            for (uint32_t i = 0; i != _partition_count; ++i) {
-                if (partitioned_blocks[i] && !partitioned_blocks[i]->empty()) {
-                    local_state._probe_blocks[i].emplace_back(partitioned_blocks[i]->to_block());
-                    partitioned_blocks[i].reset();
-                }
-            }
-        }
         return Status::OK();
     }
-    {
-        SCOPED_TIMER(local_state._partition_timer);
-        RETURN_IF_ERROR(local_state._partitioner->do_partitioning(state, input_block));
-    }
+    SCOPED_TIMER(local_state._partition_shuffle_timer);
+
+    RETURN_IF_ERROR(local_state._partitioner->do_partitioning(state, input_block));
 
     std::vector<std::vector<uint32_t>> partition_indexes(_partition_count);
     const auto& channel_ids = local_state._partitioner->get_channel_ids();
@@ -556,7 +592,6 @@ Status PartitionedHashJoinProbeOperatorX::push(RuntimeState* state, Block* input
         partition_indexes[channel_ids[i]].emplace_back(i);
     }
 
-    SCOPED_TIMER(local_state._partition_shuffle_timer);
     int64_t bytes_of_blocks = 0;
     for (uint32_t i = 0; i != _partition_count; ++i) {
         const auto count = partition_indexes[i].size();
@@ -570,16 +605,17 @@ Status PartitionedHashJoinProbeOperatorX::push(RuntimeState* state, Block* input
         RETURN_IF_ERROR(partitioned_blocks[i]->add_rows(input_block, partition_indexes[i].data(),
                                                         partition_indexes[i].data() + count));
 
-        if (partitioned_blocks[i]->rows() > 2 * 1024 * 1024 ||
-            (eos && partitioned_blocks[i]->rows() > 0)) {
-            local_state._probe_blocks[i].emplace_back(partitioned_blocks[i]->to_block());
+        const auto bytes = partitioned_blocks[i]->allocated_bytes();
+        if (bytes >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
+            SpillFileWriterSPtr writer;
+            RETURN_IF_ERROR(local_state.acquire_spill_writer(state, i, writer));
+
+            COUNTER_UPDATE(local_state._spill_probe_rows, partitioned_blocks[i]->rows());
+            RETURN_IF_ERROR(writer->write_block(state, partitioned_blocks[i]->to_block()));
+            COUNTER_UPDATE(local_state._spill_probe_blocks, 1);
             partitioned_blocks[i].reset();
         } else {
-            bytes_of_blocks += partitioned_blocks[i]->allocated_bytes();
-        }
-
-        for (auto& block : local_state._probe_blocks[i]) {
-            bytes_of_blocks += block.allocated_bytes();
+            bytes_of_blocks += bytes;
         }
     }
 
@@ -588,24 +624,23 @@ Status PartitionedHashJoinProbeOperatorX::push(RuntimeState* state, Block* input
     return Status::OK();
 }
 
-Status PartitionedHashJoinProbeOperatorX::_setup_internal_operators(
+Status PartitionedHashJoinProbeOperatorX::_setup_internal_operators_from_partition(
         PartitionedHashJoinProbeLocalState& local_state, RuntimeState* state) const {
-    local_state._shared_state->inner_runtime_state = RuntimeState::create_unique(
+    local_state._shared_state->_inner_runtime_state = RuntimeState::create_unique(
             state->fragment_instance_id(), state->query_id(), state->fragment_id(),
             state->query_options(), TQueryGlobals {}, state->exec_env(), state->get_query_ctx());
 
-    local_state._shared_state->inner_runtime_state->set_task_execution_context(
+    local_state._shared_state->_inner_runtime_state->set_task_execution_context(
             state->get_task_execution_context().lock());
-    local_state._shared_state->inner_runtime_state->set_be_number(state->be_number());
+    local_state._shared_state->_inner_runtime_state->set_be_number(state->be_number());
 
-    local_state._shared_state->inner_runtime_state->set_desc_tbl(&state->desc_tbl());
-    local_state._shared_state->inner_runtime_state->resize_op_id_to_local_state(-1);
-    local_state._shared_state->inner_runtime_state->set_runtime_filter_mgr(
+    local_state._shared_state->_inner_runtime_state->set_desc_tbl(&state->desc_tbl());
+    local_state._shared_state->_inner_runtime_state->resize_op_id_to_local_state(-1);
+    local_state._shared_state->_inner_runtime_state->set_runtime_filter_mgr(
             state->local_runtime_filter_mgr());
 
     local_state._in_mem_shared_state_sptr = _inner_sink_operator->create_shared_state();
 
-    // set sink local state
     LocalSinkStateInfo info {.task_idx = 0,
                              .parent_profile = local_state._internal_runtime_profile.get(),
                              .sender_id = -1,
@@ -613,7 +648,7 @@ Status PartitionedHashJoinProbeOperatorX::_setup_internal_operators(
                              .shared_state_map = {},
                              .tsink = {}};
     RETURN_IF_ERROR(_inner_sink_operator->setup_local_state(
-            local_state._shared_state->inner_runtime_state.get(), info));
+            local_state._shared_state->_inner_runtime_state.get(), info));
 
     LocalStateInfo state_info {.parent_profile = local_state._internal_runtime_profile.get(),
                                .scan_ranges = {},
@@ -621,38 +656,37 @@ Status PartitionedHashJoinProbeOperatorX::_setup_internal_operators(
                                .shared_state_map = {},
                                .task_idx = 0};
     RETURN_IF_ERROR(_inner_probe_operator->setup_local_state(
-            local_state._shared_state->inner_runtime_state.get(), state_info));
+            local_state._shared_state->_inner_runtime_state.get(), state_info));
 
-    auto* sink_local_state = local_state._shared_state->inner_runtime_state->get_sink_local_state();
+    auto* sink_local_state =
+            local_state._shared_state->_inner_runtime_state->get_sink_local_state();
     DCHECK(sink_local_state != nullptr);
     RETURN_IF_ERROR(sink_local_state->open(state));
 
-    auto* probe_local_state = local_state._shared_state->inner_runtime_state->get_local_state(
+    auto* probe_local_state = local_state._shared_state->_inner_runtime_state->get_local_state(
             _inner_probe_operator->operator_id());
     DCHECK(probe_local_state != nullptr);
     RETURN_IF_ERROR(probe_local_state->open(state));
 
-    auto& partitioned_block =
-            local_state._shared_state->partitioned_build_blocks[local_state._partition_cursor];
+    // Use the recovered build block from the partition stream
     Block block;
-    if (partitioned_block && partitioned_block->rows() > 0) {
-        block = partitioned_block->to_block();
-        partitioned_block.reset();
+    if (local_state._recovered_build_block && local_state._recovered_build_block->rows() > 0) {
+        block = local_state._recovered_build_block->to_block();
+        local_state._recovered_build_block.reset();
     }
-    DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_probe::sink", {
-        return Status::Error<INTERNAL_ERROR>(
-                "fault_inject partitioned_hash_join_probe sink failed");
-    });
 
-    RETURN_IF_ERROR(_inner_sink_operator->sink(local_state._shared_state->inner_runtime_state.get(),
-                                               &block, true));
+    COUNTER_UPDATE(local_state._build_rows, block.rows());
+
+    RETURN_IF_ERROR(_inner_sink_operator->sink(
+            local_state._shared_state->_inner_runtime_state.get(), &block, true));
+    local_state._current_partition.build_finished = true;
     VLOG_DEBUG << fmt::format(
             "Query:{}, hash join probe:{}, task:{},"
-            " internal build operator finished, partition:{}, rows:{}, memory usage:{}",
-            print_id(state->query_id()), node_id(), state->task_id(), local_state._partition_cursor,
-            block.rows(),
+            " internal build from partition (level:{}) finished, rows:{}, memory usage:{}",
+            print_id(state->query_id()), node_id(), state->task_id(),
+            local_state._current_partition.level, block.rows(),
             _inner_sink_operator->get_memory_usage(
-                    local_state._shared_state->inner_runtime_state.get()));
+                    local_state._shared_state->_inner_runtime_state.get()));
     return Status::OK();
 }
 
@@ -660,56 +694,113 @@ Status PartitionedHashJoinProbeOperatorX::pull(doris::RuntimeState* state, Block
                                                bool* eos) const {
     auto& local_state = get_local_state(state);
 
-    const auto partition_index = local_state._partition_cursor;
-    auto& probe_blocks = local_state._probe_blocks[partition_index];
-
-    if (local_state._recovered_build_block && !local_state._recovered_build_block->empty()) {
-        local_state._estimate_memory_usage += local_state._recovered_build_block->allocated_bytes();
-        auto& mutable_block = local_state._shared_state->partitioned_build_blocks[partition_index];
-        if (!mutable_block) {
-            mutable_block = std::move(local_state._recovered_build_block);
-        } else {
-            RETURN_IF_ERROR(mutable_block->merge(local_state._recovered_build_block->to_block()));
-            local_state._recovered_build_block.reset();
+    // On first entry after child EOS, populate _spill_partition_queue from the
+    // per-partition build and probe spill streams. After this point every partition
+    // (including the original "level-0" ones) is accessed uniformly via the queue.
+    if (!local_state._spill_queue_initialized) {
+        DCHECK(local_state._child_eos) << "pull() with is_spilled=true called before child EOS";
+        // There maybe some blocks still in partitioned block or probe blocks. Flush them to disk.
+        RETURN_IF_ERROR(local_state.spill_probe_blocks(state, true));
+        // Close all probe writers so that SpillFile metadata (part_count, etc.)
+        // is finalized and the files become readable. Without this the readers
+        // would see _part_count == 0 and return no data.
+        for (auto& writer : local_state._probe_writers) {
+            if (writer) {
+                RETURN_IF_ERROR(writer->close());
+            }
         }
+        for (uint32_t i = 0; i < _partition_count; ++i) {
+            auto& build_file = local_state._shared_state->_spilled_build_groups[i];
+            auto& probe_file = local_state._probe_spilling_groups[i];
+            // Transfer SpillFiles into JoinSpillPartitionInfo unconditionally.
+            local_state._spill_partition_queue.emplace_back(std::move(build_file),
+                                                            std::move(probe_file), 0);
+            // Metrics: count this queued partition
+            COUNTER_UPDATE(local_state._total_partition_spills, 1);
+        }
+        local_state._max_partition_level_seen = 0;
+        COUNTER_SET(local_state._max_partition_level,
+                    int64_t(local_state._max_partition_level_seen));
+        local_state._spill_queue_initialized = true;
+        VLOG_DEBUG << fmt::format(
+                "Query:{}, hash join probe:{}, task:{}, initialized spill queue with {} partitions",
+                print_id(state->query_id()), node_id(), state->task_id(),
+                local_state._spill_partition_queue.size());
     }
 
-    if (local_state._need_to_setup_internal_operators) {
-        bool has_data = false;
-        RETURN_IF_ERROR(local_state.recover_build_blocks_from_disk(
-                state, local_state._partition_cursor, has_data));
-        if (has_data) {
+    return _pull_from_spill_queue(local_state, state, output_block, eos);
+}
+
+Status PartitionedHashJoinProbeOperatorX::_pull_from_spill_queue(
+        PartitionedHashJoinProbeLocalState& local_state, RuntimeState* state, Block* output_block,
+        bool* eos) const {
+    *eos = false;
+
+    if (local_state._need_to_setup_queue_partition) {
+        // No more partitions to process and no active partition — EOS.
+        if (local_state._spill_partition_queue.empty() &&
+            (!local_state._current_partition.is_valid() ||
+             local_state._current_partition.probe_finished)) {
+            *eos = true;
             return Status::OK();
         }
 
-        *eos = false;
-        RETURN_IF_ERROR(local_state.finish_spilling(partition_index));
-        RETURN_IF_ERROR(_setup_internal_operators(local_state, state));
-        local_state._need_to_setup_internal_operators = false;
-        auto& mutable_block = local_state._partitioned_blocks[partition_index];
-        if (mutable_block && !mutable_block->empty()) {
-            probe_blocks.emplace_back(mutable_block->to_block());
+        // Pop next partition to process.
+        // Invariant: we only pop when there is no active current partition and
+        // no pending recovered build data waiting to be consumed.
+        if (!local_state._current_partition.is_valid() ||
+            local_state._current_partition.probe_finished) {
+            local_state._current_partition = std::move(local_state._spill_partition_queue.front());
+            local_state._spill_partition_queue.pop_front();
+            local_state._recovered_build_block.reset();
+            local_state._queue_probe_blocks.clear();
+            VLOG_DEBUG << fmt::format(
+                    "Query:{}, hash join probe:{}, task:{},"
+                    " processing queue partition at level:{}, queue remaining:{}",
+                    print_id(state->query_id()), node_id(), state->task_id(),
+                    local_state._current_partition.level,
+                    local_state._spill_partition_queue.size());
         }
+
+        // Continue recovering build data while there is unread build file.
+        if (local_state._current_partition.build_file) {
+            // Partially read build data — yield so it can be consumed
+            // before continuing recovery in the next scheduling slice.
+            return local_state.recover_build_blocks_from_partition(state,
+                                                                   local_state._current_partition);
+        }
+        RETURN_IF_ERROR(_setup_internal_operators_from_partition(local_state, state));
+        local_state._current_partition.build_finished = true;
+        local_state._need_to_setup_queue_partition = false;
+        return Status::OK();
     }
+
+    // Probe phase: feed probe blocks from the current partition's probe stream
+    // into the inner probe operator.
     bool in_mem_eos = false;
-    auto* runtime_state = local_state._shared_state->inner_runtime_state.get();
+    auto* runtime_state = local_state._shared_state->_inner_runtime_state.get();
+    auto& probe_blocks = local_state._queue_probe_blocks;
+
     while (_inner_probe_operator->need_more_input_data(runtime_state)) {
         if (probe_blocks.empty()) {
-            *eos = false;
-            bool has_data = false;
-            RETURN_IF_ERROR(
-                    local_state.recover_probe_blocks_from_disk(state, partition_index, has_data));
-            if (!has_data) {
+            // Try to recover more probe blocks. If the probe stream is
+            // finished (probe_file == nullptr) and no blocks are buffered,
+            // we send EOS to the inner probe operator.
+            if (!local_state._current_partition.probe_file) {
                 Block block;
                 RETURN_IF_ERROR(_inner_probe_operator->push(runtime_state, &block, true));
                 VLOG_DEBUG << fmt::format(
                         "Query:{}, hash join probe:{}, task:{},"
-                        " partition:{}, has no data to recovery",
-                        print_id(state->query_id()), node_id(), state->task_id(), partition_index);
+                        " queue partition (level:{}) probe eos",
+                        print_id(state->query_id()), node_id(), state->task_id(),
+                        local_state._current_partition.level);
                 break;
-            } else {
-                return Status::OK();
             }
+
+            // Probe data recovered — yield to let the pipeline scheduler
+            // re-schedule us so we can push the recovered blocks.
+            return local_state.recover_probe_blocks_from_partition(state,
+                                                                   local_state._current_partition);
         }
 
         auto block = std::move(probe_blocks.back());
@@ -718,23 +809,24 @@ Status PartitionedHashJoinProbeOperatorX::pull(doris::RuntimeState* state, Block
             RETURN_IF_ERROR(_inner_probe_operator->push(runtime_state, &block, false));
         }
     }
-
-    RETURN_IF_ERROR(_inner_probe_operator->pull(
-            local_state._shared_state->inner_runtime_state.get(), output_block, &in_mem_eos));
-
-    *eos = false;
+    RETURN_IF_ERROR(_inner_probe_operator->pull(runtime_state, output_block, &in_mem_eos));
     if (in_mem_eos) {
         VLOG_DEBUG << fmt::format(
                 "Query:{}, hash join probe:{}, task:{},"
-                " partition:{}, probe done",
+                " queue partition (level:{}) probe done",
                 print_id(state->query_id()), node_id(), state->task_id(),
-                local_state._partition_cursor);
-        local_state._partition_cursor++;
+                local_state._current_partition.level);
         local_state.update_profile_from_inner();
-        if (local_state._partition_cursor == _partition_count) {
+        local_state._current_partition.probe_finished = true;
+
+        // Reset for next queue entry — default-constructed partition has
+        // is_valid() == false, signaling "no partition in progress".
+        local_state._current_partition = JoinSpillPartitionInfo {};
+        local_state._need_to_setup_queue_partition = true;
+        local_state._queue_probe_blocks.clear();
+
+        if (local_state._spill_partition_queue.empty()) {
             *eos = true;
-        } else {
-            local_state._need_to_setup_internal_operators = true;
         }
     }
 
@@ -743,68 +835,86 @@ Status PartitionedHashJoinProbeOperatorX::pull(doris::RuntimeState* state, Block
 
 bool PartitionedHashJoinProbeOperatorX::need_more_input_data(RuntimeState* state) const {
     auto& local_state = get_local_state(state);
-    if (local_state._shared_state->is_spilled) {
+    if (local_state._shared_state->_is_spilled) {
         return !local_state._child_eos;
-    } else if (local_state._shared_state->inner_runtime_state) {
+    } else if (local_state._shared_state->_inner_runtime_state) {
         return _inner_probe_operator->need_more_input_data(
-                local_state._shared_state->inner_runtime_state.get());
+                local_state._shared_state->_inner_runtime_state.get());
     } else {
         return true;
     }
 }
 
+// Report only this operator's own revocable memory. The pipeline task
+// iterates all operators to sum revocable sizes and revoke each individually.
+// Sum up memory used by in-memory probe blocks and any partially-recovered build block for the current partition.
+// This is the memory that can be freed if we choose to revoke and repartition the current
 size_t PartitionedHashJoinProbeOperatorX::revocable_mem_size(RuntimeState* state) const {
     auto& local_state = get_local_state(state);
-    if (local_state._child_eos) {
+    if (!local_state._shared_state->_is_spilled) {
         return 0;
     }
 
-    auto revocable_size = _revocable_mem_size(state, true);
-    if (_child) {
-        revocable_size += _child->revocable_mem_size(state);
-    }
-    return revocable_size;
-}
-
-size_t PartitionedHashJoinProbeOperatorX::_revocable_mem_size(RuntimeState* state,
-                                                              bool force) const {
-    const auto spill_size_threshold =
-            force ? SpillStream::MIN_SPILL_WRITE_BATCH_MEM : SpillStream::MAX_SPILL_WRITE_BATCH_MEM;
-    auto& local_state = get_local_state(state);
     size_t mem_size = 0;
-    auto& probe_blocks = local_state._probe_blocks;
-    for (uint32_t i = 0; i < _partition_count; ++i) {
-        for (auto& block : probe_blocks[i]) {
-            mem_size += block.allocated_bytes();
-        }
-
-        auto& partitioned_block = local_state._partitioned_blocks[i];
-        if (partitioned_block) {
-            auto block_bytes = partitioned_block->allocated_bytes();
-            if (block_bytes >= spill_size_threshold) {
-                mem_size += block_bytes;
+    if (!local_state._child_eos) {
+        for (uint32_t i = 0; i < _partition_count; ++i) {
+            auto& partitioned_block = local_state._partitioned_blocks[i];
+            if (!partitioned_block) {
+                continue;
+            }
+            const auto bytes = partitioned_block->allocated_bytes();
+            if (bytes >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
+                mem_size += bytes;
             }
         }
+        return mem_size > state->spill_min_revocable_mem() ? mem_size : 0;
+    }
+    if (!local_state._current_partition.is_valid() ||
+        local_state._current_partition.build_finished) {
+        // No active partition — no revocable memory.
+        // Or if current partition has finished build hash table.
+        return 0;
+    }
+
+    // Include build-side memory that has been recovered but not yet consumed by the hash table.
+    // This data is revocable because we can repartition instead of building the hash table.
+    if (local_state._recovered_build_block) {
+        mem_size += local_state._recovered_build_block->allocated_bytes();
     }
-    return mem_size;
+
+    return mem_size > state->spill_min_revocable_mem() ? mem_size : 0;
 }
 
 size_t PartitionedHashJoinProbeOperatorX::get_reserve_mem_size(RuntimeState* state) {
     auto& local_state = get_local_state(state);
-    const auto is_spilled = local_state._shared_state->is_spilled;
-    if (!is_spilled || local_state._child_eos) {
+    const bool is_spilled = local_state._shared_state->_is_spilled;
+
+    // Non-spill path: delegate to the inner probe operator / base class.
+    if (!is_spilled) {
         return Base::get_reserve_mem_size(state);
     }
 
-    size_t size_to_reserve = SpillStream::MAX_SPILL_WRITE_BATCH_MEM;
+    // Spill path, probe data still flowing in (child not yet EOS):
+    // We only need room for incoming probe blocks being partitioned. Reserve
+    // one batch worth of spill-write memory; no hash table will be built yet.
+    if (!local_state._child_eos) {
+        return state->minimum_operator_memory_required_bytes();
+    }
+
+    // Spill path, child EOS — we are in the recovery / build / probe phase.
+    // Baseline reservation is one block of spill I/O.
+    size_t size_to_reserve = state->minimum_operator_memory_required_bytes();
 
-    if (local_state._need_to_setup_internal_operators) {
-        const size_t rows =
-                (local_state._recovered_build_block ? local_state._recovered_build_block->rows()
-                                                    : 0) +
-                state->batch_size();
-        size_t bucket_size = hash_join_table_calc_bucket_size(rows);
+    const bool about_to_build = local_state._current_partition.is_valid() &&
+                                !local_state._current_partition.build_finished;
 
+    if (about_to_build && local_state._recovered_build_block) {
+        // Estimate rows that will land in the hash table so we can reserve
+        // enough for JoinHashTable::first[] + JoinHashTable::next[].
+        size_t rows = std::max(static_cast<size_t>(state->batch_size()),
+                               static_cast<size_t>(local_state._recovered_build_block->rows()));
+
+        const size_t bucket_size = hash_join_table_calc_bucket_size(rows);
         size_to_reserve += bucket_size * sizeof(uint32_t); // JoinHashTable::first
         size_to_reserve += rows * sizeof(uint32_t);        // JoinHashTable::next
 
@@ -812,51 +922,87 @@ size_t PartitionedHashJoinProbeOperatorX::get_reserve_mem_size(RuntimeState* sta
             _join_op == TJoinOp::RIGHT_ANTI_JOIN || _join_op == TJoinOp::RIGHT_SEMI_JOIN) {
             size_to_reserve += rows * sizeof(uint8_t); // JoinHashTable::visited
         }
+
+        // It is hard to precisely estimate the memory needed for serialized
+        // keys when building the hash table, so use the current build block
+        // size as an estimate. This may be imprecise, but it should not
+        // underestimate the requirement. Hash table construction also merges
+        // blocks, so this approximation is reasonable here.
+        size_to_reserve += local_state._recovered_build_block->allocated_bytes();
     }
+    // Otherwise (not about to build): we only need the spill I/O baseline
+    // already included above — no hash table allocation is imminent.
 
     COUNTER_SET(local_state._memory_usage_reserved, int64_t(size_to_reserve));
     return size_to_reserve;
 }
 
-Status PartitionedHashJoinProbeOperatorX::_revoke_memory(RuntimeState* state) {
-    auto& local_state = get_local_state(state);
-    VLOG_DEBUG << fmt::format("Query:{}, hash join probe:{}, task:{}, revoke_memory",
-                              print_id(state->query_id()), node_id(), state->task_id());
+// Revoke in-memory build data by repartitioning and spilling to disk.
+//
+// Called when `revoke_memory` is invoked after child EOS. At that point all
+// build data is represented as JoinSpillPartitionInfo entries in _spill_partition_queue
+// (after queue initialization). The current partition being processed may have
+// partially-recovered build data in _recovered_build_block. We repartition that
+// data into FANOUT sub-partitions and push them back onto _spill_partition_queue
+// so the hash table build can proceed later under a smaller memory footprint.
+//
+// Build data lives in either:
+//   (a) _current_partition.build_file    (SpillFile, may have been partially read)
+//   (b) _recovered_build_block           (partially-recovered MutableBlock)
+//
+// During repartition we route (b) directly into sub-streams first, then
+// continue reading (a), avoiding an extra round of spill write/read for (b).
+Status PartitionedHashJoinProbeLocalState::revoke_build_data(RuntimeState* state) {
+    auto& p = _parent->cast<PartitionedHashJoinProbeOperatorX>();
+    DCHECK(_child_eos) << "revoke_build_data should only be called after child EOS";
+    DCHECK(_spill_queue_initialized) << "queue must be initialized before revoke_build_data";
+
+    VLOG_DEBUG << fmt::format(
+            "Query:{}, hash join probe:{}, task:{}, revoke_build_data: "
+            "repartitioning queue partition at level {} (build in SpillFile)",
+            print_id(state->query_id()), p.node_id(), state->task_id(), _current_partition.level);
+
+    RETURN_IF_ERROR(repartition_current_partition(state, _current_partition));
+
+    _current_partition = JoinSpillPartitionInfo {};
+    _need_to_setup_queue_partition = true;
+    _queue_probe_blocks.clear();
 
-    RETURN_IF_ERROR(local_state.spill_probe_blocks(state));
     return Status::OK();
 }
 
-bool PartitionedHashJoinProbeOperatorX::_should_revoke_memory(RuntimeState* state) const {
+// Public revoke_memory: called by the pipeline task scheduler when memory
+// pressure requires this operator's in-memory data to be spilled.
+//
+// Before child EOS: probe blocks are still being accumulated → spill them.
+// After child EOS: we are in the recovery/build phase. All build data is
+//   represented in _spill_partition_queue (after queue initialization). The
+//   current partition's in-memory recovered data (_recovered_build_block) is
+//   repartitioned and pushed back to the queue so the hash table build can
+//   proceed later with a smaller footprint.
+Status PartitionedHashJoinProbeOperatorX::revoke_memory(RuntimeState* state) {
     auto& local_state = get_local_state(state);
-    if (local_state._shared_state->is_spilled) {
-        const auto revocable_size = _revocable_mem_size(state);
+    VLOG_DEBUG << fmt::format("Query:{}, hash join probe:{}, task:{}, revoke_memory, child_eos:{}",
+                              print_id(state->query_id()), node_id(), state->task_id(),
+                              local_state._child_eos);
 
-        if (local_state.low_memory_mode()) {
-            return revocable_size >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM;
-        } else {
-            return revocable_size >= SpillStream::MAX_SPILL_WRITE_BATCH_MEM;
-        }
+    if (!local_state._child_eos) {
+        // Probe-data accumulation phase: spill in-memory probe blocks to disk.
+        return local_state.spill_probe_blocks(state, false);
+    }
+    if (!local_state._current_partition.is_valid() ||
+        local_state._current_partition.build_finished) {
+        return Status::OK();
     }
-    return false;
+    // Recovery/build phase: repartition the current partition's in-memory build
+    // data so the hash table build can be deferred to a smaller sub-partition.
+    return local_state.revoke_build_data(state);
 }
 
 Status PartitionedHashJoinProbeOperatorX::get_block(RuntimeState* state, Block* block, bool* eos) {
     *eos = false;
     auto& local_state = get_local_state(state);
-    local_state.copy_shared_spill_profile();
-    const auto is_spilled = local_state._shared_state->is_spilled;
-#ifndef NDEBUG
-    Defer eos_check_defer([&] {
-        if (*eos) {
-            LOG(INFO) << fmt::format(
-                    "Query:{}, hash join probe:{}, task:{}, child eos:{}, need spill:{}",
-                    print_id(state->query_id()), node_id(), state->task_id(),
-                    local_state._child_eos, is_spilled);
-        }
-    });
-#endif
-
+    const bool is_spilled = local_state._shared_state->_is_spilled;
     Defer defer([&]() {
         COUNTER_SET(local_state._memory_usage_reserved,
                     int64_t(local_state.estimate_memory_usage()));
@@ -877,13 +1023,10 @@ Status PartitionedHashJoinProbeOperatorX::get_block(RuntimeState* state, Block*
         Defer clear_defer([&] { local_state._child_block->clear_column_data(); });
         if (is_spilled) {
             RETURN_IF_ERROR(push(state, local_state._child_block.get(), local_state._child_eos));
-            if (_should_revoke_memory(state)) {
-                return _revoke_memory(state);
-            }
         } else {
-            DCHECK(local_state._shared_state->inner_runtime_state);
+            DCHECK(local_state._shared_state->_inner_runtime_state);
             RETURN_IF_ERROR(_inner_probe_operator->push(
-                    local_state._shared_state->inner_runtime_state.get(),
+                    local_state._shared_state->_inner_runtime_state.get(),
                     local_state._child_block.get(), local_state._child_eos));
         }
     }
@@ -894,12 +1037,14 @@ Status PartitionedHashJoinProbeOperatorX::get_block(RuntimeState* state, Block*
             RETURN_IF_ERROR(pull(state, block, eos));
         } else {
             RETURN_IF_ERROR(_inner_probe_operator->pull(
-                    local_state._shared_state->inner_runtime_state.get(), block, eos));
+                    local_state._shared_state->_inner_runtime_state.get(), block, eos));
             local_state.update_profile_from_inner();
         }
 
-        local_state.add_num_rows_returned(block->rows());
-        COUNTER_UPDATE(local_state._blocks_returned_counter, 1);
+        if (!block->empty()) {
+            local_state.add_num_rows_returned(block->rows());
+            COUNTER_UPDATE(local_state._blocks_returned_counter, 1);
+        }
     }
     return Status::OK();
 }
diff --git a/be/src/exec/operator/partitioned_hash_join_probe_operator.h b/be/src/exec/operator/partitioned_hash_join_probe_operator.h
index 10530d5c8ad..2a53458e129 100644
--- a/be/src/exec/operator/partitioned_hash_join_probe_operator.h
+++ b/be/src/exec/operator/partitioned_hash_join_probe_operator.h
@@ -28,6 +28,10 @@
 #include "exec/operator/operator.h"
 #include "exec/operator/spill_utils.h"
 #include "exec/pipeline/dependency.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
+#include "exec/spill/spill_repartitioner.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -35,6 +39,51 @@ class RuntimeState;
 
 class PartitionedHashJoinProbeOperatorX;
 
+/// Represents a spilled partition pair (build + probe file) that needs to be processed
+/// during recovery. For multi-level spill, when a partition is too large to fit in
+/// memory, it gets repartitioned into FANOUT sub-partitions, each represented by a
+/// new JoinSpillPartitionInfo at level + 1.
+///
+/// Lifecycle of partition progress:
+///   build_file == nullptr:
+///     - all build-side spill data has been read from disk for this partition
+///   probe_file == nullptr:
+///     - all probe-side spill data has been read from disk for this partition
+///   build_finished = true:
+///     - build side has completed hash table construction
+///   probe_finished = true:
+///     - probe side has completed probing all rows for this partition
+///
+/// A default-constructed instance has is_valid() == false, representing "no partition".
+/// New sub-partitions created by repartitioning start with both flags = false and
+/// initialized = true.
+struct JoinSpillPartitionInfo {
+    // build_file == nullptr means all build data has been read from disk.
+    SpillFileSPtr build_file;
+    // probe_file == nullptr means all probe data has been read from disk.
+    SpillFileSPtr probe_file;
+    int level = 0; // 0 = original level-0 partition, 1+ = repartitioned sub-partition
+
+    // Read all build data from disk and finished building the hash table.
+    bool build_finished = false;
+    // Read all probe data from disk and probed all rows against the hash table.
+    bool probe_finished = false;
+    // Whether this struct currently represents an active queue partition.
+    bool initialized = false;
+
+    JoinSpillPartitionInfo() = default;
+    JoinSpillPartitionInfo(SpillFileSPtr build, SpillFileSPtr probe, int lvl)
+            : build_file(std::move(build)),
+              probe_file(std::move(probe)),
+              level(lvl),
+              initialized(true) {}
+
+    /// Returns true if this struct currently represents an active partition entry
+    /// from the spill queue. A default-constructed partition is "invalid" and
+    /// serves as a sentinel meaning "no partition is being processed".
+    bool is_valid() const { return initialized; }
+};
+
 class PartitionedHashJoinProbeLocalState MOCK_REMOVE(final)
         : public PipelineXSpillLocalState<PartitionedHashJoinSharedState> {
 public:
@@ -47,14 +96,28 @@ public:
     Status open(RuntimeState* state) override;
     Status close(RuntimeState* state) override;
 
-    Status spill_probe_blocks(RuntimeState* state);
-
-    Status recover_build_blocks_from_disk(RuntimeState* state, uint32_t partition_index,
-                                          bool& has_data);
-    Status recover_probe_blocks_from_disk(RuntimeState* state, uint32_t partition_index,
-                                          bool& has_data);
-
-    Status finish_spilling(uint32_t partition_index);
+    Status spill_probe_blocks(RuntimeState* state, bool flush_all);
+
+    /// Revoke in-memory build data by repartitioning it and pushing the result back onto
+    /// _spill_partition_queue. Used by revoke_memory when child_eos is true (recovery/build
+    /// phase) and we have significant in-memory build data that cannot be kept in memory.
+    ///
+    /// After queue initialization, all partitions are represented as JoinSpillPartitionInfo entries
+    /// in _spill_partition_queue. Repartition reads from _current_partition's streams (or the
+    /// already-recovered _recovered_build_block) and pushes FANOUT sub-partitions back onto the
+    /// queue.
+    Status revoke_build_data(RuntimeState* state);
+
+    /// Recover build blocks from a JoinSpillPartitionInfo's build stream (for multi-level recovery).
+    Status recover_build_blocks_from_partition(RuntimeState* state,
+                                               JoinSpillPartitionInfo& partition_info);
+    /// Recover probe blocks from a JoinSpillPartitionInfo's probe stream (for multi-level recovery).
+    Status recover_probe_blocks_from_partition(RuntimeState* state,
+                                               JoinSpillPartitionInfo& partition_info);
+
+    /// Repartition the current partition's build and probe streams into FANOUT sub-partitions
+    /// and push them into _spill_partition_queue for subsequent processing.
+    Status repartition_current_partition(RuntimeState* state, JoinSpillPartitionInfo& partition);
 
     template <bool spilled>
     void update_build_custom_profile(RuntimeProfile* child_profile);
@@ -76,47 +139,77 @@ public:
 
     bool is_blockable() const override;
 
+    Status acquire_spill_writer(RuntimeState* state, int partition_index,
+                                SpillFileWriterSPtr& writer);
+
     friend class PartitionedHashJoinProbeOperatorX;
 
 private:
     template <typename LocalStateType>
     friend class StatefulOperatorX;
 
-    // Spill probe blocks to disk
-    Status _execute_spill_probe_blocks(RuntimeState* state, const UniqueId& query_id);
-
     std::shared_ptr<BasicSharedState> _in_mem_shared_state_sptr;
-    uint32_t _partition_cursor {0};
 
     std::unique_ptr<Block> _child_block;
     bool _child_eos {false};
 
     std::vector<std::unique_ptr<MutableBlock>> _partitioned_blocks;
     std::unique_ptr<MutableBlock> _recovered_build_block;
-    std::map<uint32_t, std::vector<Block>> _probe_blocks;
 
-    std::vector<SpillStreamSPtr> _probe_spilling_streams;
+    std::vector<SpillFileSPtr> _probe_spilling_groups;
+    std::vector<SpillFileWriterSPtr> _probe_writers;
 
     std::unique_ptr<PartitionerBase> _partitioner;
     std::unique_ptr<RuntimeProfile> _internal_runtime_profile;
 
-    bool _need_to_setup_internal_operators {true};
+    // Persistent readers for recovery across scheduling slices
+    SpillFileReaderSPtr _current_build_reader;
+    SpillFileReaderSPtr _current_probe_reader;
+
+    // ---- Spill partition queue state ----
+    // Whether _spill_partition_queue has been initialized from spilled build groups +
+    // _probe_spilling_groups. Set to true the first time pull() enters the spill
+    // path after child EOS. Once true, all partitions are accessed via the queue.
+    bool _spill_queue_initialized {false};
+    // Work queue of spilled partition pairs to process. Populated during
+    // initialization from the level-0 spilled streams and also when a partition is
+    // too large to build a hash table (repartitioned into FANOUT new entries).
+    std::deque<JoinSpillPartitionInfo> _spill_partition_queue;
+    // The partition currently being processed from _spill_partition_queue.
+    JoinSpillPartitionInfo _current_partition;
+    // Repartitioner instance (reused across repartition calls)
+    SpillRepartitioner _repartitioner;
+    // A partitioner with partition_count = FANOUT for use during repartitioning.
+    // The main _partitioner uses the original _partition_count (e.g., 32), which
+    // is wrong for repartitioning that needs FANOUT (8) sub-partitions.
+    std::unique_ptr<PartitionerBase> _fanout_partitioner;
+    std::unique_ptr<PartitionerBase> _build_fanout_partitioner;
+    // Whether internal operators need to be set up for the current queue partition.
+    bool _need_to_setup_queue_partition {true};
+    // Probe blocks recovered from the current queue partition's probe stream.
+    std::vector<Block> _queue_probe_blocks;
 
-    RuntimeProfile::Counter* _partition_timer = nullptr;
     RuntimeProfile::Counter* _partition_shuffle_timer = nullptr;
     RuntimeProfile::Counter* _spill_build_rows = nullptr;
     RuntimeProfile::Counter* _spill_build_blocks = nullptr;
     RuntimeProfile::Counter* _spill_build_timer = nullptr;
     RuntimeProfile::Counter* _recovery_build_rows = nullptr;
+    RuntimeProfile::Counter* _recovery_level0_build_rows = nullptr;
     RuntimeProfile::Counter* _recovery_build_blocks = nullptr;
     RuntimeProfile::Counter* _recovery_build_timer = nullptr;
     RuntimeProfile::Counter* _spill_probe_rows = nullptr;
     RuntimeProfile::Counter* _spill_probe_blocks = nullptr;
     RuntimeProfile::Counter* _spill_probe_timer = nullptr;
+    RuntimeProfile::Counter* _build_rows = nullptr;
     RuntimeProfile::Counter* _recovery_probe_rows = nullptr;
     RuntimeProfile::Counter* _recovery_probe_blocks = nullptr;
     RuntimeProfile::Counter* _recovery_probe_timer = nullptr;
 
+    // Counters to track spill partition metrics
+    RuntimeProfile::Counter* _max_partition_level = nullptr;
+    RuntimeProfile::Counter* _total_partition_spills = nullptr;
+    int _max_partition_level_seen = 0;
+
     RuntimeProfile::Counter* _probe_blocks_bytes = nullptr;
     RuntimeProfile::Counter* _memory_usage_reserved = nullptr;
     RuntimeProfile::Counter* _get_child_next_timer = nullptr;
@@ -126,7 +219,7 @@ class PartitionedHashJoinProbeOperatorX final
         : public JoinProbeOperatorX<PartitionedHashJoinProbeLocalState> {
 public:
     PartitionedHashJoinProbeOperatorX(ObjectPool* pool, const TPlanNode& tnode, int operator_id,
-                                      const DescriptorTbl& descs, uint32_t partition_count);
+                                      const DescriptorTbl& descs);
     Status init(const TPlanNode& tnode, RuntimeState* state) override;
     Status prepare(RuntimeState* state) override;
 
@@ -150,6 +243,11 @@ public:
 
     size_t revocable_mem_size(RuntimeState* state) const override;
 
+    // Called by the pipeline task scheduler when memory pressure requires spilling
+    // probe-side blocks. Probe-side memory is NOT managed by the sink, so the
+    // probe operator must expose this interface so the scheduler can reach it.
+    Status revoke_memory(RuntimeState* state) override;
+
     size_t get_reserve_mem_size(RuntimeState* state) override;
 
     void set_inner_operators(const std::shared_ptr<HashJoinBuildSinkOperatorX>& sink_operator,
@@ -174,16 +272,19 @@ public:
     }
 
 private:
-    Status _revoke_memory(RuntimeState* state);
-
-    size_t _revocable_mem_size(RuntimeState* state, bool force = false) const;
-
     friend class PartitionedHashJoinProbeLocalState;
 
-    [[nodiscard]] Status _setup_internal_operators(PartitionedHashJoinProbeLocalState& local_state,
-                                                   RuntimeState* state) const;
+    /// Setup internal operators using build data from a JoinSpillPartitionInfo
+    /// (for multi-level recovery, where build data comes from repartitioned streams).
+    [[nodiscard]] Status _setup_internal_operators_from_partition(
+            PartitionedHashJoinProbeLocalState& local_state, RuntimeState* state) const;
 
-    bool _should_revoke_memory(RuntimeState* state) const;
+    /// Process entries from the _spill_partition_queue.
+    /// All spilled partitions (both original level-0 and repartitioned sub-partitions)
+    /// are processed via this single path.
+    [[nodiscard]] Status _pull_from_spill_queue(PartitionedHashJoinProbeLocalState& local_state,
+                                                RuntimeState* state, Block* output_block,
+                                                bool* eos) const;
 
     const TJoinDistributionType::type _join_distribution;
 
@@ -192,14 +293,17 @@ private:
 
     // probe expr
     std::vector<TExpr> _probe_exprs;
+    std::vector<TExpr> _build_exprs;
 
     const std::vector<TExpr> _distribution_partition_exprs;
 
     const TPlanNode _tnode;
     const DescriptorTbl _descriptor_tbl;
 
-    const uint32_t _partition_count;
+    uint32_t _partition_count;
     std::unique_ptr<PartitionerBase> _partitioner;
+    // max repartition depth configured per-operator (default to static MAX_DEPTH)
+    int _repartition_max_depth = SpillRepartitioner::MAX_DEPTH;
 };
 
 #include "common/compile_check_end.h"
diff --git a/be/src/exec/operator/partitioned_hash_join_sink_operator.cpp b/be/src/exec/operator/partitioned_hash_join_sink_operator.cpp
index a702421ae08..c75db33799b 100644
--- a/be/src/exec/operator/partitioned_hash_join_sink_operator.cpp
+++ b/be/src/exec/operator/partitioned_hash_join_sink_operator.cpp
@@ -27,8 +27,9 @@
 #include "exec/operator/operator.h"
 #include "exec/operator/spill_utils.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_writer.h"
 #include "runtime/fragment_mgr.h"
 #include "runtime/runtime_profile.h"
 #include "util/pretty_printer.h"
@@ -42,16 +43,15 @@ Status PartitionedHashJoinSinkLocalState::init(doris::RuntimeState* state,
     SCOPED_TIMER(exec_time_counter());
     SCOPED_TIMER(_init_timer);
     auto& p = _parent->cast<PartitionedHashJoinSinkOperatorX>();
-    _shared_state->partitioned_build_blocks.resize(p._partition_count);
-    _shared_state->spilled_streams.resize(p._partition_count);
+    _shared_state->_partitioned_build_blocks.resize(p._partition_count);
+    _shared_state->_spilled_build_groups.resize(p._partition_count);
+    _build_writers.resize(p._partition_count);
 
     _rows_in_partitions.assign(p._partition_count, 0);
 
     _internal_runtime_profile = std::make_unique<RuntimeProfile>("internal_profile");
 
-    _partition_timer = ADD_TIMER_WITH_LEVEL(custom_profile(), "SpillPartitionTime", 1);
-    _partition_shuffle_timer =
-            ADD_TIMER_WITH_LEVEL(custom_profile(), "SpillPartitionShuffleTime", 1);
+    _partition_shuffle_timer = ADD_TIMER_WITH_LEVEL(custom_profile(), "SpillRePartitionTime", 1);
     _spill_build_timer = ADD_TIMER_WITH_LEVEL(custom_profile(), "SpillBuildTime", 1);
     _in_mem_rows_counter =
             ADD_COUNTER_WITH_LEVEL(custom_profile(), "SpillInMemRow", TUnit::UNIT, 1);
@@ -64,17 +64,8 @@ Status PartitionedHashJoinSinkLocalState::init(doris::RuntimeState* state,
 Status PartitionedHashJoinSinkLocalState::open(RuntimeState* state) {
     SCOPED_TIMER(exec_time_counter());
     SCOPED_TIMER(_open_timer);
-    _shared_state->setup_shared_profile(custom_profile());
     RETURN_IF_ERROR(PipelineXSpillSinkLocalState::open(state));
     auto& p = _parent->cast<PartitionedHashJoinSinkOperatorX>();
-    for (uint32_t i = 0; i != p._partition_count; ++i) {
-        auto& spilling_stream = _shared_state->spilled_streams[i];
-        RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-                state, spilling_stream, print_id(state->query_id()),
-                fmt::format("hash_build_sink_{}", i), _parent->node_id(),
-                std::numeric_limits<int32_t>::max(), std::numeric_limits<size_t>::max(),
-                operator_profile()));
-    }
     return p._partitioner->clone(state, _partitioner);
 }
 
@@ -84,23 +75,32 @@ Status PartitionedHashJoinSinkLocalState::close(RuntimeState* state, Status exec
     if (PipelineXSpillSinkLocalState::_closed) {
         return Status::OK();
     }
-    DCHECK(_shared_state->inner_runtime_state != nullptr);
+    DCHECK(_shared_state->_inner_runtime_state != nullptr);
     VLOG_DEBUG << "Query:" << print_id(state->query_id())
                << ", hash join sink:" << _parent->node_id() << ", task:" << state->task_id()
                << ", close";
     auto& p = _parent->cast<PartitionedHashJoinSinkOperatorX>();
-    if (!_shared_state->is_spilled && _shared_state->inner_runtime_state) {
-        RETURN_IF_ERROR(p._inner_sink_operator->close(_shared_state->inner_runtime_state.get(),
+    if (!_shared_state->_is_spilled && _shared_state->_inner_runtime_state) {
+        RETURN_IF_ERROR(p._inner_sink_operator->close(_shared_state->_inner_runtime_state.get(),
                                                       exec_status));
     }
+
+    for (auto& writer : _build_writers) {
+        if (writer) {
+            RETURN_IF_ERROR(writer->close());
+            writer.reset();
+        }
+    }
+    _build_writers.clear();
+
     return PipelineXSpillSinkLocalState::close(state, exec_status);
 }
 
 size_t PartitionedHashJoinSinkLocalState::revocable_mem_size(RuntimeState* state) const {
     /// If no need to spill, all rows were sunk into the `_inner_sink_operator` without partitioned.
-    if (!_shared_state->is_spilled) {
-        if (_shared_state->inner_shared_state) {
-            auto* inner_sink_state_ = _shared_state->inner_runtime_state->get_sink_local_state();
+    if (!_shared_state->_is_spilled) {
+        if (_shared_state->_inner_shared_state) {
+            auto* inner_sink_state_ = _shared_state->_inner_runtime_state->get_sink_local_state();
             if (inner_sink_state_) {
                 auto* inner_sink_state =
                         assert_cast<HashJoinBuildSinkLocalState*>(inner_sink_state_);
@@ -111,22 +111,22 @@ size_t PartitionedHashJoinSinkLocalState::revocable_mem_size(RuntimeState* state
     }
 
     size_t mem_size = 0;
-    auto& partitioned_blocks = _shared_state->partitioned_build_blocks;
+    auto& partitioned_blocks = _shared_state->_partitioned_build_blocks;
     for (auto& block : partitioned_blocks) {
         if (block) {
             auto block_bytes = block->allocated_bytes();
-            if (block_bytes >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
+            if (block_bytes >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
                 mem_size += block_bytes;
             }
         }
     }
-    return mem_size;
+    return mem_size > state->spill_min_revocable_mem() ? mem_size : 0;
 }
 
 void PartitionedHashJoinSinkLocalState::update_memory_usage() {
-    if (!_shared_state->is_spilled) {
-        if (_shared_state->inner_shared_state) {
-            auto* inner_sink_state_ = _shared_state->inner_runtime_state->get_sink_local_state();
+    if (!_shared_state->_is_spilled) {
+        if (_shared_state->_inner_shared_state) {
+            auto* inner_sink_state_ = _shared_state->_inner_runtime_state->get_sink_local_state();
             if (inner_sink_state_) {
                 auto* inner_sink_state =
                         assert_cast<HashJoinBuildSinkLocalState*>(inner_sink_state_);
@@ -137,7 +137,7 @@ void PartitionedHashJoinSinkLocalState::update_memory_usage() {
     }
 
     int64_t mem_size = 0;
-    auto& partitioned_blocks = _shared_state->partitioned_build_blocks;
+    auto& partitioned_blocks = _shared_state->_partitioned_build_blocks;
     for (auto& block : partitioned_blocks) {
         if (block) {
             mem_size += block->allocated_bytes();
@@ -149,12 +149,13 @@ void PartitionedHashJoinSinkLocalState::update_memory_usage() {
 size_t PartitionedHashJoinSinkLocalState::get_reserve_mem_size(RuntimeState* state, bool eos) {
     size_t size_to_reserve = 0;
     auto& p = _parent->cast<PartitionedHashJoinSinkOperatorX>();
-    if (_shared_state->is_spilled) {
-        size_to_reserve = p._partition_count * SpillStream::MIN_SPILL_WRITE_BATCH_MEM;
+
+    if (_shared_state->_is_spilled) {
+        size_to_reserve = p._partition_count * SpillFile::MIN_SPILL_WRITE_BATCH_MEM;
     } else {
-        if (_shared_state->inner_runtime_state) {
+        if (_shared_state->_inner_runtime_state) {
             size_to_reserve = p._inner_sink_operator->get_reserve_mem_size(
-                    _shared_state->inner_runtime_state.get(), eos);
+                    _shared_state->_inner_runtime_state.get(), eos);
         }
     }
 
@@ -166,99 +167,15 @@ Dependency* PartitionedHashJoinSinkLocalState::finishdependency() {
     return _finish_dependency.get();
 }
 
-Status PartitionedHashJoinSinkLocalState::_execute_spill_unpartitioned_block(RuntimeState* state,
-                                                                             Block&& build_block) {
-    Defer defer1 {[&]() { update_memory_usage(); }};
-    auto& p = _parent->cast<PartitionedHashJoinSinkOperatorX>();
-    auto& partitioned_blocks = _shared_state->partitioned_build_blocks;
-    std::vector<std::vector<uint32_t>> partitions_indexes(p._partition_count);
-
-    const size_t reserved_size = 4096;
-    std::ranges::for_each(partitions_indexes,
-                          [](std::vector<uint32_t>& indices) { indices.reserve(reserved_size); });
-
-    size_t total_rows = build_block.rows();
-    size_t offset = 1;
-    while (offset < total_rows) {
-        auto sub_block = build_block.clone_empty();
-        size_t this_run = std::min(reserved_size, total_rows - offset);
-
-        for (size_t i = 0; i != build_block.columns(); ++i) {
-            sub_block.get_by_position(i).column =
-                    build_block.get_by_position(i).column->cut(offset, this_run);
-        }
-        int64_t sub_blocks_memory_usage = sub_block.allocated_bytes();
-        COUNTER_UPDATE(_memory_used_counter, sub_blocks_memory_usage);
-        Defer defer2 {[&]() { COUNTER_UPDATE(_memory_used_counter, -sub_blocks_memory_usage); }};
-
-        offset += this_run;
-        const auto is_last_block = offset == total_rows;
-
-        {
-            SCOPED_TIMER(_partition_timer);
-            (void)_partitioner->do_partitioning(state, &sub_block);
-        }
-
-        const auto& channel_ids = _partitioner->get_channel_ids();
-        for (size_t i = 0; i != sub_block.rows(); ++i) {
-            partitions_indexes[channel_ids[i]].emplace_back(i);
-        }
-
-        for (uint32_t partition_idx = 0; partition_idx != p._partition_count; ++partition_idx) {
-            auto* begin = partitions_indexes[partition_idx].data();
-            auto* end = begin + partitions_indexes[partition_idx].size();
-            auto& partition_block = partitioned_blocks[partition_idx];
-            SpillStreamSPtr& spilling_stream = _shared_state->spilled_streams[partition_idx];
-            if (UNLIKELY(!partition_block)) {
-                partition_block = MutableBlock::create_unique(build_block.clone_empty());
-            }
-
-            int64_t old_mem = partition_block->allocated_bytes();
-            {
-                SCOPED_TIMER(_partition_shuffle_timer);
-                RETURN_IF_ERROR(partition_block->add_rows(&sub_block, begin, end));
-                partitions_indexes[partition_idx].clear();
-            }
-            int64_t new_mem = partition_block->allocated_bytes();
-
-            if (partition_block->rows() >= reserved_size || is_last_block) {
-                auto block = partition_block->to_block();
-                RETURN_IF_ERROR(spilling_stream->spill_block(state, block, false));
-                partition_block = MutableBlock::create_unique(build_block.clone_empty());
-                COUNTER_UPDATE(_memory_used_counter, -new_mem);
-            } else {
-                COUNTER_UPDATE(_memory_used_counter, new_mem - old_mem);
-            }
-        }
-    }
-
-    Status status;
-    if (_child_eos) {
-        std::ranges::for_each(_shared_state->partitioned_build_blocks, [&](auto& block) {
-            if (block) {
-                COUNTER_UPDATE(_in_mem_rows_counter, block->rows());
-            }
-        });
-        status = _finish_spilling();
-        VLOG_DEBUG << fmt::format(
-                "Query:{}, hash join sink:{}, task:{}, _revoke_unpartitioned_block, "
-                "set_ready_to_read",
-                print_id(state->query_id()), _parent->node_id(), state->task_id());
-        _dependency->set_ready_to_read();
-    }
-
-    return status;
-}
-
-Status PartitionedHashJoinSinkLocalState::_revoke_unpartitioned_block(
-        RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context) {
+Status PartitionedHashJoinSinkLocalState::_revoke_unpartitioned_block(RuntimeState* state) {
+    // SpillFiles and writers will be created lazily in _spill_to_disk
     auto& p = _parent->cast<PartitionedHashJoinSinkOperatorX>();
     HashJoinBuildSinkLocalState* inner_sink_state {nullptr};
-    if (auto* tmp_sink_state = _shared_state->inner_runtime_state->get_sink_local_state()) {
+    if (auto* tmp_sink_state = _shared_state->_inner_runtime_state->get_sink_local_state()) {
         inner_sink_state = assert_cast<HashJoinBuildSinkLocalState*>(tmp_sink_state);
     }
-    DCHECK_EQ(_shared_state->inner_shared_state->hash_table_variant_vector.size(), 1);
-    _shared_state->inner_shared_state->hash_table_variant_vector.front().reset();
+    DCHECK_EQ(_shared_state->_inner_shared_state->hash_table_variant_vector.size(), 1);
+    _shared_state->_inner_shared_state->hash_table_variant_vector.front().reset();
     if (inner_sink_state) {
         COUNTER_UPDATE(_memory_used_counter,
                        -(inner_sink_state->_hash_table_memory_usage->value() +
@@ -274,7 +191,7 @@ Status PartitionedHashJoinSinkLocalState::_revoke_unpartitioned_block(
         // If spilling was triggered, constructing runtime filters is meaningless,
         // therefore, all runtime filters are temporarily disabled.
         RETURN_IF_ERROR(inner_sink_state->_runtime_filter_producer_helper->skip_process(
-                _shared_state->inner_runtime_state.get()));
+                _shared_state->_inner_runtime_state.get()));
         _finish_dependency->set_ready();
     }
 
@@ -283,9 +200,6 @@ Status PartitionedHashJoinSinkLocalState::_revoke_unpartitioned_block(
                 "Query:{}, hash join sink:{}, task:{},"
                 " has no data to revoke",
                 print_id(state->query_id()), _parent->node_id(), state->task_id());
-        if (spill_context) {
-            spill_context->on_task_finished();
-        }
         return Status::OK();
     }
 
@@ -294,24 +208,28 @@ Status PartitionedHashJoinSinkLocalState::_revoke_unpartitioned_block(
         COUNTER_UPDATE(_memory_used_counter, build_block.allocated_bytes() - block_old_mem);
     }
 
-    auto exception_catch_func = [this, state, build_block = std::move(build_block)]() mutable {
-        auto status = [&]() {
-            RETURN_IF_CATCH_EXCEPTION(
-                    return _execute_spill_unpartitioned_block(state, std::move(build_block)));
-        }();
-        return status;
-    };
-
-    SpillSinkRunnable spill_runnable(state, spill_context, operator_profile(),
-                                     exception_catch_func);
-
-    DBUG_EXECUTE_IF(
-            "fault_inject::partitioned_hash_join_sink::revoke_unpartitioned_block_submit_func", {
-                return Status::Error<INTERNAL_ERROR>(
-                        "fault_inject partitioned_hash_join_sink "
-                        "revoke_unpartitioned_block submit_func failed");
-            });
-    return spill_runnable.run();
+    // The inner sink's _build_side_mutable_block has a sentinel row at
+    // index 0 (used for column type evaluation), so real data starts at
+    // row 1.  Split the big block into sub-blocks and reuse the normal
+    // _partition_block + _execute_spill_partitioned_blocks path to avoid
+    // duplicating the partitioning logic.
+    // make the batch size larger, because after partitioning, the
+    // number of rows per partition is much smaller. To avoid too much small blocks.
+    const size_t batch_size = 4096 * _shared_state->_partitioned_build_blocks.size();
+    const size_t total_rows = build_block.rows();
+    for (size_t offset = 1; offset < total_rows;) {
+        const size_t this_run = std::min(batch_size, total_rows - offset);
+        auto sub_block = build_block.clone_empty();
+        for (size_t c = 0; c != build_block.columns(); ++c) {
+            sub_block.get_by_position(c).column =
+                    build_block.get_by_position(c).column->cut(offset, this_run);
+        }
+        offset += this_run;
+        RETURN_IF_ERROR(_partition_block(state, &sub_block, 0, sub_block.rows()));
+        RETURN_IF_ERROR(_execute_spill_partitioned_blocks(state, true /*force_spill*/));
+    }
+    RETURN_IF_ERROR(_force_flush_partitions(state));
+    return Status::OK();
 }
 
 Status PartitionedHashJoinSinkLocalState::terminate(RuntimeState* state) {
@@ -319,42 +237,60 @@ Status PartitionedHashJoinSinkLocalState::terminate(RuntimeState* state) {
         return Status::OK();
     }
     HashJoinBuildSinkLocalState* inner_sink_state {nullptr};
-    if (auto* tmp_sink_state = _shared_state->inner_runtime_state->get_sink_local_state()) {
+    if (auto* tmp_sink_state = _shared_state->_inner_runtime_state->get_sink_local_state()) {
         inner_sink_state = assert_cast<HashJoinBuildSinkLocalState*>(tmp_sink_state);
     }
-    if (_parent->cast<PartitionedHashJoinSinkOperatorX>()._inner_sink_operator) {
-        RETURN_IF_ERROR(inner_sink_state->_runtime_filter_producer_helper->skip_process(state));
+    if (inner_sink_state) {
+        if (_parent->cast<PartitionedHashJoinSinkOperatorX>()._inner_sink_operator) {
+            RETURN_IF_ERROR(inner_sink_state->_runtime_filter_producer_helper->skip_process(state));
+        }
+        inner_sink_state->_terminated = true;
     }
-    inner_sink_state->_terminated = true;
     return PipelineXSpillSinkLocalState<PartitionedHashJoinSharedState>::terminate(state);
 }
 
-Status PartitionedHashJoinSinkLocalState::_finish_spilling_callback(
-        RuntimeState* state, TUniqueId query_id,
-        const std::shared_ptr<SpillContext>& spill_context) {
-    Status status;
-    if (_child_eos) {
-        LOG(INFO) << fmt::format(
-                "Query:{}, hash join sink:{}, task:{}, finish spilling, set_ready_to_read",
-                print_id(query_id), _parent->node_id(), state->task_id());
-        std::ranges::for_each(_shared_state->partitioned_build_blocks, [&](auto& block) {
-            if (block) {
-                COUNTER_UPDATE(_in_mem_rows_counter, block->rows());
+Status PartitionedHashJoinSinkLocalState::_force_flush_partitions(RuntimeState* state) {
+    for (size_t i = 0; i != _shared_state->_partitioned_build_blocks.size(); ++i) {
+        auto& block = _shared_state->_partitioned_build_blocks[i];
+        if (block && block->rows() > 0) {
+            auto spilled_block = block->to_block();
+            block.reset();
+            // Lazy-create SpillFile + Writer if needed
+            auto& spill_file = _shared_state->_spilled_build_groups[i];
+            auto& writer = _build_writers[i];
+            if (!writer) {
+                auto label = fmt::format("hash_build_sink_{}", i);
+                auto relative_path = fmt::format(
+                        "{}/{}-{}-{}-{}", print_id(state->query_id()), label, _parent->node_id(),
+                        state->task_id(), ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+                RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(
+                        relative_path, spill_file));
+                RETURN_IF_ERROR(spill_file->create_writer(state, operator_profile(), writer));
             }
-        });
-        status = _finish_spilling();
-        _dependency->set_ready_to_read();
+            RETURN_IF_ERROR(writer->write_block(state, spilled_block));
+        }
     }
+    return Status::OK();
+}
 
-    if (spill_context) {
-        spill_context->on_task_finished();
+Status PartitionedHashJoinSinkLocalState::_finish_spilling(RuntimeState* state) {
+    if (!_shared_state->_is_spilled) {
+        return Status::OK();
     }
-
-    return status;
+    // Close all writers (Writer::close() finalizes SpillFile metadata)
+    for (auto& writer : _build_writers) {
+        if (writer) {
+            RETURN_IF_ERROR(writer->close());
+        }
+    }
+    return Status::OK();
 }
 
+/// If revoke memory API call this method, we has to flush all memory to avoid dead loop. For example, maybe
+/// revocable memory size calcuateld by memory usage is not enough using limit 100K, but we can't spill all memory to disk
+/// because we use limit 1MB here. So we need to force spill all memory to disk to make sure we can make progress.
 Status PartitionedHashJoinSinkLocalState::_execute_spill_partitioned_blocks(RuntimeState* state,
-                                                                            TUniqueId query_id) {
+                                                                            bool force_spill) {
     DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_sink::revoke_memory_cancel", {
         auto status = Status::InternalError(
                 "fault_inject partitioned_hash_join_sink revoke_memory canceled");
@@ -363,56 +299,34 @@ Status PartitionedHashJoinSinkLocalState::_execute_spill_partitioned_blocks(Runt
     });
     SCOPED_TIMER(_spill_build_timer);
 
-    for (size_t i = 0; i != _shared_state->partitioned_build_blocks.size(); ++i) {
-        SpillStreamSPtr& spilling_stream = _shared_state->spilled_streams[i];
-        DCHECK(spilling_stream != nullptr);
-        auto& mutable_block = _shared_state->partitioned_build_blocks[i];
-
-        if (!mutable_block ||
-            mutable_block->allocated_bytes() < SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
+    for (size_t i = 0; i != _shared_state->_partitioned_build_blocks.size(); ++i) {
+        auto& mutable_block = _shared_state->_partitioned_build_blocks[i];
+        if (!mutable_block) {
             continue;
         }
-
-        auto status = [&]() {
-            RETURN_IF_CATCH_EXCEPTION(
-                    return _spill_to_disk(static_cast<uint32_t>(i), spilling_stream));
-        }();
-
-        RETURN_IF_ERROR(status);
+        if (force_spill || mutable_block->allocated_bytes() >= state->spill_buffer_size_bytes()) {
+            RETURN_IF_ERROR(_spill_to_disk(static_cast<uint32_t>(i)));
+        }
     }
     return Status::OK();
 }
 
-Status PartitionedHashJoinSinkLocalState::revoke_memory(
-        RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context) {
-    SCOPED_TIMER(_spill_total_timer);
+Status PartitionedHashJoinSinkLocalState::revoke_memory(RuntimeState* state) {
     VLOG_DEBUG << fmt::format("Query:{}, hash join sink:{}, task:{}, revoke_memory, eos:{}",
                               print_id(state->query_id()), _parent->node_id(), state->task_id(),
                               _child_eos);
 
-    if (!_shared_state->is_spilled) {
+    if (!_shared_state->_is_spilled) {
         custom_profile()->add_info_string("Spilled", "true");
-        _shared_state->is_spilled = true;
-        return _revoke_unpartitioned_block(state, spill_context);
-    }
-
-    const auto query_id = state->query_id();
-    SpillSinkRunnable spill_runnable(
-            state, nullptr, operator_profile(),
-            [this, state, query_id] { return _execute_spill_partitioned_blocks(state, query_id); },
-            [this, state, query_id, spill_context]() {
-                return _finish_spilling_callback(state, query_id, spill_context);
-            });
-
-    return spill_runnable.run();
-}
-
-Status PartitionedHashJoinSinkLocalState::_finish_spilling() {
-    for (auto& stream : _shared_state->spilled_streams) {
-        if (stream) {
-            RETURN_IF_ERROR(stream->spill_eof());
-        }
-    }
+        _shared_state->_is_spilled = true;
+        Status st = _revoke_unpartitioned_block(state);
+        DCHECK(revocable_mem_size(state) == 0);
+        return st;
+    }
+    RETURN_IF_ERROR(_execute_spill_partitioned_blocks(state, true /*force_spill*/));
+    // force flush all partitions to make sure data is written to disk
+    RETURN_IF_ERROR(_force_flush_partitions(state));
+    DCHECK(revocable_mem_size(state) == 0);
     return Status::OK();
 }
 
@@ -422,15 +336,12 @@ Status PartitionedHashJoinSinkLocalState::_partition_block(RuntimeState* state,
     if (!rows) {
         return Status::OK();
     }
+
+    SCOPED_TIMER(_partition_shuffle_timer);
     Defer defer {[&]() { update_memory_usage(); }};
-    {
-        /// TODO: DO NOT execute build exprs twice(when partition and building hash table)
-        SCOPED_TIMER(_partition_timer);
-        RETURN_IF_ERROR(_partitioner->do_partitioning(state, in_block));
-    }
+    RETURN_IF_ERROR(_partitioner->do_partitioning(state, in_block));
 
     auto& p = _parent->cast<PartitionedHashJoinSinkOperatorX>();
-    SCOPED_TIMER(_partition_shuffle_timer);
     const auto& channel_ids = _partitioner->get_channel_ids();
     std::vector<std::vector<uint32_t>> partition_indexes(p._partition_count);
     DCHECK_LT(begin, end);
@@ -438,7 +349,7 @@ Status PartitionedHashJoinSinkLocalState::_partition_block(RuntimeState* state,
         partition_indexes[channel_ids[i]].emplace_back(i);
     }
 
-    auto& partitioned_blocks = _shared_state->partitioned_build_blocks;
+    auto& partitioned_blocks = _shared_state->_partitioned_build_blocks;
     for (uint32_t i = 0; i != p._partition_count; ++i) {
         const auto count = partition_indexes[i].size();
         if (UNLIKELY(count == 0)) {
@@ -458,26 +369,33 @@ Status PartitionedHashJoinSinkLocalState::_partition_block(RuntimeState* state,
     return Status::OK();
 }
 
-Status PartitionedHashJoinSinkLocalState::_spill_to_disk(uint32_t partition_index,
-                                                         const SpillStreamSPtr& spilling_stream) {
-    auto& partitioned_block = _shared_state->partitioned_build_blocks[partition_index];
-
-    if (!_state->is_cancelled()) {
-        auto block = partitioned_block->to_block();
-        int64_t block_mem_usage = block.allocated_bytes();
-        Defer defer {[&]() { COUNTER_UPDATE(memory_used_counter(), -block_mem_usage); }};
-        partitioned_block = MutableBlock::create_unique(block.clone_empty());
-        return spilling_stream->spill_block(state(), block, false);
-    } else {
-        return _state->cancel_reason();
-    }
+Status PartitionedHashJoinSinkLocalState::_spill_to_disk(uint32_t partition_index) {
+    auto& partitioned_block = _shared_state->_partitioned_build_blocks[partition_index];
+
+    auto block = partitioned_block->to_block();
+    int64_t block_mem_usage = block.allocated_bytes();
+    Defer defer {[&]() { COUNTER_UPDATE(memory_used_counter(), -block_mem_usage); }};
+    partitioned_block = MutableBlock::create_unique(block.clone_empty());
+
+    // Lazy-create SpillFile + Writer if needed
+    auto& spill_file = _shared_state->_spilled_build_groups[partition_index];
+    auto& writer = _build_writers[partition_index];
+    if (!writer) {
+        auto label = fmt::format("hash_build_sink_{}", partition_index);
+        auto relative_path = fmt::format("{}/{}-{}-{}-{}", print_id(state()->query_id()), label,
+                                         _parent->node_id(), state()->task_id(),
+                                         ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+        RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(relative_path,
+                                                                                    spill_file));
+        RETURN_IF_ERROR(spill_file->create_writer(state(), operator_profile(), writer));
+    }
+    return writer->write_block(state(), block);
 }
 
 PartitionedHashJoinSinkOperatorX::PartitionedHashJoinSinkOperatorX(ObjectPool* pool,
                                                                    int operator_id, int dest_id,
                                                                    const TPlanNode& tnode,
-                                                                   const DescriptorTbl& descs,
-                                                                   uint32_t partition_count)
+                                                                   const DescriptorTbl& descs)
         : JoinBuildSinkOperatorX<PartitionedHashJoinSinkLocalState>(pool, operator_id, dest_id,
                                                                     tnode, descs),
           _join_distribution(tnode.hash_join_node.__isset.dist_type ? tnode.hash_join_node.dist_type
@@ -486,12 +404,12 @@ PartitionedHashJoinSinkOperatorX::PartitionedHashJoinSinkOperatorX(ObjectPool* p
                                                 ? tnode.distribute_expr_lists[1]
                                                 : std::vector<TExpr> {}),
           _tnode(tnode),
-          _descriptor_tbl(descs),
-          _partition_count(partition_count) {
+          _descriptor_tbl(descs) {
     _spillable = true;
 }
 
 Status PartitionedHashJoinSinkOperatorX::init(const TPlanNode& tnode, RuntimeState* state) {
+    _partition_count = state->spill_hash_join_partition_count();
     RETURN_IF_ERROR(JoinBuildSinkOperatorX::init(tnode, state));
     _name = "PARTITIONED_HASH_JOIN_SINK_OPERATOR";
     const std::vector<TEqJoinCondition>& eq_join_conjuncts = tnode.hash_join_node.eq_join_conjuncts;
@@ -558,8 +476,8 @@ Status PartitionedHashJoinSinkLocalState::_setup_internal_operator(RuntimeState*
     _finish_dependency = sink_local_state->finishdependency()->shared_from_this();
 
     /// Set these two values after all the work is ready.
-    _shared_state->inner_shared_state = std::move(inner_shared_state);
-    _shared_state->inner_runtime_state = std::move(inner_runtime_state);
+    _shared_state->_inner_shared_state = std::move(inner_shared_state);
+    _shared_state->_inner_runtime_state = std::move(inner_runtime_state);
     return Status::OK();
 }
 
@@ -567,7 +485,7 @@ Status PartitionedHashJoinSinkLocalState::_setup_internal_operator(RuntimeState*
     update_profile_from_inner_profile<false>(name, custom_profile(), inner_profile)
 
 void PartitionedHashJoinSinkLocalState::update_profile_from_inner() {
-    auto* sink_local_state = _shared_state->inner_runtime_state->get_sink_local_state();
+    auto* sink_local_state = _shared_state->_inner_runtime_state->get_sink_local_state();
     if (sink_local_state) {
         auto* inner_sink_state = assert_cast<HashJoinBuildSinkLocalState*>(sink_local_state);
         auto* inner_profile = inner_sink_state->custom_profile();
@@ -583,138 +501,66 @@ void PartitionedHashJoinSinkLocalState::update_profile_from_inner() {
 
 #undef UPDATE_COUNTER_FROM_INNER
 
-// After building hash table it will not be able to spill later
-// even if memory is low, and will cause cancel of queries.
-// So make a check here, if build blocks mem usage is too high,
-// then trigger revoke memory.
-static bool is_revocable_mem_high_watermark(RuntimeState* state, size_t revocable_size,
-                                            int64_t query_mem_limit) {
-    auto revocable_memory_high_watermark_percent =
-            state->spill_revocable_memory_high_watermark_percent();
-    return revocable_memory_high_watermark_percent > 0 &&
-           static_cast<double>(revocable_size) >=
-                   (double)query_mem_limit / 100.0 * revocable_memory_high_watermark_percent;
-}
-
 Status PartitionedHashJoinSinkOperatorX::sink(RuntimeState* state, Block* in_block, bool eos) {
     auto& local_state = get_local_state(state);
     SCOPED_TIMER(local_state.exec_time_counter());
-
-    local_state._child_eos = eos;
-
     const auto rows = in_block->rows();
+    if (rows > 0) {
+        COUNTER_UPDATE(local_state.rows_input_counter(), (int64_t)rows);
+    }
 
-    const auto is_spilled = local_state._shared_state->is_spilled;
-    size_t revocable_size = 0;
-    int64_t query_mem_limit = 0;
-    if (eos) {
-        revocable_size = revocable_mem_size(state);
-        query_mem_limit = state->get_query_ctx()->resource_ctx()->memory_context()->mem_limit();
-        LOG(INFO) << fmt::format(
-                "Query:{}, hash join sink:{}, task:{}, eos, need spill:{}, query mem limit:{}, "
-                "revocable memory:{}",
-                print_id(state->query_id()), node_id(), state->task_id(), is_spilled,
-                PrettyPrinter::print_bytes(query_mem_limit),
-                PrettyPrinter::print_bytes(revocable_size));
-    }
-
-    if (rows == 0) {
-        if (eos) {
-            if (is_spilled) {
-                return revoke_memory(state, nullptr);
-            } else {
-                DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_sink::sink_eos", {
-                    return Status::Error<INTERNAL_ERROR>(
-                            "fault_inject partitioned_hash_join_sink "
-                            "sink_eos failed");
-                });
-
-                if (is_revocable_mem_high_watermark(state, revocable_size, query_mem_limit)) {
-                    LOG(INFO) << fmt::format(
-                            "Query:{}, hash join sink:{}, task:{} eos, revoke_memory "
-                            "because revocable memory is high",
-                            print_id(state->query_id()), node_id(), state->task_id());
-                    return revoke_memory(state, nullptr);
-                }
-
-                Defer defer {[&]() { local_state.update_memory_usage(); }};
-                RETURN_IF_ERROR(_inner_sink_operator->sink(
-                        local_state._shared_state->inner_runtime_state.get(), in_block, eos));
-
-                local_state.update_profile_from_inner();
-
-                LOG(INFO) << fmt::format(
-                        "Query:{}, hash join sink:{}, task:{}, eos, set_ready_to_read, nonspill "
-                        "memory usage:{}",
-                        print_id(state->query_id()), node_id(), state->task_id(),
-                        _inner_sink_operator->get_memory_usage_debug_str(
-                                local_state._shared_state->inner_runtime_state.get()));
-            }
-
-            std::ranges::for_each(
-                    local_state._shared_state->partitioned_build_blocks, [&](auto& block) {
-                        if (block) {
-                            COUNTER_UPDATE(local_state._in_mem_rows_counter, block->rows());
-                        }
-                    });
-            local_state._dependency->set_ready_to_read();
+    if (local_state._shared_state->_is_spilled) {
+        // ---- Spilled path: data is partitioned and spilled to disk ----
+        if (rows > 0) {
+            RETURN_IF_ERROR(local_state._partition_block(state, in_block, 0, rows));
+            // If any partition block exceeds the spill buffer size, immediately spill that partition to disk to avoid large block accumulation.
+            RETURN_IF_ERROR(
+                    local_state._execute_spill_partitioned_blocks(state, false /*force_spill*/));
         }
-        return Status::OK();
-    }
 
-    COUNTER_UPDATE(local_state.rows_input_counter(), (int64_t)in_block->rows());
-    if (is_spilled) {
-        RETURN_IF_ERROR(local_state._partition_block(state, in_block, 0, rows));
-        if (eos) {
-            return revoke_memory(state, nullptr);
-        } else if (revocable_mem_size(state) > SpillStream::MAX_SPILL_WRITE_BATCH_MEM) {
-            return revoke_memory(state, nullptr);
+        // Flush partitioned blocks when eos or when accumulated data is large enough.
+        if (revocable_mem_size(state) > state->spill_join_build_sink_mem_limit_bytes()) {
+            RETURN_IF_ERROR(revoke_memory(state));
         }
     } else {
+        // ---- Non-spill path: forward data to the inner hash join sink ----
         DBUG_EXECUTE_IF("fault_inject::partitioned_hash_join_sink::sink", {
             return Status::Error<INTERNAL_ERROR>(
-                    "fault_inject partitioned_hash_join_sink "
-                    "sink failed");
+                    "fault_inject partitioned_hash_join_sink sink failed");
         });
 
-        if (eos) {
-            if (is_revocable_mem_high_watermark(state, revocable_size, query_mem_limit)) {
-                LOG(INFO) << fmt::format(
-                        "Query:{}, hash join sink:{}, task:{}, eos, revoke_memory "
-                        "because revocable memory is high",
-                        print_id(state->query_id()), node_id(), state->task_id());
-                return revoke_memory(state, nullptr);
-            }
-        }
+        // Sink the block into the inner (non-partitioned) hash join build operator.
         RETURN_IF_ERROR(_inner_sink_operator->sink(
-                local_state._shared_state->inner_runtime_state.get(), in_block, eos));
+                local_state._shared_state->_inner_runtime_state.get(), in_block, eos));
         local_state.update_memory_usage();
         local_state.update_profile_from_inner();
-        if (eos) {
-            LOG(INFO) << fmt::format(
-                    "Query:{}, hash join sink:{}, task:{}, eos, set_ready_to_read, nonspill memory "
-                    "usage:{}",
-                    print_id(state->query_id()), node_id(), state->task_id(),
-                    _inner_sink_operator->get_memory_usage_debug_str(
-                            local_state._shared_state->inner_runtime_state.get()));
-            local_state._dependency->set_ready_to_read();
-        }
     }
 
+    if (eos) {
+        local_state._child_eos = true;
+        if (local_state._shared_state->_is_spilled) {
+            RETURN_IF_ERROR(local_state._force_flush_partitions(state));
+            RETURN_IF_ERROR(local_state._finish_spilling(state));
+        }
+        local_state._dependency->set_ready_to_read();
+    }
     return Status::OK();
 }
 
 size_t PartitionedHashJoinSinkOperatorX::revocable_mem_size(RuntimeState* state) const {
     auto& local_state = get_local_state(state);
+    if (local_state._child_eos) {
+        return 0;
+    }
     SCOPED_TIMER(local_state.exec_time_counter());
     return local_state.revocable_mem_size(state);
 }
 
-Status PartitionedHashJoinSinkOperatorX::revoke_memory(
-        RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context) {
+Status PartitionedHashJoinSinkOperatorX::revoke_memory(RuntimeState* state) {
     auto& local_state = get_local_state(state);
+    CHECK(!local_state._child_eos);
     SCOPED_TIMER(local_state.exec_time_counter());
-    return local_state.revoke_memory(state, spill_context);
+    return local_state.revoke_memory(state);
 }
 
 size_t PartitionedHashJoinSinkOperatorX::get_reserve_mem_size(RuntimeState* state, bool eos) {
@@ -723,7 +569,7 @@ size_t PartitionedHashJoinSinkOperatorX::get_reserve_mem_size(RuntimeState* stat
 }
 
 bool PartitionedHashJoinSinkLocalState::is_blockable() const {
-    return _shared_state->is_spilled;
+    return _shared_state->_is_spilled;
 }
 
 #include "common/compile_check_end.h"
diff --git a/be/src/exec/operator/partitioned_hash_join_sink_operator.h b/be/src/exec/operator/partitioned_hash_join_sink_operator.h
index cd355ef1b5f..c4ffeb0ce44 100644
--- a/be/src/exec/operator/partitioned_hash_join_sink_operator.h
+++ b/be/src/exec/operator/partitioned_hash_join_sink_operator.h
@@ -26,9 +26,10 @@
 #include "exec/operator/hashjoin_probe_operator.h"
 #include "exec/operator/join_build_sink_operator.h"
 #include "exec/operator/operator.h"
-#include "exec/operator/spill_utils.h"
 #include "exec/partitioner/partitioner.h"
 #include "exec/pipeline/dependency.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_writer.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -45,7 +46,7 @@ public:
     Status init(RuntimeState* state, LocalSinkStateInfo& info) override;
     Status open(RuntimeState* state) override;
     Status close(RuntimeState* state, Status exec_status) override;
-    Status revoke_memory(RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context);
+    Status revoke_memory(RuntimeState* state);
     size_t revocable_mem_size(RuntimeState* state) const;
     Status terminate(RuntimeState* state) override;
     [[nodiscard]] size_t get_reserve_mem_size(RuntimeState* state, bool eos);
@@ -60,21 +61,26 @@ protected:
     PartitionedHashJoinSinkLocalState(DataSinkOperatorXBase* parent, RuntimeState* state)
             : PipelineXSpillSinkLocalState<PartitionedHashJoinSharedState>(parent, state) {}
 
-    Status _spill_to_disk(uint32_t partition_index, const SpillStreamSPtr& spilling_stream);
+    Status _spill_to_disk(uint32_t partition_index);
 
     Status _partition_block(RuntimeState* state, Block* in_block, size_t begin, size_t end);
 
-    Status _revoke_unpartitioned_block(RuntimeState* state,
-                                       const std::shared_ptr<SpillContext>& spill_context);
+    Status _revoke_unpartitioned_block(RuntimeState* state);
 
-    Status _execute_spill_unpartitioned_block(RuntimeState* state, Block&& build_block);
+    Status _finish_spilling(RuntimeState* state);
+    // Flush any remaining partitioned in-memory blocks and close spill streams.
+    // Called after revoke operations to guarantee memory is cleared.
+    Status _force_flush_partitions(RuntimeState* state);
 
-    Status _finish_spilling();
-
-    Status _finish_spilling_callback(RuntimeState* state, TUniqueId query_id,
-                                     const std::shared_ptr<SpillContext>& spill_context);
-
-    Status _execute_spill_partitioned_blocks(RuntimeState* state, TUniqueId query_id);
+    /**
+     * @brief Spill partitioned build blocks to disk if needed.
+     *
+     * @param state Runtime state for the operator.
+     * @param force_spill If true, spill all non-empty partition blocks regardless of size;
+     *                    if false, only spill blocks whose size exceeds the spill buffer threshold.
+     *                    Use force_spill at call sites for clarity.
+     */
+    Status _execute_spill_partitioned_blocks(RuntimeState* state, bool force_spill);
 
     Status _setup_internal_operator(RuntimeState* state);
 
@@ -87,19 +93,19 @@ protected:
     std::unique_ptr<RuntimeProfile> _internal_runtime_profile;
     std::shared_ptr<Dependency> _finish_dependency;
 
-    RuntimeProfile::Counter* _partition_timer = nullptr;
     RuntimeProfile::Counter* _partition_shuffle_timer = nullptr;
     RuntimeProfile::Counter* _spill_build_timer = nullptr;
     RuntimeProfile::Counter* _in_mem_rows_counter = nullptr;
     RuntimeProfile::Counter* _memory_usage_reserved = nullptr;
+
+    std::vector<SpillFileWriterSPtr> _build_writers;
 };
 
 class PartitionedHashJoinSinkOperatorX
         : public JoinBuildSinkOperatorX<PartitionedHashJoinSinkLocalState> {
 public:
     PartitionedHashJoinSinkOperatorX(ObjectPool* pool, int operator_id, int dest_id,
-                                     const TPlanNode& tnode, const DescriptorTbl& descs,
-                                     uint32_t partition_count);
+                                     const TPlanNode& tnode, const DescriptorTbl& descs);
 
     Status init(const TDataSink& tsink) override {
         return Status::InternalError("{} should not init with TDataSink",
@@ -116,8 +122,7 @@ public:
 
     size_t revocable_mem_size(RuntimeState* state) const override;
 
-    Status revoke_memory(RuntimeState* state,
-                         const std::shared_ptr<SpillContext>& spill_context) override;
+    Status revoke_memory(RuntimeState* state) override;
 
     size_t get_reserve_mem_size(RuntimeState* state, bool eos) override;
 
@@ -172,7 +177,8 @@ private:
     const std::vector<TExpr> _distribution_partition_exprs;
     const TPlanNode _tnode;
     const DescriptorTbl _descriptor_tbl;
-    const uint32_t _partition_count;
+
+    uint32_t _partition_count;
     std::unique_ptr<PartitionerBase> _partitioner;
 };
 
diff --git a/be/src/exec/operator/spill_iceberg_table_sink_operator.cpp b/be/src/exec/operator/spill_iceberg_table_sink_operator.cpp
index 0a5126d2bef..c557ac58e60 100644
--- a/be/src/exec/operator/spill_iceberg_table_sink_operator.cpp
+++ b/be/src/exec/operator/spill_iceberg_table_sink_operator.cpp
@@ -79,21 +79,14 @@ size_t SpillIcebergTableSinkLocalState::get_revocable_mem_size(RuntimeState* sta
     return sort_writer->sorter()->data_size();
 }
 
-Status SpillIcebergTableSinkLocalState::revoke_memory(
-        RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context) {
+Status SpillIcebergTableSinkLocalState::revoke_memory(RuntimeState* state) {
     if (!_writer || !_writer->current_writer()) {
-        if (spill_context) {
-            spill_context->on_task_finished();
-        }
         return Status::OK();
     }
 
     auto* sort_writer = dynamic_cast<VIcebergSortWriter*>(_writer->current_writer().get());
 
     if (!sort_writer || !sort_writer->sorter()) {
-        if (spill_context) {
-            spill_context->on_task_finished();
-        }
         return Status::OK();
     }
 
@@ -104,13 +97,7 @@ Status SpillIcebergTableSinkLocalState::revoke_memory(
         return status;
     };
 
-    state->get_query_ctx()->resource_ctx()->task_controller()->increase_revoking_tasks_count();
-    auto status =
-            SpillSinkRunnable(state, spill_context, operator_profile(), exception_catch_func).run();
-    if (!status.ok()) {
-        state->get_query_ctx()->resource_ctx()->task_controller()->decrease_revoking_tasks_count();
-    }
-    return status;
+    return run_spill_task(state, exception_catch_func);
 }
 
 SpillIcebergTableSinkOperatorX::SpillIcebergTableSinkOperatorX(
@@ -150,10 +137,9 @@ size_t SpillIcebergTableSinkOperatorX::revocable_mem_size(RuntimeState* state) c
     return local_state.get_revocable_mem_size(state);
 }
 
-Status SpillIcebergTableSinkOperatorX::revoke_memory(
-        RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context) {
+Status SpillIcebergTableSinkOperatorX::revoke_memory(RuntimeState* state) {
     auto& local_state = get_local_state(state);
-    return local_state.revoke_memory(state, spill_context);
+    return local_state.revoke_memory(state);
 }
 
 void SpillIcebergTableSinkLocalState::_init_spill_counters() {
diff --git a/be/src/exec/operator/spill_iceberg_table_sink_operator.h b/be/src/exec/operator/spill_iceberg_table_sink_operator.h
index a31a017f28f..d81e515f05d 100644
--- a/be/src/exec/operator/spill_iceberg_table_sink_operator.h
+++ b/be/src/exec/operator/spill_iceberg_table_sink_operator.h
@@ -43,7 +43,7 @@ public:
 
     bool is_blockable() const override;
     [[nodiscard]] size_t get_reserve_mem_size(RuntimeState* state, bool eos);
-    Status revoke_memory(RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context);
+    Status revoke_memory(RuntimeState* state);
     size_t get_revocable_mem_size(RuntimeState* state) const;
 
 private:
@@ -70,8 +70,7 @@ public:
 
     size_t revocable_mem_size(RuntimeState* state) const override;
 
-    Status revoke_memory(RuntimeState* state,
-                         const std::shared_ptr<SpillContext>& spill_context) override;
+    Status revoke_memory(RuntimeState* state) override;
 
     using DataSinkOperatorX<LocalStateType>::node_id;
     using DataSinkOperatorX<LocalStateType>::operator_id;
diff --git a/be/src/exec/operator/spill_sort_sink_operator.cpp b/be/src/exec/operator/spill_sort_sink_operator.cpp
index 396e069a408..3baec697de2 100644
--- a/be/src/exec/operator/spill_sort_sink_operator.cpp
+++ b/be/src/exec/operator/spill_sort_sink_operator.cpp
@@ -21,7 +21,9 @@
 #include "exec/operator/sort_sink_operator.h"
 #include "exec/operator/spill_utils.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_writer.h"
 #include "runtime/fragment_mgr.h"
 
 namespace doris {
@@ -44,7 +46,6 @@ Status SpillSortSinkLocalState::init(doris::RuntimeState* state, doris::LocalSin
 Status SpillSortSinkLocalState::open(RuntimeState* state) {
     SCOPED_TIMER(Base::exec_time_counter());
     SCOPED_TIMER(Base::_open_timer);
-    _shared_state->setup_shared_profile(custom_profile());
     return Base::open(state);
 }
 
@@ -64,6 +65,11 @@ void SpillSortSinkLocalState::update_profile(RuntimeProfile* child_profile) {
 #undef UPDATE_PROFILE
 
 Status SpillSortSinkLocalState::close(RuntimeState* state, Status execsink_status) {
+    if (_spilling_writer) {
+        RETURN_IF_ERROR(_spilling_writer->close());
+        _spilling_writer.reset();
+    }
+    _spilling_file.reset();
     return Base::close(state, execsink_status);
 }
 
@@ -127,15 +133,15 @@ size_t SpillSortSinkOperatorX::get_reserve_mem_size(RuntimeState* state, bool eo
     auto& local_state = get_local_state(state);
     return local_state.get_reserve_mem_size(state, eos);
 }
-Status SpillSortSinkOperatorX::revoke_memory(RuntimeState* state,
-                                             const std::shared_ptr<SpillContext>& spill_context) {
+Status SpillSortSinkOperatorX::revoke_memory(RuntimeState* state) {
     auto& local_state = get_local_state(state);
-    return local_state.revoke_memory(state, spill_context);
+    return local_state.revoke_memory(state);
 }
 
 size_t SpillSortSinkOperatorX::revocable_mem_size(RuntimeState* state) const {
     auto& local_state = get_local_state(state);
-    return _sort_sink_operator->get_revocable_mem_size(local_state._runtime_state.get());
+    auto mem_size = _sort_sink_operator->get_revocable_mem_size(local_state._runtime_state.get());
+    return mem_size > state->spill_min_revocable_mem() ? mem_size : 0;
 }
 
 Status SpillSortSinkOperatorX::sink(doris::RuntimeState* state, Block* in_block, bool eos) {
@@ -145,7 +151,6 @@ Status SpillSortSinkOperatorX::sink(doris::RuntimeState* state, Block* in_block,
     if (in_block->rows() > 0) {
         local_state._shared_state->update_spill_block_batch_row_count(state, in_block);
     }
-    local_state._eos = eos;
     DBUG_EXECUTE_IF("fault_inject::spill_sort_sink::sink",
                     { return Status::InternalError("fault_inject spill_sort_sink sink failed"); });
     RETURN_IF_ERROR(_sort_sink_operator->sink(local_state._runtime_state.get(), in_block, false));
@@ -153,19 +158,25 @@ Status SpillSortSinkOperatorX::sink(doris::RuntimeState* state, Block* in_block,
     int64_t data_size = local_state._shared_state->in_mem_shared_state->sorter->data_size();
     COUNTER_SET(local_state._memory_used_counter, data_size);
 
+    // Proactive spill: if already spilled, flush when accumulated data exceeds threshold.
+    if (local_state._shared_state->is_spilled) {
+        if (revocable_mem_size(state) >= state->spill_sort_sink_mem_limit_bytes()) {
+            RETURN_IF_ERROR(revoke_memory(state));
+            DCHECK(revocable_mem_size(state) == 0);
+        }
+    }
+
     if (eos) {
         if (local_state._shared_state->is_spilled) {
-            if (revocable_mem_size(state) > 0) {
-                RETURN_IF_ERROR(revoke_memory(state, nullptr));
-            } else {
-                local_state._dependency->set_ready_to_read();
-            }
+            RETURN_IF_ERROR(revoke_memory(state));
+            // TODO guolei: There is one step that needs to change the state.
         } else {
             RETURN_IF_ERROR(
                     local_state._shared_state->in_mem_shared_state->sorter->prepare_for_read(
                             false));
-            local_state._dependency->set_ready_to_read();
         }
+        local_state._eos = eos;
+        local_state._dependency->set_ready_to_read();
     }
     return Status::OK();
 }
@@ -176,64 +187,40 @@ size_t SpillSortSinkLocalState::get_reserve_mem_size(RuntimeState* state, bool e
                                                                           eos);
 }
 
-Status SpillSortSinkLocalState::_execute_spill_sort(RuntimeState* state, TUniqueId query_id) {
+Status SpillSortSinkLocalState::_execute_spill_sort(RuntimeState* state) {
     auto& parent = Base::_parent->template cast<Parent>();
-    Status status;
+    state->get_query_ctx()->resource_ctx()->task_controller()->increase_revoking_tasks_count();
     Defer defer {[&]() {
-        if (!status.ok() || state->is_cancelled()) {
-            if (!status.ok()) {
-                LOG(WARNING) << fmt::format(
-                        "Query:{}, sort sink:{}, task:{}, revoke memory error:{}",
-                        print_id(query_id), _parent->node_id(), state->task_id(), status);
-            }
-            _shared_state->close();
-        } else {
-            VLOG_DEBUG << fmt::format("Query:{}, sort sink:{}, task:{}, revoke memory finish",
-                                      print_id(query_id), _parent->node_id(), state->task_id());
-        }
-
-        if (!status.ok()) {
-            _shared_state->close();
-        }
-
-        _spilling_stream.reset();
+        _spilling_writer.reset();
+        _spilling_file.reset();
         state->get_query_ctx()->resource_ctx()->task_controller()->decrease_revoking_tasks_count();
-        if (_eos) {
-            _dependency->set_ready_to_read();
-        }
     }};
 
-    status = parent._sort_sink_operator->prepare_for_spill(_runtime_state.get());
-    RETURN_IF_ERROR(status);
+    RETURN_IF_ERROR(parent._sort_sink_operator->prepare_for_spill(_runtime_state.get()));
 
     auto* sink_local_state = _runtime_state->get_sink_local_state();
     update_profile(sink_local_state->custom_profile());
 
     bool eos = false;
-    Block block;
 
-    int32_t batch_size =
-            _shared_state->spill_block_batch_row_count > std::numeric_limits<int32_t>::max()
-                    ? std::numeric_limits<int32_t>::max()
-                    : static_cast<int32_t>(_shared_state->spill_block_batch_row_count);
+    Block block;
     while (!eos && !state->is_cancelled()) {
         {
             SCOPED_TIMER(_spill_merge_sort_timer);
-            status = parent._sort_sink_operator->merge_sort_read_for_spill(
-                    _runtime_state.get(), &block, batch_size, &eos);
+            // Currently, using 4096 as batch size, maybe using adptive size is better by using memory size.
+            RETURN_IF_ERROR(parent._sort_sink_operator->merge_sort_read_for_spill(
+                    _runtime_state.get(), &block, 4096, &eos));
         }
-        RETURN_IF_ERROR(status);
-        status = _spilling_stream->spill_block(state, block, eos);
-        RETURN_IF_ERROR(status);
+        RETURN_IF_ERROR(_spilling_writer->write_block(state, block));
         block.clear_column_data();
     }
-    parent._sort_sink_operator->reset(_runtime_state.get());
 
+    RETURN_IF_ERROR(_spilling_writer->close());
+    parent._sort_sink_operator->reset(_runtime_state.get());
     return Status::OK();
 }
 
-Status SpillSortSinkLocalState::revoke_memory(RuntimeState* state,
-                                              const std::shared_ptr<SpillContext>& spill_context) {
+Status SpillSortSinkLocalState::revoke_memory(RuntimeState* state) {
     auto& parent = Base::_parent->template cast<Parent>();
     if (!_shared_state->is_spilled) {
         _shared_state->is_spilled = true;
@@ -245,44 +232,16 @@ Status SpillSortSinkLocalState::revoke_memory(RuntimeState* state,
     VLOG_DEBUG << fmt::format("Query:{}, sort sink:{}, task:{}, revoke_memory, eos:{}",
                               print_id(state->query_id()), _parent->node_id(), state->task_id(),
                               _eos);
-
-    int32_t batch_size =
-            _shared_state->spill_block_batch_row_count > std::numeric_limits<int32_t>::max()
-                    ? std::numeric_limits<int32_t>::max()
-                    : static_cast<int32_t>(_shared_state->spill_block_batch_row_count);
-    auto status = ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-            state, _spilling_stream, print_id(state->query_id()), "sort", _parent->node_id(),
-            batch_size, state->spill_sort_batch_bytes(), operator_profile());
-    RETURN_IF_ERROR(status);
-
-    _shared_state->sorted_streams.emplace_back(_spilling_stream);
-
-    auto query_id = state->query_id();
-    auto exception_catch_func = [this, query_id, state]() {
-        DBUG_EXECUTE_IF("fault_inject::spill_sort_sink::revoke_memory_cancel", {
-            auto status =
-                    Status::InternalError("fault_inject spill_sort_sink revoke_memory canceled");
-            state->get_query_ctx()->cancel(status);
-            return status;
-        });
-
-        auto status = [&]() {
-            RETURN_IF_CATCH_EXCEPTION({ return _execute_spill_sort(state, query_id); });
-        }();
-
-        return status;
-    };
-
-    DBUG_EXECUTE_IF("fault_inject::spill_sort_sink::revoke_memory_submit_func", {
-        status = Status::Error<INTERNAL_ERROR>(
-                "fault_inject spill_sort_sink "
-                "revoke_memory submit_func failed");
-    });
-
-    RETURN_IF_ERROR(status);
-    state->get_query_ctx()->resource_ctx()->task_controller()->increase_revoking_tasks_count();
-
-    return SpillSinkRunnable(state, spill_context, operator_profile(), exception_catch_func).run();
+    _spilling_file.reset();
+    _spilling_writer.reset();
+    auto relative_path =
+            fmt::format("{}/{}-{}-{}-{}", print_id(state->query_id()), "sort", _parent->node_id(),
+                        state->task_id(), ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+    RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(relative_path,
+                                                                                _spilling_file));
+    RETURN_IF_ERROR(_spilling_file->create_writer(state, operator_profile(), _spilling_writer));
+    _shared_state->sorted_spill_groups.emplace_back(_spilling_file);
+    return _execute_spill_sort(state);
 }
 #include "common/compile_check_end.h"
-} // namespace doris
\ No newline at end of file
+} // namespace doris
diff --git a/be/src/exec/operator/spill_sort_sink_operator.h b/be/src/exec/operator/spill_sort_sink_operator.h
index 5284d681139..823bc5e7f04 100644
--- a/be/src/exec/operator/spill_sort_sink_operator.h
+++ b/be/src/exec/operator/spill_sort_sink_operator.h
@@ -21,6 +21,8 @@
 
 #include "exec/operator/operator.h"
 #include "exec/operator/sort_sink_operator.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_writer.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -44,13 +46,13 @@ public:
 
     Status setup_in_memory_sort_op(RuntimeState* state);
     [[nodiscard]] size_t get_reserve_mem_size(RuntimeState* state, bool eos);
-    Status revoke_memory(RuntimeState* state, const std::shared_ptr<SpillContext>& spill_context);
+    Status revoke_memory(RuntimeState* state);
 
 private:
     void _init_counters();
     void update_profile(RuntimeProfile* child_profile);
 
-    Status _execute_spill_sort(RuntimeState* state, TUniqueId query_id);
+    Status _execute_spill_sort(RuntimeState* state);
 
     friend class SpillSortSinkOperatorX;
 
@@ -59,7 +61,8 @@ private:
 
     RuntimeProfile::Counter* _spill_merge_sort_timer = nullptr;
 
-    SpillStreamSPtr _spilling_stream;
+    SpillFileSPtr _spilling_file;
+    SpillFileWriterSPtr _spilling_writer;
 
     std::atomic<bool> _eos = false;
 };
@@ -101,8 +104,7 @@ public:
 
     size_t revocable_mem_size(RuntimeState* state) const override;
 
-    Status revoke_memory(RuntimeState* state,
-                         const std::shared_ptr<SpillContext>& spill_context) override;
+    Status revoke_memory(RuntimeState* state) override;
 
     using DataSinkOperatorX<LocalStateType>::node_id;
     using DataSinkOperatorX<LocalStateType>::operator_id;
diff --git a/be/src/exec/operator/spill_sort_source_operator.cpp b/be/src/exec/operator/spill_sort_source_operator.cpp
index cb656761f74..7bb1bfa448b 100644
--- a/be/src/exec/operator/spill_sort_source_operator.cpp
+++ b/be/src/exec/operator/spill_sort_source_operator.cpp
@@ -26,9 +26,11 @@
 #include "exec/operator/sort_source_operator.h"
 #include "exec/operator/spill_utils.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
 #include "runtime/fragment_mgr.h"
-#include "runtime/runtime_profile.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -61,152 +63,118 @@ Status SpillSortLocalState::close(RuntimeState* state) {
     if (_closed) {
         return Status::OK();
     }
+
+    for (auto& reader : _current_merging_readers) {
+        if (reader) {
+            RETURN_IF_ERROR(reader->close());
+            reader.reset();
+        }
+    }
+    _current_merging_readers.clear();
+    _current_merging_files.clear();
+    _merger.reset();
+
     return Base::close(state);
 }
 
 int SpillSortLocalState::_calc_spill_blocks_to_merge(RuntimeState* state) const {
-    auto count = state->spill_sort_mem_limit() / state->spill_sort_batch_bytes();
-    if (count > std::numeric_limits<int>::max()) [[unlikely]] {
-        return std::numeric_limits<int>::max();
-    }
-    return std::max(2, static_cast<int32_t>(count));
+    auto count = state->spill_sort_merge_mem_limit_bytes() / state->spill_buffer_size_bytes();
+    return std::max(8, static_cast<int32_t>(count));
 }
 
-Status SpillSortLocalState::_execute_merge_sort_spill_streams(RuntimeState* state,
-                                                              TUniqueId query_id) {
+Status SpillSortLocalState::execute_merge_sort_spill_files(RuntimeState* state) {
     auto& parent = Base::_parent->template cast<Parent>();
     SCOPED_TIMER(_spill_merge_sort_timer);
     Status status;
-    Defer defer {[&]() {
-        if (!status.ok() || state->is_cancelled()) {
-            if (!status.ok()) {
-                LOG(WARNING) << fmt::format(
-                        "Query:{}, sort source:{}, task:{}, merge spill data error:{}",
-                        print_id(query_id), _parent->node_id(), state->task_id(), status);
-            }
-            for (auto& stream : _current_merging_streams) {
-                ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
-            }
-            _current_merging_streams.clear();
-        } else {
-            VLOG_DEBUG << fmt::format("Query:{}, sort source:{}, task:{}, merge spill data finish",
-                                      print_id(query_id), _parent->node_id(), state->task_id());
-        }
-    }};
+
     Block merge_sorted_block;
-    SpillStreamSPtr tmp_stream;
+    auto query_id = state->query_id();
     while (!state->is_cancelled()) {
         int max_stream_count = _calc_spill_blocks_to_merge(state);
         VLOG_DEBUG << fmt::format(
                 "Query:{}, sort source:{}, task:{}, merge spill streams, streams count:{}, "
-                "curren merge max stream count:{}",
+                "curren merge max spill file count:{}",
                 print_id(query_id), _parent->node_id(), state->task_id(),
-                _shared_state->sorted_streams.size(), max_stream_count);
-        {
-            SCOPED_TIMER(Base::_spill_recover_time);
-            status = _create_intermediate_merger(
-                    max_stream_count,
-                    parent._sort_source_operator->get_sort_description(_runtime_state.get()));
-        }
-        RETURN_IF_ERROR(status);
-
-        // all the remaining streams can be merged in a run
-        if (_shared_state->sorted_streams.empty()) {
+                _shared_state->sorted_spill_groups.size(), max_stream_count);
+        RETURN_IF_ERROR(_create_intermediate_merger(
+                state, max_stream_count,
+                parent._sort_source_operator->get_sort_description(_runtime_state.get())));
+        // It is a fast path, because all the remaining streams can be merged in a run
+        if (_shared_state->sorted_spill_groups.empty()) {
             return Status::OK();
         }
 
-        {
-            int32_t batch_size =
-                    _shared_state->spill_block_batch_row_count > std::numeric_limits<int32_t>::max()
-                            ? std::numeric_limits<int32_t>::max()
-                            : static_cast<int32_t>(_shared_state->spill_block_batch_row_count);
-            status = ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-                    state, tmp_stream, print_id(state->query_id()), "sort", _parent->node_id(),
-                    batch_size, state->spill_sort_batch_bytes(), operator_profile());
-            RETURN_IF_ERROR(status);
-
-            _shared_state->sorted_streams.emplace_back(tmp_stream);
-
-            bool eos = false;
-            while (!eos && !state->is_cancelled()) {
-                merge_sorted_block.clear_column_data();
-                {
-                    SCOPED_TIMER(Base::_spill_recover_time);
-                    DBUG_EXECUTE_IF("fault_inject::spill_sort_source::recover_spill_data", {
-                        status = Status::Error<INTERNAL_ERROR>(
-                                "fault_inject spill_sort_source "
-                                "recover_spill_data failed");
-                    });
-                    if (status.ok()) {
-                        status = _merger->get_next(&merge_sorted_block, &eos);
-                    }
-                }
-                RETURN_IF_ERROR(status);
-                status = tmp_stream->spill_block(state, merge_sorted_block, eos);
+        SpillFileSPtr tmp_file;
+        auto label = "sort";
+        auto relative_path = fmt::format("{}/{}-{}-{}-{}", print_id(state->query_id()), label,
+                                         _parent->node_id(), state->task_id(),
+                                         ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+        RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(relative_path,
+                                                                                    tmp_file));
+        SpillFileWriterSPtr tmp_writer;
+        RETURN_IF_ERROR(tmp_file->create_writer(state, operator_profile(), tmp_writer));
+        _shared_state->sorted_spill_groups.emplace_back(tmp_file);
+
+        bool eos = false;
+        while (!eos && !state->is_cancelled()) {
+            merge_sorted_block.clear_column_data();
+            {
+                DBUG_EXECUTE_IF("fault_inject::spill_sort_source::recover_spill_data", {
+                    status = Status::Error<INTERNAL_ERROR>(
+                            "fault_inject spill_sort_source "
+                            "recover_spill_data failed");
+                });
                 if (status.ok()) {
-                    DBUG_EXECUTE_IF("fault_inject::spill_sort_source::spill_merged_data", {
-                        status = Status::Error<INTERNAL_ERROR>(
-                                "fault_inject spill_sort_source "
-                                "spill_merged_data failed");
-                    });
+                    status = _merger->get_next(&merge_sorted_block, &eos);
                 }
-                RETURN_IF_ERROR(status);
             }
+            RETURN_IF_ERROR(status);
+            status = tmp_writer->write_block(state, merge_sorted_block);
+            if (status.ok()) {
+                DBUG_EXECUTE_IF("fault_inject::spill_sort_source::spill_merged_data", {
+                    status = Status::Error<INTERNAL_ERROR>(
+                            "fault_inject spill_sort_source "
+                            "spill_merged_data failed");
+                });
+            }
+            RETURN_IF_ERROR(status);
         }
-        for (auto& stream : _current_merging_streams) {
-            ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
-        }
-        _current_merging_streams.clear();
+        RETURN_IF_ERROR(tmp_writer->close());
     }
     return Status::OK();
 }
 
-Status SpillSortLocalState::initiate_merge_sort_spill_streams(RuntimeState* state) {
-    VLOG_DEBUG << fmt::format("Query:{}, sort source:{}, task:{}, merge spill data",
-                              print_id(state->query_id()), _parent->node_id(), state->task_id());
-
-    auto query_id = state->query_id();
-    auto exception_catch_func = [this, state, query_id]() {
-        auto status = [&]() {
-            RETURN_IF_CATCH_EXCEPTION(
-                    { return _execute_merge_sort_spill_streams(state, query_id); });
-        }();
-        return status;
-    };
-
-    DBUG_EXECUTE_IF("fault_inject::spill_sort_source::merge_sort_spill_data_submit_func", {
-        return Status::Error<INTERNAL_ERROR>(
-                "fault_inject spill_sort_source "
-                "merge_sort_spill_data submit_func failed");
-    });
-
-    return SpillRecoverRunnable(state, operator_profile(), exception_catch_func).run();
-}
-
-Status SpillSortLocalState::_create_intermediate_merger(int num_blocks,
+Status SpillSortLocalState::_create_intermediate_merger(RuntimeState* state, int num_blocks,
                                                         const SortDescription& sort_description) {
     std::vector<BlockSupplier> child_block_suppliers;
     int64_t limit = -1;
     int64_t offset = 0;
-    if (num_blocks >= _shared_state->sorted_streams.size()) {
+    if (num_blocks >= _shared_state->sorted_spill_groups.size()) {
         // final round use real limit and offset
         limit = Base::_shared_state->limit;
         offset = Base::_shared_state->offset;
     }
 
-    _merger = std::make_unique<VSortedRunMerger>(sort_description, _runtime_state->batch_size(),
-                                                 limit, offset, custom_profile());
+    _merger = std::make_unique<VSortedRunMerger>(sort_description, state->batch_size(), limit,
+                                                 offset, custom_profile());
 
-    _current_merging_streams.clear();
-    for (int i = 0; i < num_blocks && !_shared_state->sorted_streams.empty(); ++i) {
-        auto stream = _shared_state->sorted_streams.front();
-        stream->set_read_counters(operator_profile());
-        _current_merging_streams.emplace_back(stream);
-        child_block_suppliers.emplace_back([stream](Block* block, bool* eos) {
-            return stream->read_next_block_sync(block, eos);
-        });
+    _current_merging_files.clear();
+    _current_merging_readers.clear();
+    for (int i = 0; i < num_blocks && !_shared_state->sorted_spill_groups.empty(); ++i) {
+        auto spill_file = _shared_state->sorted_spill_groups.front();
+        _shared_state->sorted_spill_groups.pop_front();
+        _current_merging_files.emplace_back(spill_file);
+
+        // Each SpillFile's reader handles multi-part reading internally.
+        auto reader = spill_file->create_reader(state, operator_profile());
+        RETURN_IF_ERROR(reader->open());
 
-        _shared_state->sorted_streams.pop_front();
+        auto reader_ptr = reader.get();
+        _current_merging_readers.emplace_back(std::move(reader));
+
+        child_block_suppliers.emplace_back([reader_ptr](Block* block, bool* eos) -> Status {
+            return reader_ptr->read(block, eos);
+        });
     }
     RETURN_IF_ERROR(_merger->prepare(child_block_suppliers));
     return Status::OK();
@@ -261,37 +229,35 @@ Status SpillSortSourceOperatorX::prepare(RuntimeState* state) {
 
 Status SpillSortSourceOperatorX::close(RuntimeState* state) {
     RETURN_IF_ERROR(OperatorXBase::close(state));
+
+    // Perform final cleanup for local state: delete any merging streams and
+    // close shared state. Centralize cleanup so resources are released when
+    // the pipeline task finishes.
+    auto& local_state = get_local_state(state);
+    local_state._current_merging_files.clear();
+    local_state._current_merging_readers.clear();
+    local_state._merger.reset();
+
+    if (local_state._shared_state) {
+        local_state._shared_state->close();
+    }
+
     return _sort_source_operator->close(state);
 }
 
 Status SpillSortSourceOperatorX::get_block(RuntimeState* state, Block* block, bool* eos) {
     auto& local_state = get_local_state(state);
-    local_state.copy_shared_spill_profile();
-    Status status;
-    Defer defer {[&]() {
-        if (!status.ok() || *eos) {
-            local_state._shared_state->close();
-            for (auto& stream : local_state._current_merging_streams) {
-                ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
-            }
-            local_state._current_merging_streams.clear();
-            local_state._merger.reset();
-        }
-    }};
     SCOPED_TIMER(local_state.exec_time_counter());
 
     if (local_state._shared_state->is_spilled) {
         if (!local_state._merger) {
-            status = local_state.initiate_merge_sort_spill_streams(state);
-            return status;
+            return local_state.execute_merge_sort_spill_files(state);
         } else {
-            SCOPED_TIMER(local_state._spill_total_timer);
-            status = local_state._merger->get_next(block, eos);
-            RETURN_IF_ERROR(status);
+            RETURN_IF_ERROR(local_state._merger->get_next(block, eos));
         }
     } else {
-        status = _sort_source_operator->get_block(local_state._runtime_state.get(), block, eos);
-        RETURN_IF_ERROR(status);
+        RETURN_IF_ERROR(
+                _sort_source_operator->get_block(local_state._runtime_state.get(), block, eos));
     }
     local_state.reached_limit(block, eos);
     return Status::OK();
diff --git a/be/src/exec/operator/spill_sort_source_operator.h b/be/src/exec/operator/spill_sort_source_operator.h
index 5027446b787..969582243e0 100644
--- a/be/src/exec/operator/spill_sort_source_operator.h
+++ b/be/src/exec/operator/spill_sort_source_operator.h
@@ -21,6 +21,8 @@
 
 #include "common/status.h"
 #include "exec/operator/operator.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_reader.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -46,20 +48,21 @@ public:
 
     Status setup_in_memory_sort_op(RuntimeState* state);
 
-    Status initiate_merge_sort_spill_streams(RuntimeState* state);
+    Status execute_merge_sort_spill_files(RuntimeState* state);
 
 protected:
     int _calc_spill_blocks_to_merge(RuntimeState* state) const;
-    Status _create_intermediate_merger(int num_blocks, const SortDescription& sort_description);
-
-    Status _execute_merge_sort_spill_streams(RuntimeState* state, TUniqueId query_id);
+    Status _create_intermediate_merger(RuntimeState* state, int num_blocks,
+                                       const SortDescription& sort_description);
 
     friend class SpillSortSourceOperatorX;
     std::unique_ptr<RuntimeState> _runtime_state;
 
     bool _opened = false;
 
-    std::vector<SpillStreamSPtr> _current_merging_streams;
+    std::vector<SpillFileSPtr> _current_merging_files;
+    /// Readers held alive during merge; one per SpillFile, reads parts sequentially.
+    std::vector<SpillFileReaderSPtr> _current_merging_readers;
     std::unique_ptr<VSortedRunMerger> _merger;
 
     std::unique_ptr<RuntimeProfile> _internal_runtime_profile;
diff --git a/be/src/exec/operator/spill_utils.h b/be/src/exec/operator/spill_utils.h
index 44c4de17fd4..6a84c6fc2b0 100644
--- a/be/src/exec/operator/spill_utils.h
+++ b/be/src/exec/operator/spill_utils.h
@@ -35,8 +35,15 @@
 
 namespace doris {
 #include "common/compile_check_begin.h"
+
+// Default spill partitioner for initial partitioning (level-0). Repartition
+// paths may use different channel-id policies (e.g. raw-hash mode).
 using SpillPartitionerType = Crc32HashPartitioner<SpillPartitionChannelIds>;
 
+// Repartition partitioner: keeps raw hash (no final modulo) so SpillRepartitioner
+// can apply level-aware hash mixing and channel mapping.
+using SpillRePartitionerType = Crc32HashPartitioner<SpillRePartitionChannelIds>;
+
 struct SpillContext {
     std::atomic_int running_tasks_count;
     TUniqueId query_id;
@@ -64,154 +71,20 @@ struct SpillContext {
     }
 };
 
-class SpillRunnable {
-protected:
-    SpillRunnable(RuntimeState* state, std::shared_ptr<SpillContext> spill_context,
-                  RuntimeProfile* operator_profile, bool is_write,
-                  std::function<Status()> spill_exec_func,
-                  std::function<Status()> spill_fin_cb = {})
-            : _state(state),
-              _custom_profile(operator_profile->get_child("CustomCounters")),
-              _spill_context(std::move(spill_context)),
-              _is_write_task(is_write),
-              _spill_exec_func(std::move(spill_exec_func)),
-              _spill_fin_cb(std::move(spill_fin_cb)) {
-        RuntimeProfile* common_profile = operator_profile->get_child("CommonCounters");
-        DCHECK(common_profile != nullptr);
-        DCHECK(_custom_profile != nullptr);
-        _spill_total_timer = _custom_profile->get_counter("SpillTotalTime");
-
-        if (is_write) {
-            _write_wait_in_queue_task_count =
-                    _custom_profile->get_counter("SpillWriteTaskWaitInQueueCount");
-            _writing_task_count = _custom_profile->get_counter("SpillWriteTaskCount");
-            COUNTER_UPDATE(_write_wait_in_queue_task_count, 1);
-        }
-    }
-
-public:
-    virtual ~SpillRunnable() = default;
-
-    [[nodiscard]] Status run() {
-        SCOPED_TIMER(_spill_total_timer);
-
-        auto* spill_timer = _get_spill_timer();
-        DCHECK(spill_timer != nullptr);
-        SCOPED_TIMER(spill_timer);
-
-        _on_task_started();
-
-        Defer defer([&] {
-            {
-                std::function<Status()> tmp;
-                std::swap(tmp, _spill_exec_func);
-            }
-            {
-                std::function<Status()> tmp;
-                std::swap(tmp, _spill_fin_cb);
-            }
-        });
-
-        if (_state->is_cancelled()) {
-            return _state->cancel_reason();
-        }
-
-        RETURN_IF_ERROR(_spill_exec_func());
-        _on_task_finished();
-        if (_spill_fin_cb) {
-            return _spill_fin_cb();
-        }
-
-        return Status::OK();
-    }
-
-protected:
-    virtual void _on_task_finished() {
-        if (_spill_context) {
-            _spill_context->on_task_finished();
-        }
-    }
-
-    virtual RuntimeProfile::Counter* _get_spill_timer() {
-        return _custom_profile->get_counter("SpillWriteTime");
-    }
-
-    virtual void _on_task_started() {
-        VLOG_DEBUG << "Query: " << print_id(_state->query_id())
-                   << " spill task started, pipeline task id: " << _state->task_id();
-        if (_is_write_task) {
-            COUNTER_UPDATE(_write_wait_in_queue_task_count, -1);
-            COUNTER_UPDATE(_writing_task_count, 1);
-        }
-    }
-
-    RuntimeState* _state;
-    RuntimeProfile* _custom_profile;
-    std::shared_ptr<SpillContext> _spill_context;
-    bool _is_write_task;
-
-private:
-    RuntimeProfile::Counter* _spill_total_timer;
-
-    RuntimeProfile::Counter* _write_wait_in_queue_task_count = nullptr;
-    RuntimeProfile::Counter* _writing_task_count = nullptr;
-
-    std::function<Status()> _spill_exec_func;
-    std::function<Status()> _spill_fin_cb;
-};
-
-class SpillSinkRunnable : public SpillRunnable {
-public:
-    SpillSinkRunnable(RuntimeState* state, std::shared_ptr<SpillContext> spill_context,
-                      RuntimeProfile* operator_profile, std::function<Status()> spill_exec_func,
-                      std::function<Status()> spill_fin_cb = {})
-            : SpillRunnable(state, spill_context, operator_profile, true, spill_exec_func,
-                            spill_fin_cb) {}
-};
-
-class SpillNonSinkRunnable : public SpillRunnable {
-public:
-    SpillNonSinkRunnable(RuntimeState* state, RuntimeProfile* operator_profile,
-                         std::function<Status()> spill_exec_func,
-                         std::function<Status()> spill_fin_cb = {})
-            : SpillRunnable(state, nullptr, operator_profile, true, spill_exec_func, spill_fin_cb) {
-    }
-};
-
-class SpillRecoverRunnable : public SpillRunnable {
-public:
-    SpillRecoverRunnable(RuntimeState* state, RuntimeProfile* operator_profile,
-                         std::function<Status()> spill_exec_func,
-                         std::function<Status()> spill_fin_cb = {})
-            : SpillRunnable(state, nullptr, operator_profile, false, spill_exec_func,
-                            spill_fin_cb) {
-        RuntimeProfile* custom_profile = operator_profile->get_child("CustomCounters");
-        DCHECK(custom_profile != nullptr);
-        _spill_revover_timer = custom_profile->get_counter("SpillRecoverTime");
-        _read_wait_in_queue_task_count =
-                custom_profile->get_counter("SpillReadTaskWaitInQueueCount");
-        _reading_task_count = custom_profile->get_counter("SpillReadTaskCount");
-
-        COUNTER_UPDATE(_read_wait_in_queue_task_count, 1);
+// helper to execute a spill function synchronously.  The old code used
+// SpillRunnable/SpillSinkRunnable/SpillRecoverRunnable wrappers to track
+// counters and optionally notify a SpillContext.  Since spill operations are
+// now performed synchronously and external code already maintains any
+// necessary counters, those wrappers are no longer necessary.  We keep a
+// small utility to run the provided callbacks and forward cancellation.
+inline Status run_spill_task(RuntimeState* state, std::function<Status()> exec_func,
+                             std::function<Status()> fin_cb = {}) {
+    RETURN_IF_ERROR(exec_func());
+    if (fin_cb) {
+        RETURN_IF_ERROR(fin_cb());
     }
-
-protected:
-    RuntimeProfile::Counter* _get_spill_timer() override {
-        return _custom_profile->get_counter("SpillRecoverTime");
-    }
-
-    void _on_task_started() override {
-        VLOG_DEBUG << "SpillRecoverRunnable, Query: " << print_id(_state->query_id())
-                   << " spill task started, pipeline task id: " << _state->task_id();
-        COUNTER_UPDATE(_read_wait_in_queue_task_count, -1);
-        COUNTER_UPDATE(_reading_task_count, 1);
-    }
-
-private:
-    RuntimeProfile::Counter* _spill_revover_timer;
-    RuntimeProfile::Counter* _read_wait_in_queue_task_count = nullptr;
-    RuntimeProfile::Counter* _reading_task_count = nullptr;
-};
+    return Status::OK();
+}
 
 template <bool accumulating>
 inline void update_profile_from_inner_profile(const std::string& name,
@@ -240,4 +113,5 @@ inline void update_profile_from_inner_profile(const std::string& name,
 }
 
 #include "common/compile_check_end.h"
-} // namespace doris
\ No newline at end of file
+
+} // namespace doris
diff --git a/be/src/exec/partitioner/partitioner.cpp b/be/src/exec/partitioner/partitioner.cpp
index 39914d85d17..bd0c9ba7709 100644
--- a/be/src/exec/partitioner/partitioner.cpp
+++ b/be/src/exec/partitioner/partitioner.cpp
@@ -87,5 +87,6 @@ Status Crc32CHashPartitioner::clone(RuntimeState* state,
 
 template class Crc32HashPartitioner<ShuffleChannelIds>;
 template class Crc32HashPartitioner<SpillPartitionChannelIds>;
+template class Crc32HashPartitioner<SpillRePartitionChannelIds>;
 
 } // namespace doris
diff --git a/be/src/exec/partitioner/partitioner.h b/be/src/exec/partitioner/partitioner.h
index b6a4ab631fd..4eaed892cb8 100644
--- a/be/src/exec/partitioner/partitioner.h
+++ b/be/src/exec/partitioner/partitioner.h
@@ -114,9 +114,20 @@ struct ShuffleChannelIds {
 
 struct SpillPartitionChannelIds {
     using HashValType = PartitionerBase::HashValType;
+    // Default spill partition mapping used by level-0 partitioning:
+    // rotate hash bits and apply modulo to get a channel id directly.
     HashValType operator()(HashValType l, size_t r) { return ((l >> 16) | (l << 16)) % r; }
 };
 
+struct SpillRePartitionChannelIds {
+    using HashValType = PartitionerBase::HashValType;
+
+    // Repartition mode: return the raw hash value without modulo.
+    // The caller (SpillRepartitioner) will apply level-aware hash mixing and
+    // final channel mapping, so repartition behavior can vary by level.
+    HashValType operator()(HashValType l, size_t /*r*/) { return l; }
+};
+
 static inline PartitionerBase::HashValType crc32c_shuffle_mix(PartitionerBase::HashValType h) {
     // Step 1: fold high entropy into low bits
     h ^= h >> 16;
diff --git a/be/src/exec/pipeline/dependency.cpp b/be/src/exec/pipeline/dependency.cpp
index 6b10ffa9424..09239835073 100644
--- a/be/src/exec/pipeline/dependency.cpp
+++ b/be/src/exec/pipeline/dependency.cpp
@@ -21,19 +21,13 @@
 #include <mutex>
 
 #include "common/logging.h"
-#include "exec/common/util.hpp"
 #include "exec/operator/multi_cast_data_streamer.h"
 #include "exec/pipeline/pipeline_fragment_context.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/rowid_fetcher.h"
-#include "exec/runtime_filter/runtime_filter_consumer.h"
-#include "exec/scan/file_scanner.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
 #include "exprs/vectorized_agg_fn.h"
 #include "exprs/vslot_ref.h"
 #include "runtime/exec_env.h"
-#include "runtime/memory/mem_tracker.h"
-#include "util/brpc_client_cache.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -317,71 +311,13 @@ Status AggSharedState::reset_hash_table() {
             agg_data->method_variant);
 }
 
-void PartitionedAggSharedState::init_spill_params(size_t spill_partition_count) {
-    partition_count = spill_partition_count;
-    max_partition_index = partition_count - 1;
-
-    for (int i = 0; i < partition_count; ++i) {
-        spill_partitions.emplace_back(std::make_shared<AggSpillPartition>());
-    }
-}
-
-void PartitionedAggSharedState::update_spill_stream_profiles(RuntimeProfile* source_profile) {
-    for (auto& partition : spill_partitions) {
-        if (partition->spilling_stream_) {
-            partition->spilling_stream_->update_shared_profiles(source_profile);
-        }
-        for (auto& stream : partition->spill_streams_) {
-            if (stream) {
-                stream->update_shared_profiles(source_profile);
-            }
-        }
-    }
-}
-
-Status AggSpillPartition::get_spill_stream(RuntimeState* state, int node_id,
-                                           RuntimeProfile* profile, SpillStreamSPtr& spill_stream) {
-    if (spilling_stream_) {
-        spill_stream = spilling_stream_;
-        return Status::OK();
-    }
-    RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-            state, spilling_stream_, print_id(state->query_id()), "agg", node_id,
-            std::numeric_limits<int32_t>::max(), std::numeric_limits<size_t>::max(), profile));
-    spill_streams_.emplace_back(spilling_stream_);
-    spill_stream = spilling_stream_;
-    return Status::OK();
-}
-void AggSpillPartition::close() {
-    if (spilling_stream_) {
-        spilling_stream_.reset();
-    }
-    for (auto& stream : spill_streams_) {
-        (void)ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
-    }
-    spill_streams_.clear();
-}
-
 void PartitionedAggSharedState::close() {
-    // need to use CAS instead of only `if (!is_closed)` statement,
-    // to avoid concurrent entry of close() both pass the if statement
-    bool false_close = false;
-    if (!is_closed.compare_exchange_strong(false_close, true)) {
-        return;
-    }
-    DCHECK(!false_close && is_closed);
-    for (auto partition : spill_partitions) {
-        partition->close();
-    }
-    spill_partitions.clear();
-}
-
-void SpillSortSharedState::update_spill_stream_profiles(RuntimeProfile* source_profile) {
-    for (auto& stream : sorted_streams) {
-        if (stream) {
-            stream->update_shared_profiles(source_profile);
+    for (auto& partition : _spill_partitions) {
+        if (partition) {
+            ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(partition);
         }
     }
+    _spill_partitions.clear();
 }
 
 void SpillSortSharedState::close() {
@@ -392,18 +328,13 @@ void SpillSortSharedState::close() {
         return;
     }
     DCHECK(!false_close && is_closed);
-    for (auto& stream : sorted_streams) {
-        (void)ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
-    }
-    sorted_streams.clear();
+    sorted_spill_groups.clear();
 }
 
 MultiCastSharedState::MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id)
         : multi_cast_data_streamer(
                   std::make_unique<MultiCastDataStreamer>(pool, cast_sender_count, node_id)) {}
 
-void MultiCastSharedState::update_spill_stream_profiles(RuntimeProfile* source_profile) {}
-
 int AggSharedState::get_slot_column_id(const AggFnEvaluator* evaluator) {
     auto ctxs = evaluator->input_exprs_ctxs();
     CHECK(ctxs.size() == 1 && ctxs[0]->root()->is_slot_ref())
diff --git a/be/src/exec/pipeline/dependency.h b/be/src/exec/pipeline/dependency.h
index a13188fb791..28c89b5b990 100644
--- a/be/src/exec/pipeline/dependency.h
+++ b/be/src/exec/pipeline/dependency.h
@@ -44,7 +44,7 @@
 #include "exec/operator/join/process_hash_table_probe.h"
 #include "exec/sort/partition_sorter.h"
 #include "exec/sort/sorter.h"
-#include "exec/spill/spill_stream.h"
+#include "exec/spill/spill_file.h"
 #include "util/brpc_closure.h"
 #include "util/stack_util.h"
 
@@ -422,88 +422,23 @@ private:
     Status _destroy_agg_status(AggregateDataPtr data);
 };
 
-struct BasicSpillSharedState {
-    virtual ~BasicSpillSharedState() = default;
-
-    // These two counters are shared to spill source operators as the initial value
-    // of 'SpillWriteFileCurrentBytes' and 'SpillWriteFileCurrentCount'.
-    // Total bytes of spill data written to disk file(after serialized)
-    RuntimeProfile::Counter* _spill_write_file_total_size = nullptr;
-    RuntimeProfile::Counter* _spill_file_total_count = nullptr;
-
-    void setup_shared_profile(RuntimeProfile* sink_profile) {
-        _spill_file_total_count =
-                ADD_COUNTER_WITH_LEVEL(sink_profile, "SpillWriteFileTotalCount", TUnit::UNIT, 1);
-        _spill_write_file_total_size =
-                ADD_COUNTER_WITH_LEVEL(sink_profile, "SpillWriteFileBytes", TUnit::BYTES, 1);
-    }
-
-    virtual void update_spill_stream_profiles(RuntimeProfile* source_profile) = 0;
-};
-
-struct AggSpillPartition;
 struct PartitionedAggSharedState : public BasicSharedState,
-                                   public BasicSpillSharedState,
                                    public std::enable_shared_from_this<PartitionedAggSharedState> {
     ENABLE_FACTORY_CREATOR(PartitionedAggSharedState)
 
     PartitionedAggSharedState() = default;
     ~PartitionedAggSharedState() override = default;
 
-    void update_spill_stream_profiles(RuntimeProfile* source_profile) override;
-
-    void init_spill_params(size_t spill_partition_count);
-
     void close();
 
-    AggSharedState* in_mem_shared_state = nullptr;
-    std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr;
+    AggSharedState* _in_mem_shared_state = nullptr;
+    std::shared_ptr<BasicSharedState> _in_mem_shared_state_sptr;
 
-    size_t partition_count;
-    size_t max_partition_index;
-    bool is_spilled = false;
-    std::atomic_bool is_closed = false;
-    std::deque<std::shared_ptr<AggSpillPartition>> spill_partitions;
-
-    size_t get_partition_index(size_t hash_value) const { return hash_value % partition_count; }
+    // partition count is no longer stored in shared state; operators maintain their own
+    std::atomic<bool> _is_spilled = false;
+    std::deque<SpillFileSPtr> _spill_partitions;
 };
 
-struct AggSpillPartition {
-    static constexpr int64_t AGG_SPILL_FILE_SIZE = 1024 * 1024 * 1024; // 1G
-
-    AggSpillPartition() = default;
-
-    void close();
-
-    Status get_spill_stream(RuntimeState* state, int node_id, RuntimeProfile* profile,
-                            SpillStreamSPtr& spilling_stream);
-
-    Status flush_if_full() {
-        DCHECK(spilling_stream_);
-        Status status;
-        // avoid small spill files
-        if (spilling_stream_->get_written_bytes() >= AGG_SPILL_FILE_SIZE) {
-            status = spilling_stream_->spill_eof();
-            spilling_stream_.reset();
-        }
-        return status;
-    }
-
-    Status finish_current_spilling(bool eos = false) {
-        if (spilling_stream_) {
-            if (eos || spilling_stream_->get_written_bytes() >= AGG_SPILL_FILE_SIZE) {
-                auto status = spilling_stream_->spill_eof();
-                spilling_stream_.reset();
-                return status;
-            }
-        }
-        return Status::OK();
-    }
-
-    std::deque<SpillStreamSPtr> spill_streams_;
-    SpillStreamSPtr spilling_stream_;
-};
-using AggSpillPartitionSPtr = std::shared_ptr<AggSpillPartition>;
 struct SortSharedState : public BasicSharedState {
     ENABLE_FACTORY_CREATOR(SortSharedState)
 public:
@@ -511,7 +446,6 @@ public:
 };
 
 struct SpillSortSharedState : public BasicSharedState,
-                              public BasicSpillSharedState,
                               public std::enable_shared_from_this<SpillSortSharedState> {
     ENABLE_FACTORY_CREATOR(SpillSortSharedState)
 
@@ -523,13 +457,11 @@ struct SpillSortSharedState : public BasicSharedState,
         if (rows > 0 && 0 == avg_row_bytes) {
             avg_row_bytes = std::max((std::size_t)1, block->bytes() / rows);
             spill_block_batch_row_count =
-                    (state->spill_sort_batch_bytes() + avg_row_bytes - 1) / avg_row_bytes;
+                    (state->spill_buffer_size_bytes() + avg_row_bytes - 1) / avg_row_bytes;
             LOG(INFO) << "spill sort block batch row count: " << spill_block_batch_row_count;
         }
     }
 
-    void update_spill_stream_profiles(RuntimeProfile* source_profile) override;
-
     void close();
 
     SortSharedState* in_mem_shared_state = nullptr;
@@ -540,7 +472,7 @@ struct SpillSortSharedState : public BasicSharedState,
     std::atomic_bool is_closed = false;
     std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr;
 
-    std::deque<SpillStreamSPtr> sorted_streams;
+    std::deque<SpillFileSPtr> sorted_spill_groups;
     size_t avg_row_bytes = 0;
     size_t spill_block_batch_row_count;
 };
@@ -564,12 +496,10 @@ public:
 class MultiCastDataStreamer;
 
 struct MultiCastSharedState : public BasicSharedState,
-                              public BasicSpillSharedState,
                               public std::enable_shared_from_this<MultiCastSharedState> {
     MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id);
-    std::unique_ptr<MultiCastDataStreamer> multi_cast_data_streamer;
 
-    void update_spill_stream_profiles(RuntimeProfile* source_profile) override;
+    std::unique_ptr<MultiCastDataStreamer> multi_cast_data_streamer;
 };
 
 struct AnalyticSharedState : public BasicSharedState {
@@ -645,23 +575,14 @@ struct HashJoinSharedState : public JoinSharedState {
 
 struct PartitionedHashJoinSharedState
         : public HashJoinSharedState,
-          public BasicSpillSharedState,
           public std::enable_shared_from_this<PartitionedHashJoinSharedState> {
     ENABLE_FACTORY_CREATOR(PartitionedHashJoinSharedState)
 
-    void update_spill_stream_profiles(RuntimeProfile* source_profile) override {
-        for (auto& stream : spilled_streams) {
-            if (stream) {
-                stream->update_shared_profiles(source_profile);
-            }
-        }
-    }
-
-    std::unique_ptr<RuntimeState> inner_runtime_state;
-    std::shared_ptr<HashJoinSharedState> inner_shared_state;
-    std::vector<std::unique_ptr<MutableBlock>> partitioned_build_blocks;
-    std::vector<SpillStreamSPtr> spilled_streams;
-    bool is_spilled = false;
+    std::unique_ptr<RuntimeState> _inner_runtime_state;
+    std::shared_ptr<HashJoinSharedState> _inner_shared_state;
+    std::vector<std::unique_ptr<MutableBlock>> _partitioned_build_blocks;
+    std::vector<SpillFileSPtr> _spilled_build_groups;
+    std::atomic<bool> _is_spilled = false;
 };
 
 struct NestedLoopJoinSharedState : public JoinSharedState {
diff --git a/be/src/exec/pipeline/pipeline_fragment_context.cpp b/be/src/exec/pipeline/pipeline_fragment_context.cpp
index fc3d83c229d..3e3b0fe0778 100644
--- a/be/src/exec/pipeline/pipeline_fragment_context.cpp
+++ b/be/src/exec/pipeline/pipeline_fragment_context.cpp
@@ -108,7 +108,7 @@
 #include "exec/pipeline/task_scheduler.h"
 #include "exec/runtime_filter/runtime_filter_mgr.h"
 #include "exec/sort/topn_sorter.h"
-#include "exec/spill/spill_stream.h"
+#include "exec/spill/spill_file.h"
 #include "io/fs/stream_load_pipe.h"
 #include "load/stream_load/new_load_stream_mgr.h"
 #include "runtime/exec_env.h"
@@ -602,9 +602,9 @@ void PipelineFragmentContext::trigger_report_if_necessary() {
     }
     int32_t interval_s = config::pipeline_status_report_interval;
     if (interval_s <= 0) {
-        LOG(WARNING)
-                << "config::status_report_interval is equal to or less than zero, do not trigger "
-                   "report.";
+        LOG(WARNING) << "config::status_report_interval is equal to or less than zero, do not "
+                        "trigger "
+                        "report.";
     }
     uint64_t next_report_time = _previous_report_time.load(std::memory_order_acquire) +
                                 (uint64_t)(interval_s)*NANOS_PER_SEC;
@@ -731,7 +731,8 @@ Status PipelineFragmentContext::_create_tree_helper(
         // this means we have been given a bad tree and must fail
         if (*node_idx >= tnodes.size()) {
             return Status::InternalError(
-                    "Failed to reconstruct plan tree from thrift. Node id: {}, number of nodes: {}",
+                    "Failed to reconstruct plan tree from thrift. Node id: {}, number of "
+                    "nodes: {}",
                     *node_idx, tnodes.size());
         }
     }
@@ -1345,8 +1346,9 @@ Status PipelineFragmentContext::_create_operator(ObjectPool* pool, const TPlanNo
         const bool is_streaming_agg = tnode.agg_node.__isset.use_streaming_preaggregation &&
                                       tnode.agg_node.use_streaming_preaggregation &&
                                       !tnode.agg_node.grouping_exprs.empty();
+        // TODO: distinct streaming agg does not support spill.
         const bool can_use_distinct_streaming_agg =
-                tnode.agg_node.aggregate_functions.empty() &&
+                (!enable_spill || is_streaming_agg) && tnode.agg_node.aggregate_functions.empty() &&
                 !tnode.agg_node.__isset.agg_sort_info_by_group_key &&
                 _params.query_options.__isset.enable_distinct_streaming_aggregation &&
                 _params.query_options.enable_distinct_streaming_aggregation;
@@ -1428,7 +1430,6 @@ Status PipelineFragmentContext::_create_operator(ObjectPool* pool, const TPlanNo
         if (enable_spill && !is_broadcast_join) {
             auto tnode_ = tnode;
             tnode_.runtime_filters.clear();
-            uint32_t partition_count = _runtime_state->spill_hash_join_partition_count();
             auto inner_probe_operator =
                     std::make_shared<HashJoinProbeOperatorX>(pool, tnode_, 0, descs);
 
@@ -1441,7 +1442,7 @@ Status PipelineFragmentContext::_create_operator(ObjectPool* pool, const TPlanNo
             RETURN_IF_ERROR(probe_side_inner_sink_operator->init(tnode_, _runtime_state.get()));
 
             auto probe_operator = std::make_shared<PartitionedHashJoinProbeOperatorX>(
-                    pool, tnode_, next_operator_id(), descs, partition_count);
+                    pool, tnode_, next_operator_id(), descs);
             probe_operator->set_inner_operators(probe_side_inner_sink_operator,
                                                 inner_probe_operator);
             op = std::move(probe_operator);
@@ -1457,8 +1458,7 @@ Status PipelineFragmentContext::_create_operator(ObjectPool* pool, const TPlanNo
             auto inner_sink_operator =
                     std::make_shared<HashJoinBuildSinkOperatorX>(pool, 0, 0, tnode, descs);
             auto sink_operator = std::make_shared<PartitionedHashJoinSinkOperatorX>(
-                    pool, next_sink_operator_id(), op->operator_id(), tnode_, descs,
-                    partition_count);
+                    pool, next_sink_operator_id(), op->operator_id(), tnode_, descs);
             RETURN_IF_ERROR(inner_sink_operator->init(tnode, _runtime_state.get()));
 
             sink_operator->set_inner_operators(inner_sink_operator, inner_probe_operator);
@@ -1921,7 +1921,7 @@ size_t PipelineFragmentContext::get_revocable_size(bool* has_running_task) const
             }
 
             size_t revocable_size = task.first->get_revocable_size();
-            if (revocable_size >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
+            if (revocable_size >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
                 res += revocable_size;
             }
         }
@@ -1934,7 +1934,8 @@ std::vector<PipelineTask*> PipelineFragmentContext::get_revocable_tasks() const
     for (const auto& task_instances : _tasks) {
         for (const auto& task : task_instances) {
             size_t revocable_size_ = task.first->get_revocable_size();
-            if (revocable_size_ >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
+
+            if (revocable_size_ >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
                 revocable_tasks.emplace_back(task.first.get());
             }
         }
diff --git a/be/src/exec/pipeline/pipeline_task.cpp b/be/src/exec/pipeline/pipeline_task.cpp
index 6bcfd9b3c5c..29823545d30 100644
--- a/be/src/exec/pipeline/pipeline_task.cpp
+++ b/be/src/exec/pipeline/pipeline_task.cpp
@@ -39,7 +39,7 @@
 #include "exec/pipeline/revokable_task.h"
 #include "exec/pipeline/task_queue.h"
 #include "exec/pipeline/task_scheduler.h"
-#include "exec/spill/spill_stream.h"
+#include "exec/spill/spill_file.h"
 #include "runtime/descriptors.h"
 #include "runtime/exec_env.h"
 #include "runtime/query_context.h"
@@ -369,6 +369,70 @@ void PipelineTask::terminate() {
     }
 }
 
+// When current memory pressure is low, memory usage may increase significantly in the next
+// operator run, while there is no revocable memory available for spilling.
+// Trigger memory revoking when pressure is high and revocable memory is significant.
+// Memory pressure is evaluated using two signals:
+// 1. Query memory usage exceeds a threshold ratio of the query memory limit.
+// 2. Workload group memory usage reaches the workload group low-watermark threshold.
+bool PipelineTask::_should_trigger_revoking(const size_t reserve_size) const {
+    if (!_state->enable_spill()) {
+        return false;
+    }
+
+    auto query_mem_tracker = _state->get_query_ctx()->query_mem_tracker();
+    auto wg = _state->get_query_ctx()->workload_group();
+    if (!query_mem_tracker || !wg) {
+        return false;
+    }
+
+    const auto parallelism = std::max(1, _pipeline->num_tasks());
+    const auto query_water_mark = 90; // 90%
+    const auto group_mem_limit = wg->memory_limit();
+    auto query_limit = query_mem_tracker->limit();
+    if (query_limit <= 0) {
+        query_limit = group_mem_limit;
+    } else if (query_limit > group_mem_limit && group_mem_limit > 0) {
+        query_limit = group_mem_limit;
+    }
+
+    if (query_limit <= 0) {
+        return false;
+    }
+
+    if ((reserve_size * parallelism) <= (query_limit / 5)) {
+        return false;
+    }
+
+    bool is_high_memory_pressure = false;
+    const auto used_mem = query_mem_tracker->consumption() + reserve_size * parallelism;
+    if (used_mem >= int64_t((double(query_limit) * query_water_mark / 100))) {
+        is_high_memory_pressure = true;
+    }
+
+    if (!is_high_memory_pressure) {
+        bool is_low_watermark;
+        bool is_high_watermark;
+        wg->check_mem_used(&is_low_watermark, &is_high_watermark);
+        is_high_memory_pressure = is_low_watermark || is_high_watermark;
+    }
+
+    if (is_high_memory_pressure) {
+        const auto revocable_size = [&]() {
+            size_t total = _sink->revocable_mem_size(_state);
+            for (const auto& op : _operators) {
+                total += op->revocable_mem_size(_state);
+            }
+            return total;
+        }();
+
+        const auto total_estimated_revocable = revocable_size * parallelism;
+        return total_estimated_revocable >= int64_t(double(query_limit) * 0.2);
+    }
+
+    return false;
+}
+
 /**
  * `_eos` indicates whether the execution phase is done. `done` indicates whether we could close
  * this task.
@@ -516,19 +580,39 @@ Status PipelineTask::execute(bool* done) {
             SCOPED_TIMER(_get_block_timer);
             if (_state->low_memory_mode()) {
                 _sink->set_low_memory_mode(_state);
-                _root->set_low_memory_mode(_state);
+                for (auto& op : _operators) {
+                    op->set_low_memory_mode(_state);
+                }
             }
             DEFER_RELEASE_RESERVED();
             _get_block_counter->update(1);
-            const auto reserve_size = _root->get_reserve_mem_size(_state);
-            _root->reset_reserve_mem_size(_state);
-
+            // Sum reserve sizes across all operators in this pipeline.
+            // Each operator reports only its own requirement (non-recursive).
+            size_t reserve_size = 0;
+            for (auto& op : _operators) {
+                reserve_size += op->get_reserve_mem_size(_state);
+                op->reset_reserve_mem_size(_state);
+            }
             if (workload_group &&
                 _state->get_query_ctx()
                         ->resource_ctx()
                         ->task_controller()
                         ->is_enable_reserve_memory() &&
                 reserve_size > 0) {
+                if (_should_trigger_revoking(reserve_size)) {
+                    LOG(INFO) << fmt::format(
+                            "Query: {} sink: {}, node id: {}, task id: {}, reserve size: {} when "
+                            "high memory pressure, try to spill",
+                            print_id(_query_id), _sink->get_name(), _sink->node_id(),
+                            _state->task_id(), reserve_size);
+                    ExecEnv::GetInstance()->workload_group_mgr()->add_paused_query(
+                            _state->get_query_ctx()->resource_ctx()->shared_from_this(),
+                            reserve_size,
+                            Status::Error<ErrorCode::QUERY_MEMORY_EXCEEDED>(
+                                    "high memory pressure, try to spill"));
+                    _spilling = true;
+                    continue;
+                }
                 if (!_try_to_reserve_memory(reserve_size, _root)) {
                     continue;
                 }
@@ -550,6 +634,22 @@ Status PipelineTask::execute(bool* done) {
                         ->is_enable_reserve_memory() &&
                 workload_group && !(_wake_up_early || _dry_run)) {
                 const auto sink_reserve_size = _sink->get_reserve_mem_size(_state, _eos);
+
+                if (sink_reserve_size > 0 && _should_trigger_revoking(sink_reserve_size)) {
+                    LOG(INFO) << fmt::format(
+                            "Query: {} sink: {}, node id: {}, task id: {}, reserve size: {} when "
+                            "high memory pressure, try to spill",
+                            print_id(_query_id), _sink->get_name(), _sink->node_id(),
+                            _state->task_id(), sink_reserve_size);
+                    ExecEnv::GetInstance()->workload_group_mgr()->add_paused_query(
+                            _state->get_query_ctx()->resource_ctx()->shared_from_this(),
+                            sink_reserve_size,
+                            Status::Error<ErrorCode::QUERY_MEMORY_EXCEEDED>(
+                                    "high memory pressure, try to spill"));
+                    _spilling = true;
+                    continue;
+                }
+
                 if (sink_reserve_size > 0 &&
                     !_try_to_reserve_memory(sink_reserve_size, _sink.get())) {
                     continue;
@@ -637,9 +737,26 @@ Status PipelineTask::do_revoke_memory(const std::shared_ptr<SpillContext>& spill
             THROW_IF_ERROR(_sink->terminate(_state));
             _eos = true;
         }
+
+        // SpillContext tracks pipeline task count, not operator count.
+        // Notify completion once after all operators + sink have finished revoking.
+        if (spill_context) {
+            spill_context->on_task_finished();
+        }
     }};
 
-    return _sink->revoke_memory(_state, spill_context);
+    // Revoke memory from every operator that has enough revocable memory,
+    // then revoke from the sink.
+    for (auto& op : _operators) {
+        if (op->revocable_mem_size(_state) >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
+            RETURN_IF_ERROR(op->revoke_memory(_state));
+        }
+    }
+
+    if (_sink->revocable_mem_size(_state) >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
+        RETURN_IF_ERROR(_sink->revoke_memory(_state));
+    }
+    return Status::OK();
 }
 
 bool PipelineTask::_try_to_reserve_memory(const size_t reserve_size, OperatorBase* op) {
@@ -653,58 +770,68 @@ bool PipelineTask::_try_to_reserve_memory(const size_t reserve_size, OperatorBas
         return true;
     }
     COUNTER_UPDATE(_memory_reserve_times, 1);
-    auto sink_revocable_mem_size = _sink->revocable_mem_size(_state);
-    if (st.ok() && _state->enable_force_spill() && _sink->is_spillable() &&
-        sink_revocable_mem_size >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
-        st = Status(ErrorCode::QUERY_MEMORY_EXCEEDED, "Force Spill");
+
+    // Compute total revocable memory across all operators and the sink.
+    size_t total_revocable_mem_size = 0;
+    size_t operator_max_revocable_mem_size = 0;
+
+    if (!st.ok() || _state->enable_force_spill()) {
+        // Compute total revocable memory across all operators and the sink.
+        total_revocable_mem_size = _sink->revocable_mem_size(_state);
+        operator_max_revocable_mem_size = total_revocable_mem_size;
+        for (auto& cur_op : _operators) {
+            total_revocable_mem_size += cur_op->revocable_mem_size(_state);
+            operator_max_revocable_mem_size =
+                    std::max(cur_op->revocable_mem_size(_state), operator_max_revocable_mem_size);
+        }
     }
+
+    // During enable force spill, other operators like scan opeartor will also try to reserve memory and will failed
+    // here, if not add this check, it will always paused and resumed again.
+    if (st.ok() && _state->enable_force_spill()) {
+        if (operator_max_revocable_mem_size >= _state->spill_min_revocable_mem()) {
+            st = Status::Error<ErrorCode::QUERY_MEMORY_EXCEEDED>(
+                    "force spill and there is an operator has memory "
+                    "size {} exceeds min mem size {}",
+                    PrettyPrinter::print_bytes(operator_max_revocable_mem_size),
+                    PrettyPrinter::print_bytes(_state->spill_min_revocable_mem()));
+        }
+    }
+
     if (!st.ok()) {
         COUNTER_UPDATE(_memory_reserve_failed_times, 1);
+        // build per-operator revocable memory info string for debugging
+        std::string ops_revocable_info;
+        {
+            fmt::memory_buffer buf;
+            for (auto& cur_op : _operators) {
+                fmt::format_to(buf, "{}({})-> ", cur_op->get_name(),
+                               PrettyPrinter::print_bytes(cur_op->revocable_mem_size(_state)));
+            }
+            if (_sink) {
+                fmt::format_to(buf, "{}({}) ", _sink->get_name(),
+                               PrettyPrinter::print_bytes(_sink->revocable_mem_size(_state)));
+            }
+            ops_revocable_info = fmt::to_string(buf);
+        }
+
         auto debug_msg = fmt::format(
-                "Query: {} , try to reserve: {}, operator name: {}, operator "
-                "id: {}, task id: {}, root revocable mem size: {}, sink revocable mem"
-                "size: {}, failed: {}",
-                print_id(_query_id), PrettyPrinter::print_bytes(reserve_size), op->get_name(),
-                op->node_id(), _state->task_id(),
-                PrettyPrinter::print_bytes(op->revocable_mem_size(_state)),
-                PrettyPrinter::print_bytes(sink_revocable_mem_size), st.to_string());
+                "Query: {} , try to reserve: {}, total revocable mem size: {}, failed reason: {}",
+                print_id(_query_id), PrettyPrinter::print_bytes(reserve_size),
+                PrettyPrinter::print_bytes(total_revocable_mem_size), st.to_string());
+        if (!ops_revocable_info.empty()) {
+            debug_msg += fmt::format(", ops_revocable=[{}]", ops_revocable_info);
+        }
         // PROCESS_MEMORY_EXCEEDED error msg already contains process_mem_log_str
         if (!st.is<ErrorCode::PROCESS_MEMORY_EXCEEDED>()) {
             debug_msg +=
                     fmt::format(", debug info: {}", GlobalMemoryArbitrator::process_mem_log_str());
         }
-        // If sink has enough revocable memory, trigger revoke memory
-        LOG(INFO) << fmt::format(
-                "Query: {} sink: {}, node id: {}, task id: "
-                "{}, revocable mem size: {}",
-                print_id(_query_id), _sink->get_name(), _sink->node_id(), _state->task_id(),
-                PrettyPrinter::print_bytes(sink_revocable_mem_size));
+        LOG(INFO) << debug_msg;
         ExecEnv::GetInstance()->workload_group_mgr()->add_paused_query(
                 _state->get_query_ctx()->resource_ctx()->shared_from_this(), reserve_size, st);
         _spilling = true;
         return false;
-        // !!! Attention:
-        // In the past, if reserve failed, not add this query to paused list, because it is very small, will not
-        // consume a lot of memory. But need set low memory mode to indicate that the system should
-        // not use too much memory.
-        // But if we only set _state->get_query_ctx()->set_low_memory_mode() here, and return true, the query will
-        // continue to run and not blocked, and this reserve maybe the last block of join sink opertorator, and it will
-        // build hash table directly and will consume a lot of memory. So that should return false directly.
-        // TODO: we should using a global system buffer management logic to deal with low memory mode.
-        /**
-        if (sink_revocable_mem_size >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
-            LOG(INFO) << fmt::format(
-                    "Query: {} sink: {}, node id: {}, task id: "
-                    "{}, revocable mem size: {}",
-                    print_id(_query_id), _sink->get_name(), _sink->node_id(), _state->task_id(),
-                    PrettyPrinter::print_bytes(sink_revocable_mem_size));
-            ExecEnv::GetInstance()->workload_group_mgr()->add_paused_query(
-                    _state->get_query_ctx()->resource_ctx()->shared_from_this(), reserve_size, st);
-            _spilling = true;
-            return false;
-        } else {
-            _state->get_query_ctx()->set_low_memory_mode();
-        } */
     }
     return true;
 }
@@ -852,7 +979,13 @@ size_t PipelineTask::get_revocable_size() const {
         return 0;
     }
 
-    return _sink->revocable_mem_size(_state);
+    // Sum revocable memory from every operator in the pipeline + the sink.
+    // Each operator reports only its own revocable memory (no child recursion).
+    size_t total = _sink->revocable_mem_size(_state);
+    for (const auto& op : _operators) {
+        total += op->revocable_mem_size(_state);
+    }
+    return total;
 }
 
 Status PipelineTask::revoke_memory(const std::shared_ptr<SpillContext>& spill_context) {
@@ -864,14 +997,16 @@ Status PipelineTask::revoke_memory(const std::shared_ptr<SpillContext>& spill_co
         return Status::OK();
     }
 
-    const auto revocable_size = _sink->revocable_mem_size(_state);
-    if (revocable_size >= SpillStream::MIN_SPILL_WRITE_BATCH_MEM) {
+    const auto revocable_size = get_revocable_size();
+    if (revocable_size >= SpillFile::MIN_SPILL_WRITE_BATCH_MEM) {
         auto revokable_task = std::make_shared<RevokableTask>(shared_from_this(), spill_context);
+        // Submit a revocable task to run, the run method will call revoke memory. Currently the
+        // underline pipeline task is still blocked.
         RETURN_IF_ERROR(_state->get_query_ctx()->get_pipe_exec_scheduler()->submit(revokable_task));
     } else {
         spill_context->on_task_finished();
-        LOG(INFO) << "Query: " << print_id(_state->query_id()) << ", task: " << ((void*)this)
-                  << " has not enough data to revoke: " << revocable_size;
+        VLOG_DEBUG << "Query: " << print_id(_state->query_id()) << ", task: " << ((void*)this)
+                   << " has not enough data to revoke: " << revocable_size;
     }
     return Status::OK();
 }
diff --git a/be/src/exec/pipeline/pipeline_task.h b/be/src/exec/pipeline/pipeline_task.h
index cb89673b2c0..e6fed38a5db 100644
--- a/be/src/exec/pipeline/pipeline_task.h
+++ b/be/src/exec/pipeline/pipeline_task.h
@@ -199,6 +199,7 @@ private:
     // Operator `op` try to reserve memory before executing. Return false if reserve failed
     // otherwise return true.
     bool _try_to_reserve_memory(const size_t reserve_size, OperatorBase* op);
+    bool _should_trigger_revoking(const size_t reserve_size) const;
 
     const TUniqueId _query_id;
     const uint32_t _index;
diff --git a/be/src/exec/pipeline/revokable_task.h b/be/src/exec/pipeline/revokable_task.h
index c2cc728f49b..d3bf7c5d0dc 100644
--- a/be/src/exec/pipeline/revokable_task.h
+++ b/be/src/exec/pipeline/revokable_task.h
@@ -63,6 +63,7 @@ public:
 
     Status execute(bool* done) override { return _task->do_revoke_memory(_spill_context); }
 
+    // Use blockable to make sure the task will be submiited to the blockable task queue and can be revoked when necessary.
     bool is_blockable() const override { return true; }
 
 private:
diff --git a/be/src/exec/scan/split_source_connector.h b/be/src/exec/scan/split_source_connector.h
index 5e61c16b9bc..9381e5564c2 100644
--- a/be/src/exec/scan/split_source_connector.h
+++ b/be/src/exec/scan/split_source_connector.h
@@ -18,6 +18,7 @@
 #pragma once
 
 #include "common/config.h"
+#include "core/custom_allocator.h"
 #include "runtime/runtime_state.h"
 #include "util/client_cache.h"
 
@@ -46,10 +47,14 @@ public:
     virtual TFileScanRangeParams* get_params() = 0;
 
 protected:
-    template <typename T>
-    void _merge_ranges(std::vector<T>& merged_ranges, const std::vector<T>& scan_ranges) {
+    template <typename T, typename V1 = std::vector<T>, typename V2 = std::vector<T>>
+        requires(std::is_same_v<std::remove_cvref_t<V1>,
+                                std::vector<T, typename V1::allocator_type>> &&
+                 std::is_same_v<std::remove_cvref_t<V2>,
+                                std::vector<T, typename V2::allocator_type>>)
+    void _merge_ranges(V1& merged_ranges, const V2& scan_ranges) {
         if (scan_ranges.size() <= _max_scanners) {
-            merged_ranges = scan_ranges;
+            merged_ranges.assign(scan_ranges.begin(), scan_ranges.end());
             return;
         }
 
@@ -98,7 +103,7 @@ protected:
 class LocalSplitSourceConnector : public SplitSourceConnector {
 private:
     std::mutex _range_lock;
-    std::vector<TScanRangeParams> _scan_ranges;
+    DorisVector<TScanRangeParams> _scan_ranges;
     int _scan_index = 0;
     int _range_index = 0;
 
@@ -138,7 +143,7 @@ private:
     int64_t _split_source_id;
     int _num_splits;
 
-    std::vector<TScanRangeLocations> _scan_ranges;
+    DorisVector<TScanRangeLocations> _scan_ranges;
     bool _last_batch = false;
     int _scan_index = 0;
     int _range_index = 0;
diff --git a/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.cpp b/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.cpp
index 5be94279a3a..dc1038e5191 100644
--- a/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.cpp
+++ b/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.cpp
@@ -17,8 +17,9 @@
 
 #include "exec/sink/writer/iceberg/viceberg_sort_writer.h"
 
-#include "exec/spill/spill_stream.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
 #include "runtime/exec_env.h"
 #include "runtime/runtime_state.h"
 
@@ -110,7 +111,7 @@ Status VIcebergSortWriter::close(const Status& status) {
     // Check if there is any remaining data in the sorter (either unsorted or already sorted blocks)
     if (!_sorter->merge_sort_state()->unsorted_block()->empty() ||
         !_sorter->merge_sort_state()->get_sorted_block().empty()) {
-        if (_sorted_streams.empty()) {
+        if (_sorted_spill_files.empty()) {
             // No spill has occurred, all data is in memory.
             // Sort the remaining data, prepare for reading, and write to file.
             internal_status = _sorter->do_sort();
@@ -134,7 +135,7 @@ Status VIcebergSortWriter::close(const Status& status) {
     }
 
     // Merge all spilled streams using multi-way merge sort and output final sorted data to files
-    if (!_sorted_streams.empty()) {
+    if (!_sorted_spill_files.empty()) {
         internal_status = _combine_files_output();
         if (!internal_status.ok()) {
             return internal_status;
@@ -154,7 +155,7 @@ void VIcebergSortWriter::_update_spill_block_batch_row_count(const Block& block)
     // the optimal batch size for spill operations
     if (rows > 0 && 0 == _avg_row_bytes) {
         _avg_row_bytes = std::max(1UL, block.bytes() / rows);
-        int64_t spill_batch_bytes = _runtime_state->spill_sort_batch_bytes(); // default 8MB
+        int64_t spill_batch_bytes = _runtime_state->spill_buffer_size_bytes(); // default 8MB
         // Calculate how many rows fit in one spill batch (ceiling division)
         _spill_block_batch_row_count = (spill_batch_bytes + _avg_row_bytes - 1) / _avg_row_bytes;
     }
@@ -225,14 +226,18 @@ Status VIcebergSortWriter::_do_spill() {
     // prepare_for_read(is_spill=true) adjusts limit/offset for spill mode
     // and builds the merge tree for reading sorted data
     RETURN_IF_ERROR(_sorter->prepare_for_read(true));
-    int32_t batch_size = _get_spill_batch_size();
 
-    // Register a new spill stream to store the sorted data on disk
-    SpillStreamSPtr spilling_stream;
-    RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-            _runtime_state, spilling_stream, print_id(_runtime_state->query_id()), "iceberg-sort",
-            1 /* node_id */, batch_size, _runtime_state->spill_sort_batch_bytes(), _profile));
-    _sorted_streams.emplace_back(spilling_stream);
+    // Register a new spill file to store the sorted data on disk
+    SpillFileSPtr spilling_file;
+    auto relative_path = fmt::format("{}/{}-{}-{}-{}", print_id(_runtime_state->query_id()),
+                                     "MultiCastSender", 1 /* node_id */, _runtime_state->task_id(),
+                                     ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+    RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(relative_path,
+                                                                                spilling_file));
+    _sorted_spill_files.emplace_back(spilling_file);
+
+    SpillFileWriterSPtr writer;
+    RETURN_IF_ERROR(spilling_file->create_writer(_runtime_state, _profile, writer));
 
     // Read sorted data from the sorter in batches and write to the spill stream
     bool eos = false;
@@ -242,7 +247,7 @@ Status VIcebergSortWriter::_do_spill() {
         // instead of C-style cast, which includes bounds checking
         RETURN_IF_ERROR(_sorter->merge_sort_read_for_spill(_runtime_state, &block,
                                                            _get_spill_batch_size(), &eos));
-        RETURN_IF_ERROR(spilling_stream->spill_block(_runtime_state, block, eos));
+        RETURN_IF_ERROR(writer->write_block(_runtime_state, block));
         block.clear_column_data();
     }
     // Reset the sorter to free memory and accept new data
@@ -251,13 +256,13 @@ Status VIcebergSortWriter::_do_spill() {
 }
 
 Status VIcebergSortWriter::_combine_files_output() {
-    // If there are too many spill streams to merge at once (limited by memory),
-    // perform intermediate merges to reduce the number of streams
-    while (_sorted_streams.size() > static_cast<size_t>(_calc_max_merge_streams())) {
+    // If there are too many spill files to merge at once (limited by memory),
+    // perform intermediate merges to reduce the number of files
+    while (_sorted_spill_files.size() > static_cast<size_t>(_calc_max_merge_streams())) {
         RETURN_IF_ERROR(_do_intermediate_merge());
     }
 
-    // Create the final merger that combines all remaining spill streams
+    // Create the final merger that combines all remaining spill files
     RETURN_IF_ERROR(_create_final_merger());
 
     // Read merged sorted data and write to Parquet/ORC files,
@@ -287,36 +292,41 @@ Status VIcebergSortWriter::_do_intermediate_merge() {
     // Merge a subset of streams (non-final merge) to reduce total stream count
     RETURN_IF_ERROR(_create_merger(false, _spill_block_batch_row_count, max_stream_count));
 
-    // Register a new spill stream for the merged output
-    int32_t batch_size = _get_spill_batch_size();
-    SpillStreamSPtr tmp_stream;
-    RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
-            _runtime_state, tmp_stream, print_id(_runtime_state->query_id()), "iceberg-sort-merge",
-            1 /* node_id */, batch_size, _runtime_state->spill_sort_batch_bytes(), _profile));
+    // register new spill stream for merged output
+    SpillFileSPtr tmp_spill_file;
+    auto relative_path = fmt::format("{}/{}-{}-{}-{}", print_id(_runtime_state->query_id()),
+                                     "MultiCastSender", 1 /* node_id */, _runtime_state->task_id(),
+                                     ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+    RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(relative_path,
+                                                                                tmp_spill_file));
+
+    _sorted_spill_files.emplace_back(tmp_spill_file);
 
-    _sorted_streams.emplace_back(tmp_stream);
+    SpillFileWriterSPtr tmp_spill_writer;
+    RETURN_IF_ERROR(tmp_spill_file->create_writer(_runtime_state, _profile, tmp_spill_writer));
 
-    // Merge the selected streams and write the result to the new spill stream
+    // Merge the selected files and write the result to the new spill file
     bool eos = false;
     Block merge_sorted_block;
     while (!eos && !_runtime_state->is_cancelled()) {
         merge_sorted_block.clear_column_data();
         RETURN_IF_ERROR(_merger->get_next(&merge_sorted_block, &eos));
-        RETURN_IF_ERROR(tmp_stream->spill_block(_runtime_state, merge_sorted_block, eos));
+        RETURN_IF_ERROR(tmp_spill_writer->write_block(_runtime_state, merge_sorted_block));
     }
 
-    // Clean up the streams that were consumed during this intermediate merge
-    for (auto& stream : _current_merging_streams) {
-        ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
+    // Clean up the files that were consumed during this intermediate merge
+    for (auto& file : _current_merging_spill_files) {
+        ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(file);
     }
-    _current_merging_streams.clear();
+    _current_merging_spill_files.clear();
     return Status::OK();
 }
 
 int VIcebergSortWriter::_calc_max_merge_streams() const {
     // Calculate the maximum number of streams that can be merged simultaneously
     // based on the available memory limit and per-stream batch size
-    auto count = _runtime_state->spill_sort_mem_limit() / _runtime_state->spill_sort_batch_bytes();
+    auto count = _runtime_state->spill_sort_merge_mem_limit_bytes() /
+                 _runtime_state->spill_buffer_size_bytes();
     if (count > std::numeric_limits<int>::max()) {
         return std::numeric_limits<int>::max();
     }
@@ -329,21 +339,19 @@ Status VIcebergSortWriter::_create_merger(bool is_final_merge, size_t batch_size
     std::vector<BlockSupplier> child_block_suppliers;
     _merger = std::make_unique<VSortedRunMerger>(_sorter->get_sort_description(), batch_size, -1, 0,
                                                  _profile);
-    _current_merging_streams.clear();
+    _current_merging_spill_files.clear();
 
     // For final merge: merge all remaining streams
     // For intermediate merge: merge only num_streams streams
-    size_t streams_to_merge = is_final_merge ? _sorted_streams.size() : num_streams;
-
-    for (size_t i = 0; i < streams_to_merge && !_sorted_streams.empty(); ++i) {
-        auto stream = _sorted_streams.front();
-        stream->set_read_counters(_profile);
-        _current_merging_streams.emplace_back(stream);
-        // Create a block supplier lambda that reads the next block from the spill stream
-        child_block_suppliers.emplace_back([stream](Block* block, bool* eos) {
-            return stream->read_next_block_sync(block, eos);
-        });
-        _sorted_streams.pop_front();
+    size_t streams_to_merge = is_final_merge ? _sorted_spill_files.size() : num_streams;
+
+    for (size_t i = 0; i < streams_to_merge && !_sorted_spill_files.empty(); ++i) {
+        auto spill_file = _sorted_spill_files.front();
+        _current_merging_spill_files.emplace_back(spill_file);
+        SpillFileReaderSPtr reader = spill_file->create_reader(_runtime_state, _profile);
+        child_block_suppliers.emplace_back(
+                [reader](Block* block, bool* eos) { return reader->read(block, eos); });
+        _sorted_spill_files.pop_front();
     }
 
     RETURN_IF_ERROR(_merger->prepare(child_block_suppliers));
@@ -356,17 +364,17 @@ Status VIcebergSortWriter::_create_final_merger() {
 }
 
 void VIcebergSortWriter::_cleanup_spill_streams() {
-    // Clean up all remaining spill streams to release disk resources
-    for (auto& stream : _sorted_streams) {
-        ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
+    // Clean up all remaining spill files to release disk resources
+    for (auto& file : _sorted_spill_files) {
+        ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(file);
     }
-    _sorted_streams.clear();
+    _sorted_spill_files.clear();
 
-    // Also clean up any streams that are currently being merged
-    for (auto& stream : _current_merging_streams) {
-        ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
+    // Also clean up any files that are currently being merged
+    for (auto& file : _current_merging_spill_files) {
+        ExecEnv::GetInstance()->spill_file_mgr()->delete_spill_file(file);
     }
-    _current_merging_streams.clear();
+    _current_merging_spill_files.clear();
 }
 
 #include "common/compile_check_end.h"
diff --git a/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.h b/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.h
index 0348a048d07..95ffc5a60e2 100644
--- a/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.h
+++ b/be/src/exec/sink/writer/iceberg/viceberg_sort_writer.h
@@ -34,12 +34,10 @@
 // in this header, causing heavy transitive includes for all files that include
 // viceberg_sort_writer.h. Moving implementations to .cpp allows us to forward-declare
 // these types and only include their headers in the .cpp file.
-namespace doris {
-class SpillStream;
-using SpillStreamSPtr = std::shared_ptr<SpillStream>;
-} // namespace doris
 
 namespace doris {
+class SpillFile;
+using SpillFileSPtr = std::shared_ptr<SpillFile>;
 class RuntimeState;
 class RuntimeProfile;
 
@@ -169,10 +167,11 @@ private:
     // Sorter and merger for handling in-memory sorting and multi-way merge
     std::unique_ptr<FullSorter> _sorter;
     std::unique_ptr<VSortedRunMerger> _merger;
-    // Queue of spill streams waiting to be merged (FIFO order)
-    std::deque<SpillStreamSPtr> _sorted_streams;
-    // Streams currently being consumed by the merger
-    std::vector<SpillStreamSPtr> _current_merging_streams;
+
+    // Queue of spill files waiting to be merged (FIFO order)
+    std::deque<SpillFileSPtr> _sorted_spill_files;
+    // Files currently being consumed by the merger
+    std::vector<SpillFileSPtr> _current_merging_spill_files;
 
     // Target file size in bytes; files are split when this threshold is exceeded
     // Default: config::iceberg_sink_max_file_size (1GB)
diff --git a/be/src/exec/sort/sort_cursor.h b/be/src/exec/sort/sort_cursor.h
index 2a0d85d0fd3..be869f0e52f 100644
--- a/be/src/exec/sort/sort_cursor.h
+++ b/be/src/exec/sort/sort_cursor.h
@@ -20,6 +20,8 @@
 
 #pragma once
 
+#include <glog/logging.h>
+
 #include <utility>
 
 #include "core/block/block.h"
diff --git a/be/src/exec/sort/sorter.h b/be/src/exec/sort/sorter.h
index 42ef13792eb..4d8777abeff 100644
--- a/be/src/exec/sort/sorter.h
+++ b/be/src/exec/sort/sorter.h
@@ -118,6 +118,8 @@ public:
             : _vsort_exec_exprs(mock_vsort_exec_exprs),
               _is_asc_order(mock_is_asc_order),
               _nulls_first(mock_nulls_first) {}
+    SortDescription& get_mutable_sort_description() { return _sort_description; }
+    const VSortExecExprs& get_vsort_exec_exprs() const { return _vsort_exec_exprs; }
 #endif
 
     virtual ~Sorter() = default;
diff --git a/be/src/exec/spill/spill_file.cpp b/be/src/exec/spill/spill_file.cpp
new file mode 100644
index 00000000000..78347ea78eb
--- /dev/null
+++ b/be/src/exec/spill/spill_file.cpp
@@ -0,0 +1,95 @@
+// 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 "exec/spill/spill_file.h"
+
+#include <glog/logging.h>
+
+#include <filesystem>
+#include <memory>
+#include <utility>
+
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
+#include "io/fs/local_file_system.h"
+#include "runtime/exec_env.h"
+#include "runtime/query_context.h"
+#include "runtime/runtime_profile.h"
+#include "runtime/runtime_state.h"
+#include "util/debug_points.h"
+
+namespace doris {
+#include "common/compile_check_begin.h"
+SpillFile::SpillFile(SpillDataDir* data_dir, std::string relative_path)
+        : _data_dir(data_dir),
+          _spill_dir(data_dir->get_spill_data_path() + "/" + std::move(relative_path)) {}
+
+SpillFile::~SpillFile() {
+    gc();
+}
+
+void SpillFile::gc() {
+    bool exists = false;
+    auto status = io::global_local_filesystem()->exists(_spill_dir, &exists);
+    if (status.ok() && exists) {
+        // Delete spill directory directly instead of moving it to a GC directory.
+        // This simplifies cleanup and avoids retaining spill data under a GC path.
+        status = io::global_local_filesystem()->delete_directory(_spill_dir);
+        DBUG_EXECUTE_IF("fault_inject::spill_file::gc", {
+            status = Status::Error<INTERNAL_ERROR>("fault_inject spill_file gc failed");
+        });
+        if (!status.ok()) {
+            LOG_EVERY_T(WARNING, 1) << fmt::format("failed to delete spill data, dir {}, error: {}",
+                                                   _spill_dir, status.to_string());
+        }
+    }
+    // decrease spill data usage anyway, since in ~QueryContext() spill data of the query will be
+    // clean up as a last resort
+    _data_dir->update_spill_data_usage(-_total_written_bytes);
+    _total_written_bytes = 0;
+}
+
+Status SpillFile::create_writer(RuntimeState* state, RuntimeProfile* profile,
+                                SpillFileWriterSPtr& writer) {
+    writer = std::make_shared<SpillFileWriter>(shared_from_this(), state, profile, _data_dir,
+                                               _spill_dir);
+    // _active_writer is set in SpillFileWriter constructor via the shared_ptr
+    return Status::OK();
+}
+
+SpillFileReaderSPtr SpillFile::create_reader(RuntimeState* state, RuntimeProfile* profile) const {
+    // It's a programming error to create a reader while a writer is still active.
+    DCHECK(_active_writer == nullptr) << "create_reader() called while writer still active";
+    return std::make_shared<SpillFileReader>(state, profile, _spill_dir, _part_count);
+}
+
+void SpillFile::finish_writing() {
+    _ready_for_reading = true;
+    // writer finished; clear active writer pointer
+    _active_writer = nullptr;
+}
+
+void SpillFile::update_written_bytes(int64_t delta_bytes) {
+    _total_written_bytes += delta_bytes;
+}
+
+void SpillFile::increment_part_count() {
+    ++_part_count;
+}
+
+} // namespace doris
diff --git a/be/src/exec/spill/spill_file.h b/be/src/exec/spill/spill_file.h
new file mode 100644
index 00000000000..aa9b2287b44
--- /dev/null
+++ b/be/src/exec/spill/spill_file.h
@@ -0,0 +1,114 @@
+// 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.
+
+#pragma once
+#include <memory>
+#include <string>
+
+#include "common/status.h"
+
+namespace doris {
+#include "common/compile_check_begin.h"
+class RuntimeProfile;
+class RuntimeState;
+
+class Block;
+class SpillDataDir;
+class SpillFileWriter;
+class SpillFileReader;
+using SpillFileWriterSPtr = std::shared_ptr<SpillFileWriter>;
+using SpillFileReaderSPtr = std::shared_ptr<SpillFileReader>;
+
+/// SpillFile represents a logical spill file that may consist of multiple
+/// physical "part" files on disk. Parts are managed automatically by
+/// SpillFileWriter when a part exceeds the configured size threshold.
+///
+/// On-disk layout:
+///   spill_dir/         (created lazily by SpillFileWriter on first write)
+///   +-- 0              (part 0)
+///   +-- 1              (part 1)
+///   +-- ...
+///
+/// Writing workflow:
+///   SpillFileWriterSPtr writer;
+///   RETURN_IF_ERROR(spill_file->create_writer(state, profile, writer));
+///   RETURN_IF_ERROR(writer->write_block(state, block)); // auto-rotates parts
+///   RETURN_IF_ERROR(writer->close());                   // finalizes all parts
+///
+/// Reading workflow:
+///   auto reader = spill_file->create_reader(state, profile);
+///   RETURN_IF_ERROR(reader->open());
+///   while (!eos) { RETURN_IF_ERROR(reader->read(&block, &eos)); }
+class SpillFile : public std::enable_shared_from_this<SpillFile> {
+public:
+    // to avoid too many small file writes
+    static constexpr size_t MIN_SPILL_WRITE_BATCH_MEM = 512 * 1024;
+    static constexpr size_t MAX_SPILL_WRITE_BATCH_MEM = 32 * 1024 * 1024;
+
+    /// @param data_dir       The spill storage directory (disk) selected by SpillFileManager.
+    /// @param relative_path  Relative path under the spill root, formatted by the operator.
+    ///                       e.g. "query_id/sort-node_id-task_id-unique_id"
+    SpillFile(SpillDataDir* data_dir, std::string relative_path);
+
+    SpillFile() = delete;
+    SpillFile(const SpillFile&) = delete;
+    SpillFile& operator=(const SpillFile&) = delete;
+
+    ~SpillFile();
+
+    void gc();
+
+    /// Returns true after the writer has been closed (all data flushed).
+    bool ready_for_reading() const { return _ready_for_reading; }
+
+    /// Create a SpillFileWriter that automatically manages multi-part rotation.
+    /// Only one writer should exist per SpillFile at a time.
+    /// Part size threshold is read from config::spill_file_part_size_bytes.
+    Status create_writer(RuntimeState* state, RuntimeProfile* profile, SpillFileWriterSPtr& writer);
+
+    /// Create a SpillFileReader that reads sequentially across all parts.
+    /// The caller should call reader->open() before reading.
+    SpillFileReaderSPtr create_reader(RuntimeState* state, RuntimeProfile* profile) const;
+
+private:
+    friend class SpillFileWriter;
+    friend class SpillFileManager;
+
+    /// Called by SpillFileWriter::close() to mark writing as complete.
+    void finish_writing();
+
+    /// Called by SpillFileWriter to incrementally track bytes written to disk.
+    /// This ensures SpillFile always knows the correct _total_written_bytes for
+    /// gc() accounting, even if the writer's close() is never properly called.
+    void update_written_bytes(int64_t delta_bytes);
+
+    /// Called by SpillFileWriter when a part file is completed.
+    void increment_part_count();
+
+    SpillDataDir* _data_dir = nullptr;
+    // Absolute path: data_dir->get_spill_data_path() + "/" + relative_path
+    std::string _spill_dir;
+    int64_t _total_written_bytes = 0;
+    size_t _part_count = 0;
+    bool _ready_for_reading = false;
+    // Pointer to the currently-active writer. Mutable to allow checks from const
+    // methods like create_reader(). Only one writer may be active at a time.
+    mutable SpillFileWriter* _active_writer = nullptr;
+};
+using SpillFileSPtr = std::shared_ptr<SpillFile>;
+} // namespace doris
+#include "common/compile_check_end.h"
diff --git a/be/src/exec/spill/spill_stream_manager.cpp b/be/src/exec/spill/spill_file_manager.cpp
similarity index 84%
rename from be/src/exec/spill/spill_stream_manager.cpp
rename to be/src/exec/spill/spill_file_manager.cpp
index 38d42daa6bd..0946e3209b7 100644
--- a/be/src/exec/spill/spill_stream_manager.cpp
+++ b/be/src/exec/spill/spill_file_manager.cpp
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
 
 #include <fmt/format.h>
 #include <glog/logging.h>
@@ -23,34 +23,30 @@
 #include <algorithm>
 #include <filesystem>
 #include <memory>
-#include <numeric>
-#include <random>
 #include <string>
 
 #include "common/logging.h"
 #include "common/metrics/doris_metrics.h"
-#include "exec/spill/spill_stream.h"
+#include "exec/spill/spill_file.h"
 #include "io/fs/file_system.h"
 #include "io/fs/local_file_system.h"
-#include "runtime/runtime_profile.h"
-#include "runtime/runtime_state.h"
 #include "storage/olap_define.h"
 #include "util/parse_util.h"
 #include "util/pretty_printer.h"
 #include "util/time.h"
-#include "util/uid_util.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
 
-SpillStreamManager::~SpillStreamManager() {
+SpillFileManager::~SpillFileManager() {
     DorisMetrics::instance()->metric_registry()->deregister_entity(_entity);
 }
-SpillStreamManager::SpillStreamManager(
+
+SpillFileManager::SpillFileManager(
         std::unordered_map<std::string, std::unique_ptr<SpillDataDir>>&& spill_store_map)
         : _spill_store_map(std::move(spill_store_map)), _stop_background_threads_latch(1) {}
 
-Status SpillStreamManager::init() {
+Status SpillFileManager::init() {
     LOG(INFO) << "init spill stream manager";
     RETURN_IF_ERROR(_init_spill_store_map());
 
@@ -87,7 +83,7 @@ Status SpillStreamManager::init() {
     return Status::OK();
 }
 
-void SpillStreamManager::_init_metrics() {
+void SpillFileManager::_init_metrics() {
     _entity = DorisMetrics::instance()->metric_registry()->register_entity("spill",
                                                                            {{"name", "spill"}});
 
@@ -103,7 +99,7 @@ void SpillStreamManager::_init_metrics() {
 }
 
 // clean up stale spilled files
-void SpillStreamManager::_spill_gc_thread_callback() {
+void SpillFileManager::_spill_gc_thread_callback() {
     while (!_stop_background_threads_latch.wait_for(
             std::chrono::milliseconds(config::spill_gc_interval_ms))) {
         gc(config::spill_gc_work_time_ms);
@@ -113,7 +109,7 @@ void SpillStreamManager::_spill_gc_thread_callback() {
     }
 }
 
-Status SpillStreamManager::_init_spill_store_map() {
+Status SpillFileManager::_init_spill_store_map() {
     for (const auto& store : _spill_store_map) {
         RETURN_IF_ERROR(store.second->init());
     }
@@ -121,7 +117,7 @@ Status SpillStreamManager::_init_spill_store_map() {
     return Status::OK();
 }
 
-std::vector<SpillDataDir*> SpillStreamManager::_get_stores_for_spill(
+std::vector<SpillDataDir*> SpillFileManager::_get_stores_for_spill(
         TStorageMedium::type storage_medium) {
     std::vector<std::pair<SpillDataDir*, double>> stores_with_usage;
     for (auto& [_, store] : _spill_store_map) {
@@ -133,8 +129,7 @@ std::vector<SpillDataDir*> SpillStreamManager::_get_stores_for_spill(
         return {};
     }
 
-    std::sort(stores_with_usage.begin(), stores_with_usage.end(),
-              [](auto&& a, auto&& b) { return a.second < b.second; });
+    std::ranges::sort(stores_with_usage, [](auto&& a, auto&& b) { return a.second < b.second; });
 
     std::vector<SpillDataDir*> stores;
     for (const auto& [store, _] : stores_with_usage) {
@@ -143,11 +138,8 @@ std::vector<SpillDataDir*> SpillStreamManager::_get_stores_for_spill(
     return stores;
 }
 
-Status SpillStreamManager::register_spill_stream(RuntimeState* state, SpillStreamSPtr& spill_stream,
-                                                 const std::string& query_id,
-                                                 const std::string& operator_name, int32_t node_id,
-                                                 int32_t batch_rows, size_t batch_bytes,
-                                                 RuntimeProfile* operator_profile) {
+Status SpillFileManager::create_spill_file(const std::string& relative_path,
+                                           SpillFileSPtr& spill_file) {
     auto data_dirs = _get_stores_for_spill(TStorageMedium::type::SSD);
     if (data_dirs.empty()) {
         data_dirs = _get_stores_for_spill(TStorageMedium::type::HDD);
@@ -157,37 +149,21 @@ Status SpillStreamManager::register_spill_stream(RuntimeState* state, SpillStrea
                 "no available disk can be used for spill.");
     }
 
-    uint64_t id = id_++;
-    std::string spill_dir;
-    SpillDataDir* data_dir = nullptr;
-    for (auto& dir : data_dirs) {
-        std::string spill_root_dir = dir->get_spill_data_path();
-        // storage_root/spill/query_id/partitioned_hash_join-node_id-task_id-stream_id
-        spill_dir = fmt::format("{}/{}/{}-{}-{}-{}", spill_root_dir, query_id, operator_name,
-                                node_id, state->task_id(), id);
-        auto st = io::global_local_filesystem()->create_directory(spill_dir);
-        if (!st.ok()) {
-            std::cerr << "create spill dir failed: " << st.to_string();
-            continue;
-        }
-        data_dir = dir;
-        break;
-    }
-    if (!data_dir) {
-        return Status::Error<ErrorCode::CE_CMD_PARAMS_ERROR>(
-                "there is no available disk that can be used to spill.");
-    }
-    spill_stream = std::make_shared<SpillStream>(state, id, data_dir, spill_dir, batch_rows,
-                                                 batch_bytes, operator_profile);
-    RETURN_IF_ERROR(spill_stream->prepare());
+    // Select the first available data dir (sorted by usage ascending)
+    SpillDataDir* data_dir = data_dirs.front();
+    spill_file = std::make_shared<SpillFile>(data_dir, relative_path);
     return Status::OK();
 }
 
-void SpillStreamManager::delete_spill_stream(SpillStreamSPtr stream) {
-    stream->gc();
+void SpillFileManager::delete_spill_file(SpillFileSPtr spill_file) {
+    if (!spill_file) {
+        LOG(WARNING) << "[spill][delete] null spill_file";
+        return;
+    }
+    spill_file->gc();
 }
 
-void SpillStreamManager::gc(int32_t max_work_time_ms) {
+void SpillFileManager::gc(int32_t max_work_time_ms) {
     bool exists = true;
     bool has_work = false;
     int64_t max_work_time_ns = max_work_time_ms * 1000L * 1000L;
@@ -343,9 +319,7 @@ Status SpillDataDir::update_capacity() {
         _spill_data_limit_bytes = (int64_t)(_spill_data_limit_bytes *
                                             config::storage_flood_stage_usage_percent / 100);
     }
-    if (_spill_data_limit_bytes > disk_use_max_bytes) {
-        _spill_data_limit_bytes = disk_use_max_bytes;
-    }
+    _spill_data_limit_bytes = std::min(_spill_data_limit_bytes, disk_use_max_bytes);
     spill_disk_limit->set_value(_spill_data_limit_bytes);
 
     std::string spill_root_dir = get_spill_data_path();
@@ -374,7 +348,8 @@ bool SpillDataDir::reach_capacity_limit(int64_t incoming_data_size) {
     }
     if (_spill_data_bytes + incoming_data_size > _spill_data_limit_bytes) {
         LOG_EVERY_T(WARNING, 1) << fmt::format(
-                "spill data reach limit, path: {}, capacity: {}, limit: {}, used: {}, available: "
+                "spill data reach limit, path: {}, capacity: {}, limit: {}, used: {}, "
+                "available: "
                 "{}, "
                 "incoming "
                 "bytes: {}",
diff --git a/be/src/exec/spill/spill_stream_manager.h b/be/src/exec/spill/spill_file_manager.h
similarity index 87%
rename from be/src/exec/spill/spill_stream_manager.h
rename to be/src/exec/spill/spill_file_manager.h
index 4ecd93a700a..582df3f1f63 100644
--- a/be/src/exec/spill/spill_stream_manager.h
+++ b/be/src/exec/spill/spill_file_manager.h
@@ -24,9 +24,10 @@
 #include <vector>
 
 #include "common/metrics/metrics.h"
-#include "exec/spill/spill_stream.h"
+#include "exec/spill/spill_file.h"
 #include "storage/options.h"
 #include "util/threadpool.h"
+
 namespace doris {
 #include "common/compile_check_begin.h"
 class RuntimeProfile;
@@ -39,7 +40,7 @@ using UIntGauge = AtomicGauge<uint64_t>;
 class MetricEntity;
 struct MetricPrototype;
 
-class SpillStreamManager;
+class SpillFileManager;
 class SpillDataDir {
 public:
     SpillDataDir(std::string path, int64_t capacity_bytes,
@@ -88,7 +89,7 @@ private:
                                  (double)_disk_capacity_bytes;
     }
 
-    friend class SpillStreamManager;
+    friend class SpillFileManager;
     std::string _path;
 
     // protect _disk_capacity_bytes, _available_bytes, _spill_data_limit_bytes, _spill_data_bytes
@@ -110,10 +111,10 @@ private:
     IntGauge* spill_disk_has_spill_data = nullptr;
     IntGauge* spill_disk_has_spill_gc_data = nullptr;
 };
-class SpillStreamManager {
+class SpillFileManager {
 public:
-    ~SpillStreamManager();
-    SpillStreamManager(
+    ~SpillFileManager();
+    SpillFileManager(
             std::unordered_map<std::string, std::unique_ptr<SpillDataDir>>&& spill_store_map);
 
     Status init();
@@ -125,14 +126,16 @@ public:
         }
     }
 
-    // 创建SpillStream并登记
-    Status register_spill_stream(RuntimeState* state, SpillStreamSPtr& spill_stream,
-                                 const std::string& query_id, const std::string& operator_name,
-                                 int32_t node_id, int32_t batch_rows, size_t batch_bytes,
-                                 RuntimeProfile* operator_profile);
+    // Create SpillFile and register it
+    // @param relative_path  Operator-formatted path under the spill root,
+    //                       e.g. "query_id/sort-node_id-task_id-unique_id"
+    Status create_spill_file(const std::string& relative_path, SpillFileSPtr& spill_file);
+
+    /// Get a unique ID for constructing spill file paths.
+    uint64_t next_id() { return id_++; }
 
-    // 标记SpillStream需要被删除,在GC线程中异步删除落盘文件
-    void delete_spill_stream(SpillStreamSPtr spill_stream);
+    // Mark SpillFile for deletion; asynchronously delete spill files in the GC thread
+    void delete_spill_file(SpillFileSPtr spill_file);
 
     void gc(int32_t max_work_time_ms);
 
diff --git a/be/src/exec/spill/spill_file_reader.cpp b/be/src/exec/spill/spill_file_reader.cpp
new file mode 100644
index 00000000000..50609d93f42
--- /dev/null
+++ b/be/src/exec/spill/spill_file_reader.cpp
@@ -0,0 +1,237 @@
+// 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 "exec/spill/spill_file_reader.h"
+
+#include <glog/logging.h>
+
+#include <algorithm>
+
+#include "common/cast_set.h"
+#include "common/exception.h"
+#include "core/block/block.h"
+#include "exec/spill/spill_file_manager.h"
+#include "io/file_factory.h"
+#include "io/fs/file_reader.h"
+#include "io/fs/local_file_system.h"
+#include "runtime/exec_env.h"
+#include "runtime/query_context.h"
+#include "runtime/runtime_state.h"
+#include "util/debug_points.h"
+#include "util/slice.h"
+namespace doris {
+#include "common/compile_check_begin.h"
+namespace io {
+class FileSystem;
+} // namespace io
+
+SpillFileReader::SpillFileReader(RuntimeState* state, RuntimeProfile* profile,
+                                 std::string spill_dir, size_t part_count)
+        : _spill_dir(std::move(spill_dir)),
+          _part_count(part_count),
+          _resource_ctx(state->get_query_ctx()->resource_ctx()) {
+    // Internalize counter setup
+    RuntimeProfile* custom_profile = profile->get_child("CustomCounters");
+    DCHECK(custom_profile != nullptr);
+    _read_file_timer = custom_profile->get_counter("SpillReadFileTime");
+    _deserialize_timer = custom_profile->get_counter("SpillReadDerializeBlockTime");
+    _read_block_count = custom_profile->get_counter("SpillReadBlockCount");
+    _read_block_data_size = custom_profile->get_counter("SpillReadBlockBytes");
+    _read_file_size = custom_profile->get_counter("SpillReadFileBytes");
+    _read_rows_count = custom_profile->get_counter("SpillReadRows");
+    _read_file_count = custom_profile->get_counter("SpillReadFileCount");
+}
+
+Status SpillFileReader::open() {
+    if (_is_open || _part_count == 0) {
+        return Status::OK();
+    }
+    RETURN_IF_ERROR(_open_part(0));
+    _is_open = true;
+    return Status::OK();
+}
+
+Status SpillFileReader::_open_part(size_t part_index) {
+    _close_current_part();
+
+    _current_part_index = part_index;
+    _part_opened = true;
+    std::string part_path = _spill_dir + "/" + std::to_string(part_index);
+
+    SCOPED_TIMER(_read_file_timer);
+    COUNTER_UPDATE(_read_file_count, 1);
+    RETURN_IF_ERROR(io::global_local_filesystem()->open_file(part_path, &_file_reader));
+
+    size_t file_size = _file_reader->size();
+    DCHECK(file_size >= 16); // max_sub_block_size + block count
+
+    Slice result((char*)&_part_block_count, sizeof(size_t));
+
+    // read block count
+    size_t bytes_read = 0;
+    RETURN_IF_ERROR(_file_reader->read_at(file_size - sizeof(size_t), result, &bytes_read));
+    DCHECK(bytes_read == 8);
+
+    // read max sub block size
+    bytes_read = 0;
+    result.data = (char*)&_part_max_sub_block_size;
+    RETURN_IF_ERROR(_file_reader->read_at(file_size - sizeof(size_t) * 2, result, &bytes_read));
+    DCHECK(bytes_read == 8);
+
+    // The buffer is used for two purposes:
+    // 1. Reading the block start offsets array (needs _part_block_count * sizeof(size_t) bytes)
+    // 2. Reading a single block's serialized data (needs up to _part_max_sub_block_size bytes)
+    // We must ensure the buffer is large enough for either case, so take the maximum.
+    size_t buff_size = std::max(_part_block_count * sizeof(size_t), _part_max_sub_block_size);
+    if (buff_size > _read_buff.size()) {
+        _read_buff.reserve(buff_size);
+    }
+
+    // Read the block start offsets array from the end of the file.
+    // The file layout (from end backwards) is:
+    //   [block count (size_t)]
+    //   [max sub block size (size_t)]
+    //   [block start offsets array (_part_block_count * size_t)]
+    // So the offsets array starts at:
+    //   file_size - (_part_block_count + 2) * sizeof(size_t)
+    size_t read_offset = file_size - (_part_block_count + 2) * sizeof(size_t);
+    result.data = _read_buff.data();
+    result.size = _part_block_count * sizeof(size_t);
+
+    RETURN_IF_ERROR(_file_reader->read_at(read_offset, result, &bytes_read));
+    DCHECK(bytes_read == _part_block_count * sizeof(size_t));
+
+    _block_start_offsets.resize(_part_block_count + 1);
+    for (size_t i = 0; i < _part_block_count; ++i) {
+        _block_start_offsets[i] = *(size_t*)(result.data + i * sizeof(size_t));
+    }
+    _block_start_offsets[_part_block_count] = file_size - (_part_block_count + 2) * sizeof(size_t);
+
+    _part_read_block_index = 0;
+    return Status::OK();
+}
+
+void SpillFileReader::_close_current_part() {
+    if (_file_reader) {
+        (void)_file_reader->close();
+        _file_reader.reset();
+    }
+    _part_block_count = 0;
+    _part_read_block_index = 0;
+    _part_max_sub_block_size = 0;
+    _block_start_offsets.clear();
+    _part_opened = false;
+}
+
+Status SpillFileReader::read(Block* block, bool* eos) {
+    DBUG_EXECUTE_IF("fault_inject::spill_file::read_next_block", {
+        return Status::InternalError("fault_inject spill_file read_next_block failed");
+    });
+    block->clear_column_data();
+
+    if (_part_count == 0) {
+        *eos = true;
+        return Status::OK();
+    }
+
+    // Advance to next part if current part is exhausted
+    while (_part_read_block_index >= _part_block_count) {
+        size_t next_part = _part_opened ? _current_part_index + 1 : 0;
+        if (next_part >= _part_count) {
+            *eos = true;
+            return Status::OK();
+        }
+        RETURN_IF_ERROR(_open_part(next_part));
+    }
+
+    size_t bytes_to_read = _block_start_offsets[_part_read_block_index + 1] -
+                           _block_start_offsets[_part_read_block_index];
+
+    if (bytes_to_read == 0) {
+        ++_part_read_block_index;
+        *eos = false;
+        return Status::OK();
+    }
+
+    Slice result(_read_buff.data(), bytes_to_read);
+    size_t bytes_read = 0;
+    {
+        SCOPED_TIMER(_read_file_timer);
+        RETURN_IF_ERROR(_file_reader->read_at(_block_start_offsets[_part_read_block_index], result,
+                                              &bytes_read));
+    }
+    DCHECK(bytes_read == bytes_to_read);
+
+    if (bytes_read > 0) {
+        COUNTER_UPDATE(_read_file_size, bytes_read);
+        ExecEnv::GetInstance()->spill_file_mgr()->update_spill_read_bytes(bytes_read);
+        if (_resource_ctx) {
+            _resource_ctx->io_context()->update_spill_read_bytes_from_local_storage(bytes_read);
+        }
+        COUNTER_UPDATE(_read_block_count, 1);
+        {
+            SCOPED_TIMER(_deserialize_timer);
+            if (!_pb_block.ParseFromArray(result.data, cast_set<int>(result.size))) {
+                return Status::InternalError("Failed to read spilled block");
+            }
+            size_t uncompressed_size = 0;
+            int64_t uncompressed_time = 0;
+            RETURN_IF_ERROR(block->deserialize(_pb_block, &uncompressed_size, &uncompressed_time));
+        }
+        COUNTER_UPDATE(_read_block_data_size, block->bytes());
+        COUNTER_UPDATE(_read_rows_count, block->rows());
+    } else {
+        block->clear_column_data();
+    }
+
+    ++_part_read_block_index;
+    *eos = false;
+    return Status::OK();
+}
+
+Status SpillFileReader::seek(size_t block_index) {
+    return _seek_to_block(block_index);
+}
+
+Status SpillFileReader::_seek_to_block(size_t block_index) {
+    if (_part_count == 0) {
+        return Status::OK();
+    }
+
+    size_t remaining = block_index;
+    for (size_t part_index = 0; part_index < _part_count; ++part_index) {
+        RETURN_IF_ERROR(_open_part(part_index));
+        if (remaining < _part_block_count) {
+            _part_read_block_index = remaining;
+            return Status::OK();
+        }
+        remaining -= _part_block_count;
+    }
+
+    // block_index is out of range: position reader at EOS.
+    RETURN_IF_ERROR(_open_part(_part_count - 1));
+    _part_read_block_index = _part_block_count;
+    return Status::OK();
+}
+
+Status SpillFileReader::close() {
+    _close_current_part();
+    _is_open = false;
+    return Status::OK();
+}
+
+} // namespace doris
diff --git a/be/src/exec/spill/spill_file_reader.h b/be/src/exec/spill/spill_file_reader.h
new file mode 100644
index 00000000000..beca6cc7c44
--- /dev/null
+++ b/be/src/exec/spill/spill_file_reader.h
@@ -0,0 +1,111 @@
+// 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.
+
+#pragma once
+
+#include <gen_cpp/data.pb.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "common/status.h"
+#include "core/pod_array.h"
+#include "core/pod_array_fwd.h"
+#include "io/fs/file_reader_writer_fwd.h"
+#include "runtime/runtime_profile.h"
+#include "runtime/workload_management/resource_context.h"
+
+namespace doris {
+#include "common/compile_check_begin.h"
+class RuntimeState;
+class Block;
+
+/// SpillFileReader reads blocks sequentially across all parts of a SpillFile.
+///
+/// Usage:
+///   auto reader = spill_file->create_reader(state, profile);
+///   RETURN_IF_ERROR(reader->open());
+///   bool eos = false;
+///   while (!eos) { RETURN_IF_ERROR(reader->read(&block, &eos)); }
+///
+/// Part boundaries are transparent to the caller. When the current part is
+/// exhausted, the reader automatically opens the next part.
+class SpillFileReader {
+public:
+    SpillFileReader(RuntimeState* state, RuntimeProfile* profile, std::string spill_dir,
+                    size_t part_count);
+
+    ~SpillFileReader() { (void)close(); }
+
+    /// Open the first part and read its footer metadata.
+    Status open();
+
+    /// Read the next block. Automatically advances across part boundaries.
+    /// Sets *eos = true when all parts are exhausted.
+    Status read(Block* block, bool* eos);
+
+    /// Seek to a global block index within the whole spill file.
+    /// block_index is 0-based across all parts.
+    /// If block_index is out of range, the reader is positioned at EOS.
+    Status seek(size_t block_index);
+
+    Status close();
+
+private:
+    /// Open a specific part file and read its footer.
+    Status _open_part(size_t part_index);
+
+    /// Seek implementation with status propagation.
+    Status _seek_to_block(size_t block_index);
+
+    /// Close the current part's file reader.
+    void _close_current_part();
+
+    // ── Configuration ──
+    std::string _spill_dir;
+    size_t _part_count;
+
+    // ── Current part state ──
+    size_t _current_part_index = 0;
+    bool _is_open = false;
+    bool _part_opened = false;
+    io::FileReaderSPtr _file_reader;
+    size_t _part_block_count = 0;
+    size_t _part_read_block_index = 0;
+    size_t _part_max_sub_block_size = 0;
+    PaddedPODArray<char> _read_buff;
+    std::vector<size_t> _block_start_offsets;
+
+    PBlock _pb_block;
+
+    // ── Counters ──
+    RuntimeProfile::Counter* _read_file_timer = nullptr;
+    RuntimeProfile::Counter* _deserialize_timer = nullptr;
+    RuntimeProfile::Counter* _read_block_count = nullptr;
+    RuntimeProfile::Counter* _read_block_data_size = nullptr;
+    RuntimeProfile::Counter* _read_file_size = nullptr;
+    RuntimeProfile::Counter* _read_rows_count = nullptr;
+    RuntimeProfile::Counter* _read_file_count = nullptr;
+
+    std::shared_ptr<ResourceContext> _resource_ctx = nullptr;
+};
+
+using SpillFileReaderSPtr = std::shared_ptr<SpillFileReader>;
+
+} // namespace doris
+#include "common/compile_check_end.h"
diff --git a/be/src/exec/spill/spill_file_writer.cpp b/be/src/exec/spill/spill_file_writer.cpp
new file mode 100644
index 00000000000..ced813e51e3
--- /dev/null
+++ b/be/src/exec/spill/spill_file_writer.cpp
@@ -0,0 +1,273 @@
+// 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 "exec/spill/spill_file_writer.h"
+
+#include "agent/be_exec_version_manager.h"
+#include "common/config.h"
+#include "common/status.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "io/fs/local_file_system.h"
+#include "io/fs/local_file_writer.h"
+#include "runtime/exec_env.h"
+#include "runtime/query_context.h"
+#include "runtime/runtime_state.h"
+#include "runtime/thread_context.h"
+
+namespace doris {
+#include "common/compile_check_begin.h"
+
+SpillFileWriter::SpillFileWriter(const std::shared_ptr<SpillFile>& spill_file, RuntimeState* state,
+                                 RuntimeProfile* profile, SpillDataDir* data_dir,
+                                 const std::string& spill_dir)
+        : _spill_file_wptr(spill_file),
+          _data_dir(data_dir),
+          _spill_dir(spill_dir),
+          _max_part_size(config::spill_file_part_size_bytes),
+          _resource_ctx(state->get_query_ctx()->resource_ctx()) {
+    // Common counters
+    RuntimeProfile* common_profile = profile->get_child("CommonCounters");
+    DCHECK(common_profile != nullptr);
+    _memory_used_counter = common_profile->get_counter("MemoryUsage");
+
+    // Register this writer as the active writer for the SpillFile.
+    spill_file->_active_writer = this;
+
+    // Custom (spill-specific) counters
+    RuntimeProfile* custom_profile = profile->get_child("CustomCounters");
+    _write_file_timer = custom_profile->get_counter("SpillWriteFileTime");
+    _serialize_timer = custom_profile->get_counter("SpillWriteSerializeBlockTime");
+    _write_block_counter = custom_profile->get_counter("SpillWriteBlockCount");
+    _write_block_bytes_counter = custom_profile->get_counter("SpillWriteBlockBytes");
+    _write_file_total_size = custom_profile->get_counter("SpillWriteFileBytes");
+    _write_file_current_size = custom_profile->get_counter("SpillWriteFileCurrentBytes");
+    _write_rows_counter = custom_profile->get_counter("SpillWriteRows");
+    _total_file_count = custom_profile->get_counter("SpillWriteFileTotalCount");
+}
+
+SpillFileWriter::~SpillFileWriter() {
+    if (_closed) {
+        return;
+    }
+    Status st = close();
+    if (!st.ok()) {
+        LOG(WARNING) << "SpillFileWriter::~SpillFileWriter() failed: " << st.to_string()
+                     << ", spill_dir=" << _spill_dir;
+    }
+}
+
+Status SpillFileWriter::_open_next_part() {
+    _current_part_path = _spill_dir + "/" + std::to_string(_current_part_index);
+    // Create the spill directory lazily on first part
+    if (_current_part_index == 0) {
+        RETURN_IF_ERROR(io::global_local_filesystem()->create_directory(_spill_dir));
+    }
+    RETURN_IF_ERROR(io::global_local_filesystem()->create_file(_current_part_path, &_file_writer));
+    COUNTER_UPDATE(_total_file_count, 1);
+    return Status::OK();
+}
+
+Status SpillFileWriter::_close_current_part(const std::shared_ptr<SpillFile>& spill_file) {
+    if (!_file_writer) {
+        return Status::OK();
+    }
+
+    // Write footer: block offsets + max_sub_block_size + block_count
+    _part_meta.append((const char*)&_part_max_sub_block_size, sizeof(_part_max_sub_block_size));
+    _part_meta.append((const char*)&_part_written_blocks, sizeof(_part_written_blocks));
+
+    {
+        SCOPED_TIMER(_write_file_timer);
+        RETURN_IF_ERROR(_file_writer->append(_part_meta));
+    }
+
+    int64_t meta_size = _part_meta.size();
+    _part_written_bytes += meta_size;
+    _total_written_bytes += meta_size;
+    COUNTER_UPDATE(_write_file_total_size, meta_size);
+    if (_resource_ctx) {
+        _resource_ctx->io_context()->update_spill_write_bytes_to_local_storage(meta_size);
+    }
+    if (_write_file_current_size) {
+        COUNTER_UPDATE(_write_file_current_size, meta_size);
+    }
+    _data_dir->update_spill_data_usage(meta_size);
+    ExecEnv::GetInstance()->spill_file_mgr()->update_spill_write_bytes(meta_size);
+    // Incrementally update SpillFile's accounting so gc() can always
+    // decrement the correct amount, even if close() is never called.
+    if (spill_file) {
+        spill_file->update_written_bytes(meta_size);
+    }
+
+    RETURN_IF_ERROR(_file_writer->close());
+    _file_writer.reset();
+
+    // Advance to next part
+    ++_current_part_index;
+    ++_total_parts;
+    if (spill_file) {
+        spill_file->increment_part_count();
+    }
+    _part_written_blocks = 0;
+    _part_written_bytes = 0;
+    _part_max_sub_block_size = 0;
+    _part_meta.clear();
+
+    return Status::OK();
+}
+
+Status SpillFileWriter::_rotate_if_needed(const std::shared_ptr<SpillFile>& spill_file) {
+    if (_file_writer && _part_written_bytes >= _max_part_size) {
+        RETURN_IF_ERROR(_close_current_part(spill_file));
+    }
+    return Status::OK();
+}
+
+Status SpillFileWriter::write_block(RuntimeState* state, const Block& block) {
+    DCHECK(!_closed);
+
+    // Lock the SpillFile to ensure it is still alive. If it has already been
+    // destroyed (gc'd), we must not write any more data because the disk
+    // accounting would be out of sync.
+    auto spill_file = _spill_file_wptr.lock();
+    if (!spill_file) {
+        return Status::Error<INTERNAL_ERROR>(
+                "SpillFile has been destroyed, cannot write more data, spill_dir={}", _spill_dir);
+    }
+
+    // Lazily open the first part
+    if (!_file_writer) {
+        RETURN_IF_ERROR(_open_next_part());
+    }
+
+    DBUG_EXECUTE_IF("fault_inject::spill_file::spill_block", {
+        return Status::Error<INTERNAL_ERROR>("fault_inject spill_file spill_block failed");
+    });
+
+    auto rows = block.rows();
+    COUNTER_UPDATE(_write_rows_counter, rows);
+    COUNTER_UPDATE(_write_block_bytes_counter, block.bytes());
+
+    RETURN_IF_ERROR(_write_internal(block, spill_file));
+
+    // Auto-rotate if current part is full
+    return _rotate_if_needed(spill_file);
+}
+
+Status SpillFileWriter::close() {
+    if (_closed) {
+        return Status::OK();
+    }
+    _closed = true;
+
+    DBUG_EXECUTE_IF("fault_inject::spill_file::spill_eof", {
+        return Status::Error<INTERNAL_ERROR>("fault_inject spill_file spill_eof failed");
+    });
+
+    auto spill_file = _spill_file_wptr.lock();
+    RETURN_IF_ERROR(_close_current_part(spill_file));
+
+    if (spill_file) {
+        if (spill_file->_active_writer != this) {
+            return Status::Error<INTERNAL_ERROR>(
+                    "SpillFileWriter close() called but not registered as active writer, possible "
+                    "double close or logic error");
+        }
+        spill_file->finish_writing();
+    }
+
+    return Status::OK();
+}
+
+Status SpillFileWriter::_write_internal(const Block& block,
+                                        const std::shared_ptr<SpillFile>& spill_file) {
+    size_t uncompressed_bytes = 0, compressed_bytes = 0;
+
+    Status status;
+    std::string buff;
+    int64_t buff_size {0};
+
+    if (block.rows() > 0) {
+        {
+            PBlock pblock;
+            SCOPED_TIMER(_serialize_timer);
+            int64_t compressed_time = 0;
+            status = block.serialize(
+                    BeExecVersionManager::get_newest_version(), &pblock, &uncompressed_bytes,
+                    &compressed_bytes, &compressed_time,
+                    segment_v2::CompressionTypePB::ZSTD); // ZSTD for better compression ratio
+            RETURN_IF_ERROR(status);
+            int64_t pblock_mem = pblock.ByteSizeLong();
+            COUNTER_UPDATE(_memory_used_counter, pblock_mem);
+            Defer defer {[&]() { COUNTER_UPDATE(_memory_used_counter, -pblock_mem); }};
+            if (!pblock.SerializeToString(&buff)) {
+                return Status::Error<ErrorCode::SERIALIZE_PROTOBUF_ERROR>(
+                        "serialize spill data error. [path={}]", _current_part_path);
+            }
+            buff_size = buff.size();
+            COUNTER_UPDATE(_memory_used_counter, buff_size);
+            Defer defer2 {[&]() { COUNTER_UPDATE(_memory_used_counter, -buff_size); }};
+        }
+        if (_data_dir->reach_capacity_limit(buff_size)) {
+            return Status::Error<ErrorCode::DISK_REACH_CAPACITY_LIMIT>(
+                    "spill data total size exceed limit, path: {}, size limit: {}, spill data "
+                    "size: {}",
+                    _data_dir->path(),
+                    PrettyPrinter::print_bytes(_data_dir->get_spill_data_limit()),
+                    PrettyPrinter::print_bytes(_data_dir->get_spill_data_bytes()));
+        }
+
+        {
+            Defer defer {[&]() {
+                if (status.ok()) {
+                    _data_dir->update_spill_data_usage(buff_size);
+                    ExecEnv::GetInstance()->spill_file_mgr()->update_spill_write_bytes(buff_size);
+
+                    _part_max_sub_block_size =
+                            std::max(_part_max_sub_block_size, (size_t)buff_size);
+
+                    _part_meta.append((const char*)&_part_written_bytes, sizeof(size_t));
+                    COUNTER_UPDATE(_write_file_total_size, buff_size);
+                    if (_resource_ctx) {
+                        _resource_ctx->io_context()->update_spill_write_bytes_to_local_storage(
+                                buff_size);
+                    }
+                    if (_write_file_current_size) {
+                        COUNTER_UPDATE(_write_file_current_size, buff_size);
+                    }
+                    COUNTER_UPDATE(_write_block_counter, 1);
+                    _part_written_bytes += buff_size;
+                    _total_written_bytes += buff_size;
+                    ++_part_written_blocks;
+                    // Incrementally update SpillFile so gc() can always
+                    // decrement the correct amount from _data_dir.
+                    spill_file->update_written_bytes(buff_size);
+                }
+            }};
+            {
+                SCOPED_TIMER(_write_file_timer);
+                status = _file_writer->append(buff);
+                RETURN_IF_ERROR(status);
+            }
+        }
+    }
+
+    return status;
+}
+
+} // namespace doris
\ No newline at end of file
diff --git a/be/src/exec/spill/spill_file_writer.h b/be/src/exec/spill/spill_file_writer.h
new file mode 100644
index 00000000000..ba83ca8a546
--- /dev/null
+++ b/be/src/exec/spill/spill_file_writer.h
@@ -0,0 +1,114 @@
+// 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.
+
+#pragma once
+
+#include <atomic>
+#include <memory>
+#include <string>
+
+#include "core/block/block.h"
+#include "io/fs/file_writer.h"
+#include "runtime/runtime_profile.h"
+#include "runtime/workload_management/resource_context.h"
+namespace doris {
+#include "common/compile_check_begin.h"
+class RuntimeState;
+
+class SpillDataDir;
+class SpillFile;
+
+/// SpillFileWriter writes blocks to a SpillFile, automatically managing
+/// part-file rotation when a part exceeds the configured size threshold
+/// (config::spill_file_part_size_bytes).
+///
+/// Usage:
+///   SpillFileWriterSPtr writer;
+///   RETURN_IF_ERROR(spill_file->create_writer(state, profile, writer));
+///   RETURN_IF_ERROR(writer->write_block(state, block));
+///   RETURN_IF_ERROR(writer->close());
+///
+/// Part rotation is fully internal. Each part file has its own footer with
+/// block offset metadata. Parts are named 0, 1, 2, ... within the SpillFile's
+/// directory.
+class SpillFileWriter {
+public:
+    SpillFileWriter(const std::shared_ptr<SpillFile>& spill_file, RuntimeState* state,
+                    RuntimeProfile* profile, SpillDataDir* data_dir, const std::string& spill_dir);
+
+    ~SpillFileWriter();
+
+    /// Write a block. Automatically opens the first part, splits large blocks,
+    /// and rotates to a new part when the current one exceeds max_part_size.
+    Status write_block(RuntimeState* state, const Block& block);
+
+    /// Finalize: close the current part, record cumulative stats in SpillFile.
+    /// After close(), no more writes are allowed.
+    Status close();
+
+private:
+    /// Open the next part file (spill_dir/{_current_part_index}).
+    Status _open_next_part();
+
+    /// Close the current part: write footer, close FileWriter, update stats.
+    Status _close_current_part(const std::shared_ptr<SpillFile>& spill_file);
+
+    /// If current part size >= _max_part_size, close it.
+    Status _rotate_if_needed(const std::shared_ptr<SpillFile>& spill_file);
+
+    /// Serialize and write a single block to the current part.
+    Status _write_internal(const Block& block, const std::shared_ptr<SpillFile>& spill_file);
+
+    // ── Back-reference ──
+    std::weak_ptr<SpillFile> _spill_file_wptr; // weak ref; use lock() in close()
+
+    // ── Configuration ──
+    SpillDataDir* _data_dir = nullptr;
+    std::string _spill_dir;
+    int64_t _max_part_size;
+
+    // ── Current part state (reset on rotation) ──
+    size_t _current_part_index = 0;
+    std::string _current_part_path;
+    std::unique_ptr<doris::io::FileWriter> _file_writer;
+    size_t _part_written_blocks = 0;
+    int64_t _part_written_bytes = 0;
+    size_t _part_max_sub_block_size = 0;
+    std::string _part_meta;
+
+    // ── Cumulative state ──
+    int64_t _total_written_bytes = 0;
+    size_t _total_parts = 0;
+    bool _closed = false;
+
+    // ── Counters ──
+    RuntimeProfile::Counter* _write_file_timer = nullptr;
+    RuntimeProfile::Counter* _serialize_timer = nullptr;
+    RuntimeProfile::Counter* _write_block_counter = nullptr;
+    RuntimeProfile::Counter* _write_block_bytes_counter = nullptr;
+    RuntimeProfile::Counter* _write_file_total_size = nullptr;
+    RuntimeProfile::Counter* _write_file_current_size = nullptr;
+    RuntimeProfile::Counter* _write_rows_counter = nullptr;
+    RuntimeProfile::Counter* _memory_used_counter = nullptr;
+    RuntimeProfile::Counter* _total_file_count = nullptr;
+
+    std::shared_ptr<ResourceContext> _resource_ctx = nullptr;
+};
+using SpillFileWriterSPtr = std::shared_ptr<SpillFileWriter>;
+} // namespace doris
+
+#include "common/compile_check_end.h"
diff --git a/be/src/exec/spill/spill_reader.cpp b/be/src/exec/spill/spill_reader.cpp
deleted file mode 100644
index 4604d93cdf1..00000000000
--- a/be/src/exec/spill/spill_reader.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-// 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 "exec/spill/spill_reader.h"
-
-#include <glog/logging.h>
-
-#include <algorithm>
-
-#include "common/cast_set.h"
-#include "common/exception.h"
-#include "core/block/block.h"
-#include "exec/spill/spill_stream_manager.h"
-#include "io/file_factory.h"
-#include "io/fs/file_reader.h"
-#include "io/fs/local_file_system.h"
-#include "runtime/exec_env.h"
-#include "util/slice.h"
-namespace doris {
-#include "common/compile_check_begin.h"
-namespace io {
-class FileSystem;
-} // namespace io
-
-Status SpillReader::open() {
-    if (file_reader_) {
-        return Status::OK();
-    }
-
-    SCOPED_TIMER(_read_file_timer);
-
-    COUNTER_UPDATE(_read_file_count, 1);
-
-    RETURN_IF_ERROR(io::global_local_filesystem()->open_file(file_path_, &file_reader_));
-
-    size_t file_size = file_reader_->size();
-    DCHECK(file_size >= 16); // max_sub_block_size, block count
-
-    Slice result((char*)&block_count_, sizeof(size_t));
-
-    size_t total_read_bytes = 0;
-    // read block count
-    size_t bytes_read = 0;
-    RETURN_IF_ERROR(file_reader_->read_at(file_size - sizeof(size_t), result, &bytes_read));
-    DCHECK(bytes_read == 8); // max_sub_block_size, block count
-    total_read_bytes += bytes_read;
-    if (_resource_ctx) {
-        _resource_ctx->io_context()->update_spill_write_bytes_to_local_storage(bytes_read);
-    }
-
-    // read max sub block size
-    bytes_read = 0;
-    result.data = (char*)&max_sub_block_size_;
-    RETURN_IF_ERROR(file_reader_->read_at(file_size - sizeof(size_t) * 2, result, &bytes_read));
-    DCHECK(bytes_read == 8); // max_sub_block_size, block count
-    total_read_bytes += bytes_read;
-    if (_resource_ctx) {
-        _resource_ctx->io_context()->update_spill_write_bytes_to_local_storage(bytes_read);
-    }
-
-    size_t buff_size = std::max(block_count_ * sizeof(size_t), max_sub_block_size_);
-    read_buff_.reserve(buff_size);
-
-    // read block start offsets
-    size_t read_offset = file_size - (block_count_ + 2) * sizeof(size_t);
-    result.data = read_buff_.data();
-    result.size = block_count_ * sizeof(size_t);
-
-    RETURN_IF_ERROR(file_reader_->read_at(read_offset, result, &bytes_read));
-    DCHECK(bytes_read == block_count_ * sizeof(size_t));
-    total_read_bytes += bytes_read;
-    COUNTER_UPDATE(_read_file_size, total_read_bytes);
-    ExecEnv::GetInstance()->spill_stream_mgr()->update_spill_read_bytes(total_read_bytes);
-    if (_resource_ctx) {
-        _resource_ctx->io_context()->update_spill_read_bytes_from_local_storage(bytes_read);
-    }
-
-    block_start_offsets_.resize(block_count_ + 1);
-    for (size_t i = 0; i < block_count_; ++i) {
-        block_start_offsets_[i] = *(size_t*)(result.data + i * sizeof(size_t));
-    }
-    block_start_offsets_[block_count_] = file_size - (block_count_ + 2) * sizeof(size_t);
-
-    return Status::OK();
-}
-
-void SpillReader::seek(size_t block_index) {
-    DCHECK_LT(block_index, block_count_);
-    read_block_index_ = block_index;
-}
-
-Status SpillReader::read(Block* block, bool* eos) {
-    DCHECK(file_reader_);
-    block->clear_column_data();
-
-    if (read_block_index_ >= block_count_) {
-        *eos = true;
-        return Status::OK();
-    }
-
-    size_t bytes_to_read =
-            block_start_offsets_[read_block_index_ + 1] - block_start_offsets_[read_block_index_];
-
-    if (bytes_to_read == 0) {
-        ++read_block_index_;
-        return Status::OK();
-    }
-
-    Slice result(read_buff_.data(), bytes_to_read);
-    size_t bytes_read = 0;
-    {
-        SCOPED_TIMER(_read_file_timer);
-        RETURN_IF_ERROR(file_reader_->read_at(block_start_offsets_[read_block_index_], result,
-                                              &bytes_read));
-    }
-    DCHECK(bytes_read == bytes_to_read);
-
-    if (bytes_read > 0) {
-        COUNTER_UPDATE(_read_file_size, bytes_read);
-        ExecEnv::GetInstance()->spill_stream_mgr()->update_spill_read_bytes(bytes_read);
-        if (_resource_ctx) {
-            _resource_ctx->io_context()->update_spill_read_bytes_from_local_storage(bytes_read);
-        }
-        COUNTER_UPDATE(_read_block_count, 1);
-        {
-            SCOPED_TIMER(_deserialize_timer);
-            if (!pb_block_.ParseFromArray(result.data, cast_set<int>(result.size))) {
-                return Status::InternalError("Failed to read spilled block");
-            }
-            size_t uncompressed_size = 0;
-            int64_t uncompressed_time = 0;
-            RETURN_IF_ERROR(block->deserialize(pb_block_, &uncompressed_size, &uncompressed_time));
-        }
-        COUNTER_UPDATE(_read_block_data_size, block->bytes());
-        COUNTER_UPDATE(_read_rows_count, block->rows());
-    } else {
-        block->clear_column_data();
-    }
-
-    ++read_block_index_;
-
-    return Status::OK();
-}
-
-Status SpillReader::close() {
-    if (!file_reader_) {
-        return Status::OK();
-    }
-    (void)file_reader_->close();
-    file_reader_.reset();
-    return Status::OK();
-}
-
-} // namespace doris
\ No newline at end of file
diff --git a/be/src/exec/spill/spill_reader.h b/be/src/exec/spill/spill_reader.h
deleted file mode 100644
index d787cf17354..00000000000
--- a/be/src/exec/spill/spill_reader.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// 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.
-
-#pragma once
-
-#include <gen_cpp/data.pb.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "common/status.h"
-#include "core/pod_array.h"
-#include "core/pod_array_fwd.h"
-#include "io/fs/file_reader_writer_fwd.h"
-#include "runtime/runtime_profile.h"
-#include "runtime/workload_management/resource_context.h"
-
-namespace doris {
-#include "common/compile_check_begin.h"
-class Block;
-class SpillReader {
-public:
-    SpillReader(std::shared_ptr<ResourceContext> resource_context, int64_t stream_id,
-                std::string file_path)
-            : stream_id_(stream_id),
-              file_path_(std::move(file_path)),
-              _resource_ctx(std::move(resource_context)) {}
-
-    ~SpillReader() { (void)close(); }
-
-    Status open();
-
-    Status close();
-
-    Status read(Block* block, bool* eos);
-
-    void seek(size_t block_index);
-
-    int64_t get_id() const { return stream_id_; }
-
-    std::string get_path() const { return file_path_; }
-
-    size_t block_count() const { return block_count_; }
-
-    void set_counters(RuntimeProfile* operator_profile) {
-        RuntimeProfile* custom_profile = operator_profile->get_child("CustomCounters");
-        DCHECK(custom_profile != nullptr);
-        _read_file_timer = custom_profile->get_counter("SpillReadFileTime");
-        _deserialize_timer = custom_profile->get_counter("SpillReadDeserializeBlockTime");
-        _read_block_count = custom_profile->get_counter("SpillReadBlockCount");
-        _read_block_data_size = custom_profile->get_counter("SpillReadBlockBytes");
-        _read_file_size = custom_profile->get_counter("SpillReadFileBytes");
-        _read_rows_count = custom_profile->get_counter("SpillReadRows");
-        _read_file_count = custom_profile->get_counter("SpillReadFileCount");
-    }
-
-private:
-    int64_t stream_id_;
-    std::string file_path_;
-    io::FileReaderSPtr file_reader_;
-
-    size_t block_count_ = 0;
-    size_t read_block_index_ = 0;
-    size_t max_sub_block_size_ = 0;
-    PaddedPODArray<char> read_buff_;
-    std::vector<size_t> block_start_offsets_;
-
-    PBlock pb_block_;
-
-    RuntimeProfile::Counter* _read_file_timer = nullptr;
-    RuntimeProfile::Counter* _deserialize_timer = nullptr;
-    RuntimeProfile::Counter* _read_block_count = nullptr;
-    RuntimeProfile::Counter* _read_block_data_size = nullptr;
-    RuntimeProfile::Counter* _read_file_size = nullptr;
-    RuntimeProfile::Counter* _read_rows_count = nullptr;
-    RuntimeProfile::Counter* _read_file_count = nullptr;
-
-    std::shared_ptr<ResourceContext> _resource_ctx = nullptr;
-};
-
-using SpillReaderUPtr = std::unique_ptr<SpillReader>;
-
-} // namespace doris
-#include "common/compile_check_end.h"
diff --git a/be/src/exec/spill/spill_repartitioner.cpp b/be/src/exec/spill/spill_repartitioner.cpp
new file mode 100644
index 00000000000..de7d225c69e
--- /dev/null
+++ b/be/src/exec/spill/spill_repartitioner.cpp
@@ -0,0 +1,371 @@
+// 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 "exec/spill/spill_repartitioner.h"
+
+#include <glog/logging.h>
+
+#include <limits>
+#include <memory>
+#include <vector>
+
+#include "core/block/block.h"
+#include "core/column/column.h"
+#include "exec/partitioner/partitioner.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_manager.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
+#include "runtime/exec_env.h"
+#include "runtime/runtime_profile.h"
+#include "runtime/runtime_state.h"
+#include "util/uid_util.h"
+
+namespace doris {
+#include "common/compile_check_begin.h"
+
+void SpillRepartitioner::init(std::unique_ptr<PartitionerBase> partitioner, RuntimeProfile* profile,
+                              int fanout, int repartition_level) {
+    _partitioner = std::move(partitioner);
+    _use_column_index_mode = false;
+    _fanout = fanout;
+    _repartition_level = repartition_level;
+    _operator_profile = profile;
+    _repartition_timer = ADD_TIMER_WITH_LEVEL(profile, "SpillRepartitionTime", 1);
+    _repartition_rows = ADD_COUNTER_WITH_LEVEL(profile, "SpillRepartitionRows", TUnit::UNIT, 1);
+}
+
+void SpillRepartitioner::init_with_key_columns(std::vector<size_t> key_column_indices,
+                                               std::vector<DataTypePtr> key_data_types,
+                                               RuntimeProfile* profile, int fanout,
+                                               int repartition_level) {
+    _key_column_indices = std::move(key_column_indices);
+    _key_data_types = std::move(key_data_types);
+    _use_column_index_mode = true;
+    _partitioner.reset();
+    _fanout = fanout;
+    _repartition_level = repartition_level;
+    _operator_profile = profile;
+    _repartition_timer = ADD_TIMER_WITH_LEVEL(profile, "SpillRepartitionTime", 1);
+    _repartition_rows = ADD_COUNTER_WITH_LEVEL(profile, "SpillRepartitionRows", TUnit::UNIT, 1);
+}
+
+Status SpillRepartitioner::setup_output(RuntimeState* state,
+                                        std::vector<SpillFileSPtr>& output_spill_files) {
+    DCHECK_EQ(output_spill_files.size(), _fanout);
+    _output_spill_files = &output_spill_files;
+    _output_writers.resize(_fanout);
+    for (int i = 0; i < _fanout; ++i) {
+        RETURN_IF_ERROR(
+                output_spill_files[i]->create_writer(state, _operator_profile, _output_writers[i]));
+    }
+    // Reset reader state from any previous repartition session
+    _input_reader.reset();
+    _current_input_file.reset();
+    return Status::OK();
+}
+
+Status SpillRepartitioner::repartition(RuntimeState* state, SpillFileSPtr& input_spill_file,
+                                       bool* done) {
+    DCHECK(_output_spill_files != nullptr) << "setup_output() must be called first";
+    SCOPED_TIMER(_repartition_timer);
+
+    *done = false;
+    size_t accumulated_bytes = 0;
+
+    // Create or reuse input reader. If the input file changed, create a new reader.
+    if (_current_input_file != input_spill_file) {
+        _current_input_file = input_spill_file;
+        _input_reader = input_spill_file->create_reader(state, _operator_profile);
+        RETURN_IF_ERROR(_input_reader->open());
+    }
+
+    // Per-partition write buffers to batch small writes
+    std::vector<std::unique_ptr<MutableBlock>> output_buffers(_fanout);
+
+    bool eos = false;
+    while (!eos && !state->is_cancelled()) {
+        Block block;
+        RETURN_IF_ERROR(_input_reader->read(&block, &eos));
+
+        if (block.empty()) {
+            continue;
+        }
+
+        accumulated_bytes += block.allocated_bytes();
+        COUNTER_UPDATE(_repartition_rows, block.rows());
+
+        if (_use_column_index_mode) {
+            RETURN_IF_ERROR(_route_block_by_columns(state, block, output_buffers));
+        } else {
+            RETURN_IF_ERROR(_route_block(state, block, output_buffers));
+        }
+
+        // Yield after processing MAX_BATCH_BYTES to let pipeline scheduler re-schedule
+        if (accumulated_bytes >= MAX_BATCH_BYTES && !eos) {
+            break;
+        }
+    }
+
+    // Flush all remaining buffers
+    RETURN_IF_ERROR(_flush_all_buffers(state, output_buffers, /*force=*/true));
+
+    if (eos) {
+        *done = true;
+        // Reset reader for this input file
+        _input_reader.reset();
+        _current_input_file.reset();
+    }
+
+    return Status::OK();
+}
+
+Status SpillRepartitioner::repartition(RuntimeState* state, SpillFileReaderSPtr& reader,
+                                       bool* done) {
+    DCHECK(_output_spill_files != nullptr) << "setup_output() must be called first";
+    DCHECK(reader != nullptr) << "reader must not be null";
+    SCOPED_TIMER(_repartition_timer);
+
+    *done = false;
+    size_t accumulated_bytes = 0;
+
+    // Per-partition write buffers to batch small writes
+    std::vector<std::unique_ptr<MutableBlock>> output_buffers(_fanout);
+
+    bool eos = false;
+    while (!eos && !state->is_cancelled()) {
+        Block block;
+        RETURN_IF_ERROR(reader->read(&block, &eos));
+
+        if (block.empty()) {
+            continue;
+        }
+
+        accumulated_bytes += block.allocated_bytes();
+        COUNTER_UPDATE(_repartition_rows, block.rows());
+
+        if (_use_column_index_mode) {
+            RETURN_IF_ERROR(_route_block_by_columns(state, block, output_buffers));
+        } else {
+            RETURN_IF_ERROR(_route_block(state, block, output_buffers));
+        }
+
+        // Yield after processing MAX_BATCH_BYTES to let pipeline scheduler re-schedule
+        if (accumulated_bytes >= MAX_BATCH_BYTES && !eos) {
+            break;
+        }
+    }
+
+    // Flush all remaining buffers
+    RETURN_IF_ERROR(_flush_all_buffers(state, output_buffers, /*force=*/true));
+
+    if (eos) {
+        *done = true;
+        reader.reset();
+    }
+
+    return Status::OK();
+}
+
+Status SpillRepartitioner::route_block(RuntimeState* state, Block& block) {
+    DCHECK(_output_spill_files != nullptr) << "setup_output() must be called first";
+    if (UNLIKELY(_output_spill_files == nullptr)) {
+        return Status::InternalError("SpillRepartitioner::setup_output() must be called first");
+    }
+    SCOPED_TIMER(_repartition_timer);
+
+    if (block.empty()) {
+        return Status::OK();
+    }
+
+    COUNTER_UPDATE(_repartition_rows, block.rows());
+
+    std::vector<std::unique_ptr<MutableBlock>> output_buffers(_fanout);
+    if (_use_column_index_mode) {
+        RETURN_IF_ERROR(_route_block_by_columns(state, block, output_buffers));
+    } else {
+        RETURN_IF_ERROR(_route_block(state, block, output_buffers));
+    }
+    RETURN_IF_ERROR(_flush_all_buffers(state, output_buffers, /*force=*/true));
+    return Status::OK();
+}
+
+Status SpillRepartitioner::finalize() {
+    DCHECK(_output_spill_files != nullptr) << "setup_output() must be called first";
+    if (UNLIKELY(_output_spill_files == nullptr)) {
+        return Status::InternalError("SpillRepartitioner::setup_output() must be called first");
+    }
+    // Close all writers (Writer::close() automatically updates SpillFile stats)
+    for (int i = 0; i < _fanout; ++i) {
+        if (_output_writers[i]) {
+            RETURN_IF_ERROR(_output_writers[i]->close());
+        }
+    }
+    _output_writers.clear();
+    _output_spill_files = nullptr;
+    _input_reader.reset();
+    _current_input_file.reset();
+    return Status::OK();
+}
+
+Status SpillRepartitioner::create_output_spill_files(
+        RuntimeState* state, int node_id, const std::string& label_prefix, int fanout,
+        std::vector<SpillFileSPtr>& output_spill_files) {
+    output_spill_files.resize(fanout);
+    for (int i = 0; i < fanout; ++i) {
+        auto relative_path = fmt::format("{}/{}_sub{}-{}-{}-{}", print_id(state->query_id()),
+                                         label_prefix, i, node_id, state->task_id(),
+                                         ExecEnv::GetInstance()->spill_file_mgr()->next_id());
+        RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_file_mgr()->create_spill_file(
+                relative_path, output_spill_files[i]));
+    }
+    return Status::OK();
+}
+
+Status SpillRepartitioner::_route_block(
+        RuntimeState* state, Block& block,
+        std::vector<std::unique_ptr<MutableBlock>>& output_buffers) {
+    // Compute raw hash values for every row in the block.
+    RETURN_IF_ERROR(_partitioner->do_partitioning(state, &block));
+    const auto& hash_vals = _partitioner->get_channel_ids();
+    const auto rows = block.rows();
+
+    // Build per-partition row index lists
+    std::vector<std::vector<uint32_t>> partition_row_indexes(_fanout);
+    for (uint32_t i = 0; i < rows; ++i) {
+        auto partition_idx = _map_hash_to_partition(hash_vals[i]);
+        partition_row_indexes[partition_idx].emplace_back(i);
+    }
+
+    // Scatter rows into per-partition buffers
+    for (int p = 0; p < _fanout; ++p) {
+        if (partition_row_indexes[p].empty()) {
+            continue;
+        }
+
+        // Lazily initialize the buffer
+        if (!output_buffers[p]) {
+            output_buffers[p] = MutableBlock::create_unique(block.clone_empty());
+        }
+
+        RETURN_IF_ERROR(output_buffers[p]->add_rows(
+                &block, partition_row_indexes[p].data(),
+                partition_row_indexes[p].data() + partition_row_indexes[p].size()));
+
+        // Flush large buffers immediately to keep memory bounded
+        if (output_buffers[p]->allocated_bytes() >= MAX_BATCH_BYTES) {
+            RETURN_IF_ERROR(_flush_buffer(state, p, output_buffers[p]));
+        }
+    }
+
+    return Status::OK();
+}
+
+Status SpillRepartitioner::_route_block_by_columns(
+        RuntimeState* state, Block& block,
+        std::vector<std::unique_ptr<MutableBlock>>& output_buffers) {
+    const auto rows = block.rows();
+    if (rows == 0) {
+        return Status::OK();
+    }
+
+    // Compute CRC32 hash on key columns
+    std::vector<uint32_t> hash_vals(rows, 0);
+    auto* __restrict hashes = hash_vals.data();
+    for (size_t j = 0; j < _key_column_indices.size(); ++j) {
+        auto col_idx = _key_column_indices[j];
+        DCHECK_LT(col_idx, block.columns());
+        const auto& column = block.get_by_position(col_idx).column;
+        column->update_crcs_with_value(hashes, _key_data_types[j]->get_primitive_type(),
+                                       static_cast<uint32_t>(rows));
+    }
+
+    // Map hash values to output channels with level-aware mixing.
+    for (size_t i = 0; i < rows; ++i) {
+        hashes[i] = _map_hash_to_partition(hashes[i]);
+    }
+
+    // Build per-partition row index lists
+    std::vector<std::vector<uint32_t>> partition_row_indexes(_fanout);
+    for (uint32_t i = 0; i < rows; ++i) {
+        partition_row_indexes[hashes[i]].emplace_back(i);
+    }
+
+    // Scatter rows into per-partition buffers
+    for (int p = 0; p < _fanout; ++p) {
+        if (partition_row_indexes[p].empty()) {
+            continue;
+        }
+
+        if (!output_buffers[p]) {
+            output_buffers[p] = MutableBlock::create_unique(block.clone_empty());
+        }
+
+        RETURN_IF_ERROR(output_buffers[p]->add_rows(
+                &block, partition_row_indexes[p].data(),
+                partition_row_indexes[p].data() + partition_row_indexes[p].size()));
+
+        if (output_buffers[p]->allocated_bytes() >= MAX_BATCH_BYTES) {
+            RETURN_IF_ERROR(_flush_buffer(state, p, output_buffers[p]));
+        }
+    }
+
+    return Status::OK();
+}
+
+Status SpillRepartitioner::_flush_buffer(RuntimeState* state, int partition_idx,
+                                         std::unique_ptr<MutableBlock>& buffer) {
+    if (!buffer || buffer->rows() == 0) {
+        return Status::OK();
+    }
+    DCHECK(partition_idx < _fanout && _output_writers[partition_idx]);
+    if (UNLIKELY(partition_idx >= _fanout || !_output_writers[partition_idx])) {
+        return Status::InternalError(
+                "SpillRepartitioner output writer is not initialized for partition {}",
+                partition_idx);
+    }
+    auto out_block = buffer->to_block();
+    buffer.reset();
+    return _output_writers[partition_idx]->write_block(state, out_block);
+}
+
+Status SpillRepartitioner::_flush_all_buffers(
+        RuntimeState* state, std::vector<std::unique_ptr<MutableBlock>>& output_buffers,
+        bool force) {
+    for (int i = 0; i < _fanout; ++i) {
+        if (!output_buffers[i] || output_buffers[i]->rows() == 0) {
+            continue;
+        }
+        if (force || output_buffers[i]->allocated_bytes() >= MAX_BATCH_BYTES) {
+            RETURN_IF_ERROR(_flush_buffer(state, i, output_buffers[i]));
+        }
+    }
+    return Status::OK();
+}
+
+uint32_t SpillRepartitioner::_map_hash_to_partition(uint32_t hash) const {
+    DCHECK_GT(_fanout, 0);
+    // Use a level-dependent salt so each repartition level has a different
+    // projection from hash-space to partition-space.
+    constexpr uint32_t LEVEL_SALT_BASE = 0x9E3779B9U;
+    auto salt = static_cast<uint32_t>(_repartition_level + 1) * LEVEL_SALT_BASE;
+    auto mixed = crc32c_shuffle_mix(hash ^ salt);
+    return ((mixed >> 16) | (mixed << 16)) % static_cast<uint32_t>(_fanout);
+}
+
+#include "common/compile_check_end.h"
+} // namespace doris
diff --git a/be/src/exec/spill/spill_repartitioner.h b/be/src/exec/spill/spill_repartitioner.h
new file mode 100644
index 00000000000..e100a2eeb95
--- /dev/null
+++ b/be/src/exec/spill/spill_repartitioner.h
@@ -0,0 +1,161 @@
+// 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.
+
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+#include "common/status.h"
+#include "core/data_type/data_type.h"
+#include "exec/spill/spill_file.h"
+#include "exec/spill/spill_file_reader.h"
+#include "exec/spill/spill_file_writer.h"
+
+namespace doris {
+class RuntimeState;
+class RuntimeProfile;
+
+class Block;
+class PartitionerBase;
+
+/// SpillRepartitioner reads data from an input SpillFile and redistributes it
+/// into FANOUT output SpillFiles by computing hash on key columns.
+///
+/// This is the core building block for multi-level spill partitioning used by both
+/// Hash Join and Aggregation operators.
+///
+/// Two modes of operation:
+/// 1. Partitioner mode (init): Uses a PartitionerBase with expression contexts to
+///    compute hash. Suitable for Hash Join where blocks match the child's row descriptor.
+/// 2. Column-index mode (init_with_key_columns): Computes CRC32 hash directly on
+///    specified column indices. Suitable for Aggregation where spill blocks have a
+///    different schema (key columns at fixed positions 0..N-1).
+///
+/// For repartitioning, hash computation and final channel mapping are separated:
+/// - a partitioner can provide either direct channel ids or raw hash values
+///   (e.g. SpillRePartitionChannelIds returns raw hash),
+/// - SpillRepartitioner then applies the final channel mapping strategy.
+/// This keeps repartition policy centralized and allows level-aware mapping.
+///
+/// Processing is incremental: each call to repartition() processes up to MAX_BATCH_BYTES
+/// (32 MB) of data and then returns, allowing the pipeline scheduler to yield and
+/// re-schedule. The caller should loop calling repartition() until `done` is true.
+///
+/// Usage pattern:
+///   // 1. Initialize
+///   repartitioner.init(...) or repartitioner.init_with_key_columns(...)
+///   // 2. Create output files and set up writers
+///   SpillRepartitioner::create_output_spill_files(state, ..., output_files, fanout);
+///   repartitioner.setup_output(state, output_files);
+///   // 3. Route blocks and/or repartition files
+///   repartitioner.route_block(state, block);         // from hash table
+///   repartitioner.repartition(state, input_file, &done);  // from spill file
+///   // 4. Finalize
+///   repartitioner.finalize();
+class SpillRepartitioner {
+public:
+    static constexpr int MAX_DEPTH = 8;
+    static constexpr size_t MAX_BATCH_BYTES = 32 * 1024 * 1024; // 32 MB yield threshold
+
+    SpillRepartitioner() = default;
+    ~SpillRepartitioner() = default;
+
+    /// Initialize the repartitioner with a partitioner (for Hash Join).
+    void init(std::unique_ptr<PartitionerBase> partitioner, RuntimeProfile* profile, int fanout,
+              int repartition_level);
+
+    /// Initialize the repartitioner with explicit key column indices (for Aggregation).
+    void init_with_key_columns(std::vector<size_t> key_column_indices,
+                               std::vector<DataTypePtr> key_data_types, RuntimeProfile* profile,
+                               int fanout, int repartition_level);
+
+    /// Set up output SpillFiles and create persistent writers for them.
+    /// Must be called before repartition() or route_block().
+    Status setup_output(RuntimeState* state, std::vector<SpillFileSPtr>& output_spill_files);
+
+    /// Repartition data from input_spill_file into output files.
+    /// The input reader is created lazily and persists across yield calls.
+    /// Call repeatedly until done == true.
+    Status repartition(RuntimeState* state, SpillFileSPtr& input_spill_file, bool* done);
+
+    /// Repartition data using an existing reader (continues from its current
+    /// position). Useful when the caller has already partially read the file
+    /// and wants to repartition only the remaining data without re-reading
+    /// from the beginning. Ownership of the reader is transferred on completion.
+    /// Call repeatedly until done == true.
+    Status repartition(RuntimeState* state, SpillFileReaderSPtr& reader, bool* done);
+
+    /// Route a single in-memory block into output files via persistent writers.
+    Status route_block(RuntimeState* state, Block& block);
+
+    /// Finalize: close all output writers and update SpillFile stats.
+    /// Also resets internal reader state.
+    Status finalize();
+
+    /// Create FANOUT output SpillFiles registered with the SpillFileManager.
+    static Status create_output_spill_files(RuntimeState* state, int node_id,
+                                            const std::string& label_prefix, int fanout,
+                                            std::vector<SpillFileSPtr>& output_spill_files);
+
+    int fanout() const { return _fanout; }
+
+private:
+    /// Route a block using the partitioner (Hash Join mode).
+    Status _route_block(RuntimeState* state, Block& block,
+                        std::vector<std::unique_ptr<MutableBlock>>& output_buffers);
+
+    /// Route a block using direct column-index hashing (Aggregation mode).
+    Status _route_block_by_columns(RuntimeState* state, Block& block,
+                                   std::vector<std::unique_ptr<MutableBlock>>& output_buffers);
+
+    Status _flush_buffer(RuntimeState* state, int partition_idx,
+                         std::unique_ptr<MutableBlock>& buffer);
+
+    Status _flush_all_buffers(RuntimeState* state,
+                              std::vector<std::unique_ptr<MutableBlock>>& output_buffers,
+                              bool force);
+
+    uint32_t _map_hash_to_partition(uint32_t hash) const;
+
+    // Partitioner mode (used by Hash Join)
+    std::unique_ptr<PartitionerBase> _partitioner;
+
+    // Column-index mode (used by Aggregation)
+    std::vector<size_t> _key_column_indices;
+    std::vector<DataTypePtr> _key_data_types;
+    bool _use_column_index_mode = false;
+
+    RuntimeProfile::Counter* _repartition_timer = nullptr;
+    RuntimeProfile::Counter* _repartition_rows = nullptr;
+    RuntimeProfile* _operator_profile = nullptr;
+    int _fanout = 8;
+    int _repartition_level = 0;
+
+    // ── Persistent state across repartition/route_block calls ──────
+    // Output writers (one per partition), created by setup_output()
+    std::vector<SpillFileWriterSPtr> _output_writers;
+    // Pointer to caller's output SpillFiles vector (for finalize)
+    std::vector<SpillFileSPtr>* _output_spill_files = nullptr;
+    // Input reader for repartition(), persists across yield calls
+    SpillFileReaderSPtr _input_reader;
+    SpillFileSPtr _current_input_file;
+};
+
+} // namespace doris
diff --git a/be/src/exec/spill/spill_stream.cpp b/be/src/exec/spill/spill_stream.cpp
deleted file mode 100644
index 07a7d85b116..00000000000
--- a/be/src/exec/spill/spill_stream.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-// 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 "exec/spill/spill_stream.h"
-
-#include <glog/logging.h>
-
-#include <memory>
-#include <mutex>
-#include <utility>
-
-#include "core/block/block.h"
-#include "exec/spill/spill_reader.h"
-#include "exec/spill/spill_stream_manager.h"
-#include "exec/spill/spill_writer.h"
-#include "io/fs/local_file_system.h"
-#include "runtime/exec_env.h"
-#include "runtime/query_context.h"
-#include "runtime/runtime_profile.h"
-#include "runtime/runtime_state.h"
-#include "runtime/thread_context.h"
-#include "util/debug_points.h"
-
-namespace doris {
-#include "common/compile_check_begin.h"
-SpillStream::SpillStream(RuntimeState* state, int64_t stream_id, SpillDataDir* data_dir,
-                         std::string spill_dir, size_t batch_rows, size_t batch_bytes,
-                         RuntimeProfile* operator_profile)
-        : state_(state),
-          stream_id_(stream_id),
-          data_dir_(data_dir),
-          spill_dir_(std::move(spill_dir)),
-          batch_rows_(batch_rows),
-          batch_bytes_(batch_bytes),
-          query_id_(state->query_id()),
-          profile_(operator_profile) {
-    RuntimeProfile* custom_profile = operator_profile->get_child("CustomCounters");
-    DCHECK(custom_profile != nullptr);
-    _total_file_count = custom_profile->get_counter("SpillWriteFileTotalCount");
-    _current_file_count = custom_profile->get_counter("SpillWriteFileCurrentCount");
-    _current_file_size = custom_profile->get_counter("SpillWriteFileCurrentBytes");
-}
-
-void SpillStream::update_shared_profiles(RuntimeProfile* source_op_profile) {
-    _current_file_count = source_op_profile->get_counter("SpillWriteFileCurrentCount");
-    _current_file_size = source_op_profile->get_counter("SpillWriteFileCurrentBytes");
-}
-
-SpillStream::~SpillStream() {
-    gc();
-}
-
-void SpillStream::gc() {
-    if (_current_file_size) {
-        COUNTER_UPDATE(_current_file_size, -total_written_bytes_);
-    }
-    bool exists = false;
-    auto status = io::global_local_filesystem()->exists(spill_dir_, &exists);
-    if (status.ok() && exists) {
-        if (_current_file_count) {
-            COUNTER_UPDATE(_current_file_count, -1);
-        }
-        auto query_gc_dir = data_dir_->get_spill_data_gc_path(print_id(query_id_));
-        status = io::global_local_filesystem()->create_directory(query_gc_dir);
-        DBUG_EXECUTE_IF("fault_inject::spill_stream::gc", {
-            status = Status::Error<INTERNAL_ERROR>("fault_inject spill_stream gc failed");
-        });
-        if (status.ok()) {
-            auto gc_dir = fmt::format("{}/{}", query_gc_dir,
-                                      std::filesystem::path(spill_dir_).filename().string());
-            status = io::global_local_filesystem()->rename(spill_dir_, gc_dir);
-        }
-        if (!status.ok()) {
-            LOG_EVERY_T(WARNING, 1) << fmt::format("failed to gc spill data, dir {}, error: {}",
-                                                   query_gc_dir, status.to_string());
-        }
-    }
-    // If QueryContext is destructed earlier than PipelineFragmentContext,
-    // spill_dir_ will be already moved to spill_gc directory.
-
-    // decrease spill data usage anyway, since in ~QueryContext() spill data of the query will be
-    // clean up as a last resort
-    data_dir_->update_spill_data_usage(-total_written_bytes_);
-    total_written_bytes_ = 0;
-}
-
-Status SpillStream::prepare() {
-    writer_ = std::make_unique<SpillWriter>(state_->get_query_ctx()->resource_ctx(), profile_,
-                                            stream_id_, batch_rows_, data_dir_, spill_dir_);
-    _set_write_counters(profile_);
-
-    reader_ = std::make_unique<SpillReader>(state_->get_query_ctx()->resource_ctx(), stream_id_,
-                                            writer_->get_file_path());
-
-    DBUG_EXECUTE_IF("fault_inject::spill_stream::prepare_spill", {
-        return Status::Error<INTERNAL_ERROR>("fault_inject spill_stream prepare_spill failed");
-    });
-    COUNTER_UPDATE(_total_file_count, 1);
-    if (_current_file_count) {
-        COUNTER_UPDATE(_current_file_count, 1);
-    }
-    return writer_->open();
-}
-
-SpillReaderUPtr SpillStream::create_separate_reader() const {
-    return std::make_unique<SpillReader>(state_->get_query_ctx()->resource_ctx(), stream_id_,
-                                         writer_->get_file_path());
-}
-
-const TUniqueId& SpillStream::query_id() const {
-    return query_id_;
-}
-
-const std::string& SpillStream::get_spill_root_dir() const {
-    return data_dir_->path();
-}
-
-Status SpillStream::spill_block(RuntimeState* state, const Block& block, bool eof) {
-    size_t written_bytes = 0;
-    DBUG_EXECUTE_IF("fault_inject::spill_stream::spill_block", {
-        return Status::Error<INTERNAL_ERROR>("fault_inject spill_stream spill_block failed");
-    });
-    RETURN_IF_ERROR(writer_->write(state, block, written_bytes));
-    if (eof) {
-        RETURN_IF_ERROR(spill_eof());
-    } else {
-        total_written_bytes_ = writer_->get_written_bytes();
-    }
-    return Status::OK();
-}
-
-Status SpillStream::spill_eof() {
-    DBUG_EXECUTE_IF("fault_inject::spill_stream::spill_eof", {
-        return Status::Error<INTERNAL_ERROR>("fault_inject spill_stream spill_eof failed");
-    });
-    auto status = writer_->close();
-    total_written_bytes_ = writer_->get_written_bytes();
-    writer_.reset();
-
-    if (status.ok()) {
-        _ready_for_reading = true;
-    }
-    return status;
-}
-
-Status SpillStream::read_next_block_sync(Block* block, bool* eos) {
-    DCHECK(reader_ != nullptr);
-    DCHECK(!_is_reading);
-    _is_reading = true;
-    Defer defer([this] { _is_reading = false; });
-
-    DBUG_EXECUTE_IF("fault_inject::spill_stream::read_next_block", {
-        return Status::Error<INTERNAL_ERROR>("fault_inject spill_stream read_next_block failed");
-    });
-    RETURN_IF_ERROR(reader_->open());
-    return reader_->read(block, eos);
-}
-
-} // namespace doris
diff --git a/be/src/exec/spill/spill_stream.h b/be/src/exec/spill/spill_stream.h
deleted file mode 100644
index 14420d2a6c9..00000000000
--- a/be/src/exec/spill/spill_stream.h
+++ /dev/null
@@ -1,108 +0,0 @@
-// 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.
-
-#pragma once
-#include <atomic>
-#include <future>
-#include <memory>
-
-#include "exec/spill/spill_reader.h"
-#include "exec/spill/spill_writer.h"
-
-namespace doris {
-#include "common/compile_check_begin.h"
-class RuntimeProfile;
-class ThreadPool;
-
-class Block;
-class SpillDataDir;
-
-class SpillStream {
-public:
-    // to avoid too many small file writes
-    static constexpr size_t MIN_SPILL_WRITE_BATCH_MEM = 32 * 1024;
-    static constexpr size_t MAX_SPILL_WRITE_BATCH_MEM = 32 * 1024 * 1024;
-    SpillStream(RuntimeState* state, int64_t stream_id, SpillDataDir* data_dir,
-                std::string spill_dir, size_t batch_rows, size_t batch_bytes,
-                RuntimeProfile* profile);
-
-    SpillStream() = delete;
-
-    ~SpillStream();
-
-    void gc();
-
-    int64_t id() const { return stream_id_; }
-
-    SpillDataDir* get_data_dir() const { return data_dir_; }
-    const std::string& get_spill_root_dir() const;
-
-    const std::string& get_spill_dir() const { return spill_dir_; }
-
-    int64_t get_written_bytes() const { return total_written_bytes_; }
-
-    Status spill_block(RuntimeState* state, const Block& block, bool eof);
-
-    Status spill_eof();
-
-    Status read_next_block_sync(Block* block, bool* eos);
-
-    void set_read_counters(RuntimeProfile* operator_profile) {
-        reader_->set_counters(operator_profile);
-    }
-
-    void update_shared_profiles(RuntimeProfile* source_op_profile);
-
-    SpillReaderUPtr create_separate_reader() const;
-
-    const TUniqueId& query_id() const;
-
-    bool ready_for_reading() const { return _ready_for_reading; }
-
-private:
-    friend class SpillStreamManager;
-
-    Status prepare();
-
-    void _set_write_counters(RuntimeProfile* profile) { writer_->set_counters(profile); }
-
-    RuntimeState* state_ = nullptr;
-    int64_t stream_id_;
-    SpillDataDir* data_dir_ = nullptr;
-    // Directory path format specified in SpillStreamManager::register_spill_stream:
-    // storage_root/spill/query_id/partitioned_hash_join-node_id-task_id-stream_id
-    std::string spill_dir_;
-    size_t batch_rows_;
-    size_t batch_bytes_;
-    int64_t total_written_bytes_ = 0;
-
-    std::atomic_bool _ready_for_reading = false;
-    std::atomic_bool _is_reading = false;
-
-    SpillWriterUPtr writer_;
-    SpillReaderUPtr reader_;
-
-    TUniqueId query_id_;
-
-    RuntimeProfile* profile_ = nullptr;
-    RuntimeProfile::Counter* _current_file_count = nullptr;
-    RuntimeProfile::Counter* _total_file_count = nullptr;
-    RuntimeProfile::Counter* _current_file_size = nullptr;
-};
-using SpillStreamSPtr = std::shared_ptr<SpillStream>;
-} // namespace doris
-#include "common/compile_check_end.h"
diff --git a/be/src/exec/spill/spill_writer.cpp b/be/src/exec/spill/spill_writer.cpp
deleted file mode 100644
index ce5bfa14215..00000000000
--- a/be/src/exec/spill/spill_writer.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-// 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 "exec/spill/spill_writer.h"
-
-#include "agent/be_exec_version_manager.h"
-#include "common/status.h"
-#include "exec/spill/spill_stream_manager.h"
-#include "io/fs/local_file_system.h"
-#include "io/fs/local_file_writer.h"
-#include "runtime/exec_env.h"
-#include "runtime/runtime_state.h"
-#include "runtime/thread_context.h"
-
-namespace doris {
-#include "common/compile_check_begin.h"
-Status SpillWriter::open() {
-    if (file_writer_) {
-        return Status::OK();
-    }
-    return io::global_local_filesystem()->create_file(file_path_, &file_writer_);
-}
-
-Status SpillWriter::close() {
-    if (closed_ || !file_writer_) {
-        return Status::OK();
-    }
-    closed_ = true;
-
-    meta_.append((const char*)&max_sub_block_size_, sizeof(max_sub_block_size_));
-    meta_.append((const char*)&written_blocks_, sizeof(written_blocks_));
-
-    // meta: block1 offset, block2 offset, ..., blockn offset, max_sub_block_size, n
-    {
-        SCOPED_TIMER(_write_file_timer);
-        RETURN_IF_ERROR(file_writer_->append(meta_));
-    }
-
-    total_written_bytes_ += meta_.size();
-    COUNTER_UPDATE(_write_file_total_size, meta_.size());
-    if (_resource_ctx) {
-        _resource_ctx->io_context()->update_spill_write_bytes_to_local_storage(meta_.size());
-    }
-    if (_write_file_current_size) {
-        COUNTER_UPDATE(_write_file_current_size, meta_.size());
-    }
-    data_dir_->update_spill_data_usage(meta_.size());
-    ExecEnv::GetInstance()->spill_stream_mgr()->update_spill_write_bytes(meta_.size());
-
-    RETURN_IF_ERROR(file_writer_->close());
-
-    file_writer_.reset();
-    return Status::OK();
-}
-
-Status SpillWriter::write(RuntimeState* state, const Block& block, size_t& written_bytes) {
-    written_bytes = 0;
-    DCHECK(file_writer_);
-    auto rows = block.rows();
-    COUNTER_UPDATE(_write_rows_counter, rows);
-    COUNTER_UPDATE(_write_block_bytes_counter, block.bytes());
-    // file format: block1, block2, ..., blockn, meta
-    if (rows <= batch_size_) {
-        return _write_internal(block, written_bytes);
-    } else {
-        auto tmp_block = block.clone_empty();
-        const auto& src_data = block.get_columns_with_type_and_name();
-
-        for (size_t row_idx = 0; row_idx < rows && !state->is_cancelled();) {
-            tmp_block.clear_column_data();
-
-            const auto& dst_data = tmp_block.get_columns_with_type_and_name();
-
-            size_t block_rows = std::min(rows - row_idx, batch_size_);
-            RETURN_IF_CATCH_EXCEPTION({
-                for (size_t col_idx = 0; col_idx < block.columns(); ++col_idx) {
-                    dst_data[col_idx].column->assume_mutable()->insert_range_from(
-                            *src_data[col_idx].column, row_idx, block_rows);
-                }
-            });
-
-            int64_t tmp_blcok_mem = tmp_block.allocated_bytes();
-            COUNTER_UPDATE(_memory_used_counter, tmp_blcok_mem);
-            Defer defer {[&]() { COUNTER_UPDATE(_memory_used_counter, -tmp_blcok_mem); }};
-            RETURN_IF_ERROR(_write_internal(tmp_block, written_bytes));
-
-            row_idx += block_rows;
-        }
-        return Status::OK();
-    }
-}
-
-Status SpillWriter::_write_internal(const Block& block, size_t& written_bytes) {
-    size_t uncompressed_bytes = 0, compressed_bytes = 0;
-
-    Status status;
-    std::string buff;
-    int64_t buff_size {0};
-
-    if (block.rows() > 0) {
-        {
-            PBlock pblock;
-            SCOPED_TIMER(_serialize_timer);
-            int64_t compressed_time = 0;
-            status = block.serialize(
-                    BeExecVersionManager::get_newest_version(), &pblock, &uncompressed_bytes,
-                    &compressed_bytes, &compressed_time,
-                    segment_v2::CompressionTypePB::ZSTD); // ZSTD for better compression ratio
-            RETURN_IF_ERROR(status);
-            int64_t pblock_mem = pblock.ByteSizeLong();
-            COUNTER_UPDATE(_memory_used_counter, pblock_mem);
-            Defer defer {[&]() { COUNTER_UPDATE(_memory_used_counter, -pblock_mem); }};
-            if (!pblock.SerializeToString(&buff)) {
-                return Status::Error<ErrorCode::SERIALIZE_PROTOBUF_ERROR>(
-                        "serialize spill data error. [path={}]", file_path_);
-            }
-            buff_size = buff.size();
-            COUNTER_UPDATE(_memory_used_counter, buff_size);
-            Defer defer2 {[&]() { COUNTER_UPDATE(_memory_used_counter, -buff_size); }};
-        }
-        if (data_dir_->reach_capacity_limit(buff_size)) {
-            return Status::Error<ErrorCode::DISK_REACH_CAPACITY_LIMIT>(
-                    "spill data total size exceed limit, path: {}, size limit: {}, spill data "
-                    "size: {}",
-                    data_dir_->path(),
-                    PrettyPrinter::print_bytes(data_dir_->get_spill_data_limit()),
-                    PrettyPrinter::print_bytes(data_dir_->get_spill_data_bytes()));
-        }
-
-        {
-            Defer defer {[&]() {
-                if (status.ok()) {
-                    data_dir_->update_spill_data_usage(buff_size);
-                    ExecEnv::GetInstance()->spill_stream_mgr()->update_spill_write_bytes(buff_size);
-
-                    written_bytes += buff_size;
-                    max_sub_block_size_ = std::max(max_sub_block_size_, (size_t)buff_size);
-
-                    meta_.append((const char*)&total_written_bytes_, sizeof(size_t));
-                    COUNTER_UPDATE(_write_file_total_size, buff_size);
-                    if (_resource_ctx) {
-                        _resource_ctx->io_context()->update_spill_write_bytes_to_local_storage(
-                                buff_size);
-                    }
-                    if (_write_file_current_size) {
-                        COUNTER_UPDATE(_write_file_current_size, buff_size);
-                    }
-                    COUNTER_UPDATE(_write_block_counter, 1);
-                    total_written_bytes_ += buff_size;
-                    ++written_blocks_;
-                }
-            }};
-            {
-                SCOPED_TIMER(_write_file_timer);
-                status = file_writer_->append(buff);
-                RETURN_IF_ERROR(status);
-            }
-        }
-    }
-
-    return status;
-}
-
-} // namespace doris
\ No newline at end of file
diff --git a/be/src/exec/spill/spill_writer.h b/be/src/exec/spill/spill_writer.h
deleted file mode 100644
index c78fcaea98b..00000000000
--- a/be/src/exec/spill/spill_writer.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// 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.
-
-#pragma once
-
-#include <atomic>
-#include <memory>
-#include <string>
-
-#include "core/block/block.h"
-#include "io/fs/file_writer.h"
-#include "runtime/runtime_profile.h"
-#include "runtime/workload_management/resource_context.h"
-namespace doris {
-#include "common/compile_check_begin.h"
-class RuntimeState;
-
-class SpillDataDir;
-class SpillWriter {
-public:
-    SpillWriter(std::shared_ptr<ResourceContext> resource_context, RuntimeProfile* profile,
-                int64_t id, size_t batch_size, SpillDataDir* data_dir, const std::string& dir)
-            : data_dir_(data_dir),
-              stream_id_(id),
-              batch_size_(batch_size),
-              _resource_ctx(std::move(resource_context)) {
-        // Directory path format specified in SpillStreamManager::register_spill_stream:
-        // storage_root/spill/query_id/partitioned_hash_join-node_id-task_id-stream_id/0
-        file_path_ = dir + "/0";
-        RuntimeProfile* common_profile = profile->get_child("CommonCounters");
-        DCHECK(common_profile != nullptr);
-        _memory_used_counter = common_profile->get_counter("MemoryUsage");
-    }
-
-    Status open();
-
-    Status close();
-
-    Status write(RuntimeState* state, const Block& block, size_t& written_bytes);
-
-    int64_t get_id() const { return stream_id_; }
-
-    int64_t get_written_bytes() const { return total_written_bytes_; }
-
-    const std::string& get_file_path() const { return file_path_; }
-
-    void set_counters(RuntimeProfile* operator_profile) {
-        RuntimeProfile* custom_profile = operator_profile->get_child("CustomCounters");
-        _write_file_timer = custom_profile->get_counter("SpillWriteFileTime");
-        _serialize_timer = custom_profile->get_counter("SpillWriteSerializeBlockTime");
-        _write_block_counter = custom_profile->get_counter("SpillWriteBlockCount");
-        _write_block_bytes_counter = custom_profile->get_counter("SpillWriteBlockBytes");
-        _write_file_total_size = custom_profile->get_counter("SpillWriteFileBytes");
-        _write_file_current_size = custom_profile->get_counter("SpillWriteFileCurrentBytes");
-        _write_rows_counter = custom_profile->get_counter("SpillWriteRows");
-    }
-
-private:
-    Status _write_internal(const Block& block, size_t& written_bytes);
-
-    // not owned, point to the data dir of this rowset
-    // for checking disk capacity when write data to disk.
-    SpillDataDir* data_dir_ = nullptr;
-    std::atomic_bool closed_ = false;
-    int64_t stream_id_;
-    size_t batch_size_;
-    size_t max_sub_block_size_ = 0;
-    std::string file_path_;
-    std::unique_ptr<doris::io::FileWriter> file_writer_;
-
-    size_t written_blocks_ = 0;
-    int64_t total_written_bytes_ = 0;
-    std::string meta_;
-
-    RuntimeProfile::Counter* _write_file_timer = nullptr;
-    RuntimeProfile::Counter* _serialize_timer = nullptr;
-    RuntimeProfile::Counter* _write_block_counter = nullptr;
-    RuntimeProfile::Counter* _write_block_bytes_counter = nullptr;
-    RuntimeProfile::Counter* _write_file_total_size = nullptr;
-    RuntimeProfile::Counter* _write_file_current_size = nullptr;
-    RuntimeProfile::Counter* _write_rows_counter = nullptr;
-    RuntimeProfile::Counter* _memory_used_counter = nullptr;
-
-    std::shared_ptr<ResourceContext> _resource_ctx = nullptr;
-};
-using SpillWriterUPtr = std::unique_ptr<SpillWriter>;
-} // namespace doris
-
-#include "common/compile_check_end.h"
diff --git a/be/src/format/parquet/byte_array_dict_decoder.cpp b/be/src/format/parquet/byte_array_dict_decoder.cpp
index 9b685a075e2..5441c07fce6 100644
--- a/be/src/format/parquet/byte_array_dict_decoder.cpp
+++ b/be/src/format/parquet/byte_array_dict_decoder.cpp
@@ -23,6 +23,7 @@
 #include "core/column/column.h"
 #include "core/column/column_dictionary.h"
 #include "core/column/column_string.h"
+#include "core/custom_allocator.h"
 #include "core/data_type/data_type_nullable.h"
 #include "util/coding.h"
 #include "util/rle_encoding.h"
@@ -81,7 +82,8 @@ Status ByteArrayDictDecoder::read_dict_values_to_column(MutableColumnPtr& doris_
 MutableColumnPtr ByteArrayDictDecoder::convert_dict_column_to_string_column(
         const ColumnInt32* dict_column) {
     auto res = ColumnString::create();
-    std::vector<StringRef> dict_values(dict_column->size());
+    DorisVector<StringRef> dict_values(dict_column->size());
+
     const auto& data = dict_column->get_data();
     for (size_t i = 0; i < dict_column->size(); ++i) {
         dict_values[i] = _dict_items[data[i]];
@@ -126,7 +128,7 @@ Status ByteArrayDictDecoder::_decode_values(MutableColumnPtr& doris_column, Data
     while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) {
         switch (read_type) {
         case ColumnSelectVector::CONTENT: {
-            std::vector<StringRef> string_values;
+            DorisVector<StringRef> string_values;
             string_values.reserve(run_length);
             for (size_t i = 0; i < run_length; ++i) {
                 string_values.emplace_back(_dict_items[_indexes[dict_index++]]);
diff --git a/be/src/format/parquet/byte_array_dict_decoder.h b/be/src/format/parquet/byte_array_dict_decoder.h
index 28d82f04ef0..89df5a2c8b5 100644
--- a/be/src/format/parquet/byte_array_dict_decoder.h
+++ b/be/src/format/parquet/byte_array_dict_decoder.h
@@ -58,8 +58,8 @@ public:
 
 protected:
     // For dictionary encoding
-    std::vector<StringRef> _dict_items;
-    std::vector<uint8_t> _dict_data;
+    DorisVector<StringRef> _dict_items;
+    DorisVector<uint8_t> _dict_data;
     size_t _max_value_length;
 };
 #include "common/compile_check_end.h"
diff --git a/be/src/format/parquet/fix_length_dict_decoder.hpp b/be/src/format/parquet/fix_length_dict_decoder.hpp
index ef84ecbfdbc..37782cd7242 100644
--- a/be/src/format/parquet/fix_length_dict_decoder.hpp
+++ b/be/src/format/parquet/fix_length_dict_decoder.hpp
@@ -223,7 +223,7 @@ protected:
         return res;
     }
     // For dictionary encoding
-    std::vector<typename PhysicalTypeTraits<PhysicalType>::CppType> _dict_items;
+    DorisVector<typename PhysicalTypeTraits<PhysicalType>::CppType> _dict_items;
 };
 #include "common/compile_check_end.h"
 
diff --git a/be/src/runtime/exec_env.h b/be/src/runtime/exec_env.h
index 502fb50bd91..f5afa76aa9f 100644
--- a/be/src/runtime/exec_env.h
+++ b/be/src/runtime/exec_env.h
@@ -50,7 +50,7 @@ class MemoryPool;
 
 namespace doris {
 class VDataStreamMgr;
-class SpillStreamManager;
+class SpillFileManager;
 class DeltaWriterV2Pool;
 class DictionaryFactory;
 class TaskScheduler;
@@ -284,7 +284,9 @@ public:
     LoadStreamMgr* load_stream_mgr() { return _load_stream_mgr.get(); }
     NewLoadStreamMgr* new_load_stream_mgr() { return _new_load_stream_mgr.get(); }
     SmallFileMgr* small_file_mgr() { return _small_file_mgr; }
-    doris::SpillStreamManager* spill_stream_mgr() { return _spill_stream_mgr; }
+
+    SpillFileManager* spill_file_mgr() { return _spill_file_mgr; }
+
     GroupCommitMgr* group_commit_mgr() { return _group_commit_mgr; }
     CdcClientMgr* cdc_client_mgr() { return _cdc_client_mgr; }
 
@@ -556,7 +558,8 @@ private:
 
     std::unique_ptr<PipelineTracerContext> _pipeline_tracer_ctx;
     std::unique_ptr<segment_v2::TmpFileDirs> _tmp_file_dirs;
-    doris::SpillStreamManager* _spill_stream_mgr = nullptr;
+
+    SpillFileManager* _spill_file_mgr = nullptr;
 
     orc::MemoryPool* _orc_memory_pool = nullptr;
     arrow::MemoryPool* _arrow_memory_pool = nullptr;
diff --git a/be/src/runtime/exec_env_init.cpp b/be/src/runtime/exec_env_init.cpp
index 68a8b6fed11..d914ba1d73e 100644
--- a/be/src/runtime/exec_env_init.cpp
+++ b/be/src/runtime/exec_env_init.cpp
@@ -52,7 +52,7 @@
 #include "exec/scan/scanner_scheduler.h"
 #include "exec/sink/delta_writer_v2_pool.h"
 #include "exec/sink/load_stream_map_pool.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
 #include "exprs/function/dictionary_factory.h"
 #include "format/orc/orc_memory_pool.h"
 #include "format/parquet/arrow_memory_pool.h"
@@ -124,6 +124,7 @@
 #include "util/threadpool.h"
 #include "util/thrift_rpc_helper.h"
 #include "util/timezone_utils.h"
+
 // clang-format off
 // this must after util/brpc_client_cache.h
 // /doris/thirdparty/installed/include/brpc/errno.pb.h:69:3: error: expected identifier
@@ -350,7 +351,8 @@ Status ExecEnv::_init(const std::vector<StorePath>& store_paths,
     _wal_manager = WalManager::create_unique(this, config::group_commit_wal_path);
     _dns_cache = new DNSCache();
     _write_cooldown_meta_executors = std::make_unique<WriteCooldownMetaExecutors>();
-    _spill_stream_mgr = new SpillStreamManager(std::move(spill_store_map));
+
+    _spill_file_mgr = new SpillFileManager(std::move(spill_store_map));
     _kerberos_ticket_mgr = new kerberos::KerberosTicketMgr(config::kerberos_ccache_path);
     _hdfs_mgr = new io::HdfsMgr();
     _backend_client_cache->init_metrics("backend");
@@ -442,7 +444,7 @@ Status ExecEnv::_init(const std::vector<StorePath>& store_paths,
         });
     }
 
-    RETURN_IF_ERROR(_spill_stream_mgr->init());
+    RETURN_IF_ERROR(_spill_file_mgr->init());
     RETURN_IF_ERROR(_runtime_query_statistics_mgr->start_report_thread());
     _dict_factory = new doris::DictionaryFactory();
     _s_ready = true;
@@ -832,7 +834,7 @@ void ExecEnv::destroy() {
     SAFE_STOP(_storage_engine);
     _storage_engine.reset();
 
-    SAFE_STOP(_spill_stream_mgr);
+    SAFE_STOP(_spill_file_mgr);
     if (_runtime_query_statistics_mgr) {
         _runtime_query_statistics_mgr->stop_report_thread();
     }
@@ -885,7 +887,7 @@ void ExecEnv::destroy() {
     SAFE_DELETE(_vstream_mgr);
     // When _vstream_mgr is deconstructed, it will try call query context's dctor and will
     // access spill stream mgr, so spill stream mgr should be deconstructed after data stream manager
-    SAFE_DELETE(_spill_stream_mgr);
+    SAFE_DELETE(_spill_file_mgr);
     SAFE_DELETE(_fragment_mgr);
     SAFE_DELETE(_workload_sched_mgr);
     SAFE_DELETE(_workload_group_manager);
diff --git a/be/src/runtime/query_context.cpp b/be/src/runtime/query_context.cpp
index dc7e28cf60c..d641bad3c61 100644
--- a/be/src/runtime/query_context.cpp
+++ b/be/src/runtime/query_context.cpp
@@ -35,7 +35,7 @@
 #include "exec/pipeline/dependency.h"
 #include "exec/pipeline/pipeline_fragment_context.h"
 #include "exec/runtime_filter/runtime_filter_definitions.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
 #include "runtime/exec_env.h"
 #include "runtime/fragment_mgr.h"
 #include "runtime/memory/heap_profiler.h"
diff --git a/be/src/runtime/runtime_state.h b/be/src/runtime/runtime_state.h
index 74a0e7c34e5..f233db496f2 100644
--- a/be/src/runtime/runtime_state.h
+++ b/be/src/runtime/runtime_state.h
@@ -665,37 +665,91 @@ public:
 
     int64_t spill_min_revocable_mem() const {
         if (_query_options.__isset.min_revocable_mem) {
-            return std::max(_query_options.min_revocable_mem, (int64_t)1);
+            return std::max(_query_options.min_revocable_mem, (int64_t)1 << 20);
         }
-        return 1;
+        return 32 << 20;
     }
 
-    int64_t spill_sort_mem_limit() const {
-        if (_query_options.__isset.spill_sort_mem_limit) {
-            return std::max(_query_options.spill_sort_mem_limit, (int64_t)16777216);
+    int spill_aggregation_partition_count() const {
+        if (_query_options.__isset.spill_aggregation_partition_count) {
+            return std::min(std::max(2, _query_options.spill_aggregation_partition_count), 32);
         }
-        return 134217728;
+        return 8;
     }
 
-    int64_t spill_sort_batch_bytes() const {
-        if (_query_options.__isset.spill_sort_batch_bytes) {
-            return std::max(_query_options.spill_sort_batch_bytes, (int64_t)8388608);
+    int spill_hash_join_partition_count() const {
+        if (_query_options.__isset.spill_hash_join_partition_count) {
+            return std::min(std::max(2, _query_options.spill_hash_join_partition_count), 32);
         }
-        return 8388608;
+        return 8;
     }
 
-    int spill_aggregation_partition_count() const {
-        if (_query_options.__isset.spill_aggregation_partition_count) {
-            return std::min(std::max(_query_options.spill_aggregation_partition_count, 16), 8192);
+    int spill_repartition_max_depth() const {
+        if (_query_options.__isset.spill_repartition_max_depth) {
+            // Clamp to a reasonable range: [1, 128]
+            return std::max(1, std::min(_query_options.spill_repartition_max_depth, 128));
+        }
+        return 8;
+    }
+
+    int64_t spill_buffer_size_bytes() const {
+        // clamp to [1MB, 256MB]
+        constexpr int64_t kMin = 1LL * 1024 * 1024;
+        constexpr int64_t kMax = 256LL * 1024 * 1024;
+        if (_query_options.__isset.spill_buffer_size_bytes) {
+            int64_t v = _query_options.spill_buffer_size_bytes;
+            if (v < kMin) return kMin;
+            if (v > kMax) return kMax;
+            return v;
+        }
+        return 8LL * 1024 * 1024;
+    }
+
+    // Per-sink memory limits: after spill is triggered, the sink proactively
+    // spills when its revocable memory exceeds this threshold.
+    // Clamped to [1MB, 4GB], default 64MB.
+    int64_t spill_join_build_sink_mem_limit_bytes() const {
+        constexpr int64_t kMin = 1LL * 1024 * 1024;
+        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
+        constexpr int64_t kDefault = 64LL * 1024 * 1024;
+        if (_query_options.__isset.spill_join_build_sink_mem_limit_bytes) {
+            int64_t v = _query_options.spill_join_build_sink_mem_limit_bytes;
+            return std::min(std::max(v, kMin), kMax);
         }
-        return 32;
+        return kDefault;
     }
 
-    int spill_hash_join_partition_count() const {
-        if (_query_options.__isset.spill_hash_join_partition_count) {
-            return std::min(std::max(_query_options.spill_hash_join_partition_count, 16), 8192);
+    int64_t spill_aggregation_sink_mem_limit_bytes() const {
+        constexpr int64_t kMin = 1LL * 1024 * 1024;
+        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
+        constexpr int64_t kDefault = 64LL * 1024 * 1024;
+        if (_query_options.__isset.spill_aggregation_sink_mem_limit_bytes) {
+            int64_t v = _query_options.spill_aggregation_sink_mem_limit_bytes;
+            return std::min(std::max(v, kMin), kMax);
+        }
+        return kDefault;
+    }
+
+    int64_t spill_sort_sink_mem_limit_bytes() const {
+        constexpr int64_t kMin = 1LL * 1024 * 1024;
+        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
+        constexpr int64_t kDefault = 64LL * 1024 * 1024;
+        if (_query_options.__isset.spill_sort_sink_mem_limit_bytes) {
+            int64_t v = _query_options.spill_sort_sink_mem_limit_bytes;
+            return std::min(std::max(v, kMin), kMax);
+        }
+        return kDefault;
+    }
+
+    int64_t spill_sort_merge_mem_limit_bytes() const {
+        constexpr int64_t kMin = 1LL * 1024 * 1024;
+        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
+        constexpr int64_t kDefault = 64LL * 1024 * 1024;
+        if (_query_options.__isset.spill_sort_merge_mem_limit_bytes) {
+            int64_t v = _query_options.spill_sort_merge_mem_limit_bytes;
+            return std::min(std::max(v, kMin), kMax);
         }
-        return 32;
+        return kDefault;
     }
 
     int64_t low_memory_mode_buffer_limit() const {
@@ -722,7 +776,7 @@ public:
             return _query_options.minimum_operator_memory_required_kb * 1024;
         } else {
             // refer other database
-            return 100 * 1024;
+            return 4 * 1024 * 1024;
         }
     }
 
diff --git a/be/test/exec/operator/agg_operator_test.cpp b/be/test/exec/operator/agg_operator_test.cpp
index ff99bee4d44..945fd0f9f1f 100644
--- a/be/test/exec/operator/agg_operator_test.cpp
+++ b/be/test/exec/operator/agg_operator_test.cpp
@@ -592,7 +592,7 @@ TEST_F(AggOperatorTestWithGroupBy, other_case_2) {
         local_state->_emplace_into_hash_table(local_state->_places.data(), key_columns,
                                               block.rows());
 
-        EXPECT_EQ(local_state->_get_hash_table_size(), 4); // [1,2,3,null]
+        EXPECT_EQ(local_state->get_hash_table_size(), 4); // [1,2,3,null]
     }
 }
 
diff --git a/be/test/exec/operator/join_test_helper.h b/be/test/exec/operator/join_test_helper.h
index ff6ea8a5982..e507c0cbcd5 100644
--- a/be/test/exec/operator/join_test_helper.h
+++ b/be/test/exec/operator/join_test_helper.h
@@ -27,7 +27,7 @@
 
 #include "common/object_pool.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
 #include "runtime/fragment_mgr.h"
 #include "runtime/runtime_profile.h"
 #include "testutil/mock/mock_runtime_state.h"
diff --git a/be/test/exec/operator/partitioned_aggregation_sink_operator_test.cpp b/be/test/exec/operator/partitioned_aggregation_sink_operator_test.cpp
index 8db5e782778..42cc320f183 100644
--- a/be/test/exec/operator/partitioned_aggregation_sink_operator_test.cpp
+++ b/be/test/exec/operator/partitioned_aggregation_sink_operator_test.cpp
@@ -29,7 +29,7 @@
 #include "exec/operator/partitioned_hash_join_probe_operator.h"
 #include "exec/operator/partitioned_hash_join_sink_operator.h"
 #include "exec/pipeline/pipeline_task.h"
-#include "exec/spill/spill_stream_manager.h"
+#include "exec/spill/spill_file_manager.h"
 #include "runtime/fragment_mgr.h"
 #include "runtime/runtime_profile.h"
 #include "testutil/column_helper.h"
@@ -222,16 +222,14 @@ TEST_F(PartitionedAggregationSinkOperatorTest, SinkWithSpill) {
     st = sink_operator->sink(_helper.runtime_state.get(), &block, false);
     ASSERT_TRUE(st.ok()) << "sink failed: " << st.to_string();
 
-    ASSERT_GT(sink_operator->revocable_mem_size(_helper.runtime_state.get()), 0);
-
     auto* inner_sink_local_state = reinterpret_cast<AggSinkLocalState*>(
             local_state->_runtime_state->get_sink_local_state());
-    ASSERT_GT(inner_sink_local_state->_get_hash_table_size(), 0);
+    ASSERT_GT(inner_sink_local_state->get_hash_table_size(), 0);
 
-    st = sink_operator->revoke_memory(_helper.runtime_state.get(), nullptr);
+    st = sink_operator->revoke_memory(_helper.runtime_state.get());
     ASSERT_TRUE(st.ok()) << "revoke_memory failed: " << st.to_string();
 
-    ASSERT_EQ(inner_sink_local_state->_get_hash_table_size(), 0);
+    ASSERT_EQ(inner_sink_local_state->get_hash_table_size(), 0);
 
     st = sink_operator->sink(_helper.runtime_state.get(), &block, true);
     ASSERT_TRUE(st.ok()) << "sink failed: " << st.to_string();
@@ -283,16 +281,14 @@ TEST_F(PartitionedAggregationSinkOperatorTest, SinkWithSpillAndEmptyEOS) {
     st = sink_operator->sink(_helper.runtime_state.get(), &block, false);
     ASSERT_TRUE(st.ok()) << "sink failed: " << st.to_string();
 
-    ASSERT_GT(sink_operator->revocable_mem_size(_helper.runtime_state.get()), 0);
-
     auto* inner_sink_local_state = reinterpret_cast<AggSinkLocalState*>(
             local_state->_runtime_state->get_sink_local_state());
-    ASSERT_GT(inner_sink_local_state->_get_hash_table_size(), 0);
+    ASSERT_GT(inner_sink_local_state->get_hash_table_size(), 0);
 
-    st = sink_operator->revoke_memory(_helper.runtime_state.get(), nullptr);
+    st = sink_operator->revoke_memory(_helper.runtime_state.get());
     ASSERT_TRUE(st.ok()) << "revoke_memory failed: " << st.to_string();
 
-    ASSERT_EQ(inner_sink_local_state->_get_hash_table_size(), 0);
+    ASSERT_EQ(inner_sink_local_state->get_hash_table_size(), 0);
 
     block.clear_column_data();
     st = sink_operator->sink(_helper.runtime_state.get(), &block, true);
@@ -344,20 +340,18 @@ TEST_F(PartitionedAggregationSinkOperatorTest, SinkWithSpillLargeData) {
     st = sink_operator->sink(_helper.runtime_state.get(), &block, false);
     ASSERT_TRUE(st.ok()) << "sink failed: " << st.to_string();
 
-    ASSERT_GT(sink_operator->revocable_mem_size(_helper.runtime_state.get()), 0);
-
     auto* inner_sink_local_state = reinterpret_cast<AggSinkLocalState*>(
             local_state->_runtime_state->get_sink_local_state());
-    ASSERT_GT(inner_sink_local_state->_get_hash_table_size(), 0);
+    ASSERT_GT(inner_sink_local_state->get_hash_table_size(), 0);
 
-    st = sink_operator->revoke_memory(_helper.runtime_state.get(), nullptr);
+    st = sink_operator->revoke_memory(_helper.runtime_state.get());
     ASSERT_TRUE(st.ok()) << "revoke_memory failed: " << st.to_string();
 
     auto* spill_write_rows_counter = local_state->custom_profile()->get_counter("SpillWriteRows");
     ASSERT_TRUE(spill_write_rows_counter != nullptr);
     ASSERT_EQ(spill_write_rows_counter->value(), 4);
 
-    ASSERT_EQ(inner_sink_local_state->_get_hash_table_size(), 0);
+    ASSERT_EQ(inner_sink_local_state->get_hash_table_size(), 0);
 
     const size_t count = 1048576;
     std::vector<int32_t> data(count);
@@ -416,15 +410,303 @@ TEST_F(PartitionedAggregationSinkOperatorTest, SinkWithSpilError) {
     st = sink_operator->sink(_helper.runtime_state.get(), &block, false);
     ASSERT_TRUE(st.ok()) << "sink failed: " << st.to_string();
 
-    ASSERT_GT(sink_operator->revocable_mem_size(_helper.runtime_state.get()), 0);
-
     auto* inner_sink_local_state = reinterpret_cast<AggSinkLocalState*>(
             local_state->_runtime_state->get_sink_local_state());
-    ASSERT_GT(inner_sink_local_state->_get_hash_table_size(), 0);
+    ASSERT_GT(inner_sink_local_state->get_hash_table_size(), 0);
 
-    SpillableDebugPointHelper dp_helper("fault_inject::spill_stream::spill_block");
-    st = sink_operator->revoke_memory(_helper.runtime_state.get(), nullptr);
+    SpillableDebugPointHelper dp_helper("fault_inject::spill_file::spill_block");
+    st = sink_operator->revoke_memory(_helper.runtime_state.get());
     ASSERT_FALSE(st.ok()) << "spilll status should be failed";
+
+    st = sink_operator->close(_helper.runtime_state.get(), st);
+    ASSERT_TRUE(st.ok()) << "close status should be successful even if spill failed: "
+                         << st.to_string();
+}
+
+// Test multiple consecutive revoke_memory calls to verify repeated spilling works.
+TEST_F(PartitionedAggregationSinkOperatorTest, SinkWithMultipleRevokes) {
+    auto [source_operator, sink_operator] = _helper.create_operators();
+    ASSERT_TRUE(source_operator != nullptr);
+    ASSERT_TRUE(sink_operator != nullptr);
+
+    const auto tnode = _helper.create_test_plan_node();
+    auto st = sink_operator->init(tnode, _helper.runtime_state.get());
+    ASSERT_TRUE(st.ok()) << "init failed: " << st.to_string();
+
+    st = sink_operator->prepare(_helper.runtime_state.get());
+    ASSERT_TRUE(st.ok()) << "prepare failed: " << st.to_string();
+
+    auto shared_state = std::dynamic_pointer_cast<PartitionedAggSharedState>(
+            sink_operator->create_shared_state());
+    shared_state->create_source_dependency(source_operator->operator_id(),
+                                           source_operator->node_id(), "PartitionedAggSinkTestDep");
+
+    LocalSinkStateInfo info {.task_idx = 0,
+                             .parent_profile = _helper.operator_profile.get(),
+                             .sender_id = 0,
+                             .shared_state = shared_state.get(),
+                             .shared_state_map = {},
+                             .tsink = TDataSink()};
+    st = sink_operator->setup_local_state(_helper.runtime_state.get(), info);
+    ASSERT_TRUE(st.ok()) << "setup_local_state failed: " << st.to_string();
+
+    auto* local_state = reinterpret_cast<PartitionedAggSinkLocalState*>(
+            _helper.runtime_state->get_sink_local_state());
+    ASSERT_TRUE(local_state != nullptr);
+
+    st = local_state->open(_helper.runtime_state.get());
+    ASSERT_TRUE(st.ok()) << "open failed: " << st.to_string();
... 6838 lines suppressed ...


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org