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


##########
be/src/pipeline/pipeline_x/dependency.h:
##########
@@ -476,5 +482,25 @@ class NestedLoopJoinDependency final : public Dependency {
     NestedLoopJoinSharedState _join_state;
 };
 
+struct PartitionSortNodeSharedState {
+public:
+    std::queue<vectorized::Block> _blocks_buffer;

Review Comment:
   Delete `_` prefix



##########
be/src/pipeline/exec/partition_sort_source_operator.cpp:
##########
@@ -0,0 +1,107 @@
+// 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 "partition_sort_source_operator.h"
+
+#include "pipeline/exec/operator.h"
+
+namespace doris {
+class ExecNode;
+class RuntimeState;
+
+namespace pipeline {
+
+OperatorPtr PartitionSortSourceOperatorBuilder::build_operator() {
+    return std::make_shared<PartitionSortSourceOperator>(this, _node);
+}
+
+Status PartitionSortSourceLocalState::close(RuntimeState* state) {
+    if (_closed) {
+        return Status::OK();
+    }
+    _shared_state->_previous_row = nullptr;
+    _shared_state->_partition_sorts.clear();
+    return PipelineXLocalState<PartitionSortDependency>::close(state);
+}
+
+Status PartitionSortSourceOperatorX::get_block(RuntimeState* state, 
vectorized::Block* output_block,
+                                               SourceState& source_state) {
+    RETURN_IF_CANCELLED(state);
+    auto& local_state = 
state->get_local_state(id())->cast<PartitionSortSourceLocalState>();
+    output_block->clear_column_data();
+    {
+        std::lock_guard<std::mutex> 
lock(local_state._shared_state->_buffer_mutex);
+        if (local_state._shared_state->_blocks_buffer.empty() == false) {
+            
local_state._shared_state->_blocks_buffer.front().swap(*output_block);
+            local_state._shared_state->_blocks_buffer.pop();
+            //if buffer have no data, block reading and wait for signal again
+            if (local_state._shared_state->_blocks_buffer.empty()) {
+                local_state._dependency->block_reading();
+            }
+            return Status::OK();
+        }
+    }
+
+    // this is set by sink node using: 
local_state._dependency->set_ready_for_read()
+    if (local_state._dependency->is_ready_for_read()) {

Review Comment:
   `_dependency->is_ready_for_read()` is always true because we run this 
operator only if this condition is true



##########
be/src/pipeline/exec/partition_sort_source_operator.h:
##########
@@ -48,9 +49,53 @@ class PartitionSortSourceOperator final
     Status open(RuntimeState*) override { return Status::OK(); }
 };
 
-OperatorPtr PartitionSortSourceOperatorBuilder::build_operator() {
-    return std::make_shared<PartitionSortSourceOperator>(this, _node);
-}
+class PartitionSortSourceOperatorX;
+class PartitionSortSourceLocalState final : public 
PipelineXLocalState<PartitionSortDependency> {
+    ENABLE_FACTORY_CREATOR(PartitionSortSourceLocalState);
+
+public:
+    using Base = PipelineXLocalState<PartitionSortDependency>;
+    PartitionSortSourceLocalState(RuntimeState* state, OperatorXBase* parent)
+            : PipelineXLocalState<PartitionSortDependency>(state, parent),
+              _get_next_timer(nullptr) {}
+
+    Status init(RuntimeState* state, LocalStateInfo& info) override {
+        
RETURN_IF_ERROR(PipelineXLocalState<PartitionSortDependency>::init(state, 
info));
+        _get_next_timer = ADD_TIMER(profile(), "GetResultTime");
+        _get_sorted_timer = ADD_TIMER(profile(), "GetSortedTime");
+        _shared_state->_previous_row = 
std::make_unique<vectorized::SortCursorCmp>();
+        return Status::OK();
+    }
+
+    Status close(RuntimeState* state) override;
+
+    int64_t _num_rows_returned = 0;
+
+private:
+    friend class PartitionSortSourceOperatorX;
+    RuntimeProfile::Counter* _get_sorted_timer;
+    RuntimeProfile::Counter* _get_next_timer = nullptr;
+};
+
+class PartitionSortSourceOperatorX final : public 
OperatorX<PartitionSortSourceLocalState> {
+public:
+    using Base = OperatorX<PartitionSortSourceLocalState>;
+    PartitionSortSourceOperatorX(ObjectPool* pool, const TPlanNode& tnode,
+                                 const DescriptorTbl& descs)
+            : OperatorX<PartitionSortSourceLocalState>(pool, tnode, descs) {}
+
+    Status get_block(RuntimeState* state, vectorized::Block* block,
+                     SourceState& source_state) override;
+
+    Dependency* wait_for_dependency(RuntimeState* state) override;
+
+    bool is_source() const override { return true; }
+
+private:
+    friend class PartitionSortSourceLocalState;
+    Status get_sorted_block(RuntimeState* state, vectorized::Block* 
output_block, bool* eos,
+                            PartitionSortSourceLocalState& local_state);
+};
 
 } // namespace pipeline
 } // namespace doris

Review Comment:
   Append an empty line here



##########
be/src/pipeline/exec/partition_sort_source_operator.cpp:
##########
@@ -0,0 +1,107 @@
+// 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 "partition_sort_source_operator.h"
+
+#include "pipeline/exec/operator.h"
+
+namespace doris {
+class ExecNode;
+class RuntimeState;
+
+namespace pipeline {
+
+OperatorPtr PartitionSortSourceOperatorBuilder::build_operator() {
+    return std::make_shared<PartitionSortSourceOperator>(this, _node);
+}
+
+Status PartitionSortSourceLocalState::close(RuntimeState* state) {
+    if (_closed) {
+        return Status::OK();
+    }
+    _shared_state->_previous_row = nullptr;
+    _shared_state->_partition_sorts.clear();
+    return PipelineXLocalState<PartitionSortDependency>::close(state);
+}
+
+Status PartitionSortSourceOperatorX::get_block(RuntimeState* state, 
vectorized::Block* output_block,
+                                               SourceState& source_state) {
+    RETURN_IF_CANCELLED(state);
+    auto& local_state = 
state->get_local_state(id())->cast<PartitionSortSourceLocalState>();
+    output_block->clear_column_data();
+    {
+        std::lock_guard<std::mutex> 
lock(local_state._shared_state->_buffer_mutex);
+        if (local_state._shared_state->_blocks_buffer.empty() == false) {
+            
local_state._shared_state->_blocks_buffer.front().swap(*output_block);
+            local_state._shared_state->_blocks_buffer.pop();
+            //if buffer have no data, block reading and wait for signal again
+            if (local_state._shared_state->_blocks_buffer.empty()) {
+                local_state._dependency->block_reading();
+            }
+            return Status::OK();
+        }
+    }
+
+    // this is set by sink node using: 
local_state._dependency->set_ready_for_read()
+    if (local_state._dependency->is_ready_for_read()) {
+        bool current_eos = false;

Review Comment:
   `current_eos` is not used. I think we should just declare this in 
`get_sorted_block`



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

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to