-
Notifications
You must be signed in to change notification settings - Fork 770
feat: support using fragment forest to execute additional broadcast operations. #17872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SkyFan2002
wants to merge
35
commits into
databendlabs:main
Choose a base branch
from
SkyFan2002:cluster
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
71b069b
update
SkyFan2002 c990993
avoid committing multiple times
SkyFan2002 7aa4421
Merge remote-tracking branch 'upstream/main' into shuffle_rf
SkyFan2002 59be6a3
fix merge
SkyFan2002 8dafec8
fix fragment type
SkyFan2002 0060d46
rm unused modify
SkyFan2002 097f94c
fix
SkyFan2002 413fd1c
improve err msg
SkyFan2002 45dc770
fix build pipeline
SkyFan2002 7939cad
fix exhchange
SkyFan2002 509fa2d
refactor
SkyFan2002 5711316
fix root pipeline
SkyFan2002 baa0f22
fix pipeline
SkyFan2002 0c2e757
improve error msg
SkyFan2002 ec1c88b
fix serialize block
SkyFan2002 aa7e5af
fix sink
SkyFan2002 cbbfb38
add log
SkyFan2002 ef53984
fix send
SkyFan2002 95f767b
merge rf
SkyFan2002 2a808bf
Merge branch 'main' into shuffle_rf
SkyFan2002 f668d1c
fix
SkyFan2002 10e0fae
fix
SkyFan2002 00b834a
fix
SkyFan2002 648c9f8
Merge remote-tracking branch 'upstream/main' into shuffle_rf
SkyFan2002 beff896
fix conflict
SkyFan2002 b8f9544
update
SkyFan2002 9d7e431
Merge remote-tracking branch 'upstream/main' into cluster
SkyFan2002 6a8a352
fix
SkyFan2002 feef21c
rm unused modify
SkyFan2002 5d5c0ed
make lint
SkyFan2002 0357265
fix
SkyFan2002 f2a9107
rm log
SkyFan2002 e05b400
rm empty impl
SkyFan2002 1aa0cc6
fix
SkyFan2002 b28877e
add comment
SkyFan2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/query/service/src/pipelines/builders/builder_broadcast.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed 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. | ||
|
||
use databend_common_exception::Result; | ||
use databend_common_sql::executor::physical_plans::BroadcastSink; | ||
use databend_common_sql::executor::physical_plans::BroadcastSource; | ||
|
||
use crate::pipelines::processors::transforms::BroadcastSinkProcessor; | ||
use crate::pipelines::processors::transforms::BroadcastSourceProcessor; | ||
use crate::pipelines::PipelineBuilder; | ||
|
||
impl PipelineBuilder { | ||
pub(crate) fn build_broadcast_source(&mut self, source: &BroadcastSource) -> Result<()> { | ||
let receiver = self.ctx.broadcast_source_receiver(source.broadcast_id); | ||
self.main_pipeline.add_source( | ||
|output| BroadcastSourceProcessor::create(self.ctx.clone(), receiver.clone(), output), | ||
1, | ||
) | ||
} | ||
|
||
pub(crate) fn build_broadcast_sink(&mut self, sink: &BroadcastSink) -> Result<()> { | ||
self.build_pipeline(&sink.input)?; | ||
self.main_pipeline.resize(1, true)?; | ||
self.main_pipeline.add_sink(|input| { | ||
BroadcastSinkProcessor::create(input, self.ctx.broadcast_sink_sender(sink.broadcast_id)) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/query/service/src/pipelines/processors/transforms/broadcast.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed 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. | ||
|
||
use std::sync::Arc; | ||
|
||
use async_channel::Receiver; | ||
use async_channel::Sender; | ||
use databend_common_catalog::table_context::TableContext; | ||
use databend_common_exception::ErrorCode; | ||
use databend_common_exception::Result; | ||
use databend_common_expression::BlockMetaInfoPtr; | ||
use databend_common_expression::DataBlock; | ||
use databend_common_pipeline_core::processors::InputPort; | ||
use databend_common_pipeline_core::processors::OutputPort; | ||
use databend_common_pipeline_core::processors::ProcessorPtr; | ||
use databend_common_pipeline_sinks::AsyncSink; | ||
use databend_common_pipeline_sinks::AsyncSinker; | ||
use databend_common_pipeline_sources::AsyncSource; | ||
use databend_common_pipeline_sources::AsyncSourcer; | ||
|
||
pub struct BroadcastSourceProcessor { | ||
pub receiver: Receiver<BlockMetaInfoPtr>, | ||
} | ||
|
||
impl BroadcastSourceProcessor { | ||
pub fn create( | ||
ctx: Arc<dyn TableContext>, | ||
receiver: Receiver<BlockMetaInfoPtr>, | ||
output_port: Arc<OutputPort>, | ||
) -> Result<ProcessorPtr> { | ||
AsyncSourcer::create(ctx, output_port, Self { receiver }) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncSource for BroadcastSourceProcessor { | ||
const NAME: &'static str = "BroadcastSource"; | ||
const SKIP_EMPTY_DATA_BLOCK: bool = false; | ||
|
||
#[async_backtrace::framed] | ||
async fn generate(&mut self) -> Result<Option<DataBlock>> { | ||
let received = self.receiver.recv().await; | ||
match received { | ||
Ok(meta) => Ok(Some(DataBlock::empty_with_meta(meta))), | ||
Err(_) => { | ||
// The channel is closed, we should return None to stop generating | ||
Ok(None) | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub struct BroadcastSinkProcessor { | ||
received: Vec<BlockMetaInfoPtr>, | ||
sender: Sender<BlockMetaInfoPtr>, | ||
} | ||
|
||
impl BroadcastSinkProcessor { | ||
pub fn create(input: Arc<InputPort>, sender: Sender<BlockMetaInfoPtr>) -> Result<ProcessorPtr> { | ||
Ok(ProcessorPtr::create(AsyncSinker::create(input, Self { | ||
received: vec![], | ||
sender, | ||
}))) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncSink for BroadcastSinkProcessor { | ||
const NAME: &'static str = "BroadcastSink"; | ||
|
||
async fn on_finish(&mut self) -> Result<()> { | ||
self.sender.close(); | ||
Ok(()) | ||
} | ||
|
||
async fn consume(&mut self, mut data_block: DataBlock) -> Result<bool> { | ||
let meta = data_block | ||
.take_meta() | ||
.ok_or_else(|| ErrorCode::Internal("Cannot downcast meta to BroadcastMeta"))?; | ||
log::info!("BroadcastSinkProcessor recv meta: {:?}", meta); | ||
self.sender | ||
.send(meta) | ||
.await | ||
.map_err(|_| ErrorCode::Internal("BroadcastSinkProcessor send error"))?; | ||
Ok(false) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need remove.