-
Notifications
You must be signed in to change notification settings - Fork 776
feat(planner): support union/union all #7160
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e17e184
feat(planner): support union all
xudong963 573fcfc
finish demo
xudong963 a0a682e
cargo fix
xudong963 afcc942
union all now works
xudong963 5f156ac
support union empty
xudong963 e61254f
refine code
xudong963 da0750b
add logic test
xudong963 15196d4
support union distinct
xudong963 953b966
use async_channel
xudong963 31b090f
address comments
xudong963 3da9537
address comments
xudong963 513883e
fix cluster
xudong963 f2ec61b
fix toml format
xudong963 a90628d
rename union to union all
xudong963 8eea7a0
Merge branch 'main' into union
mergify[bot] 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
57 changes: 57 additions & 0 deletions
57
src/common/pipeline/sinks/src/processors/sinks/union_receive_sink.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,57 @@ | ||
// Copyright 2022 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::Sender; | ||
use async_trait::async_trait; | ||
use async_trait::unboxed_simple; | ||
use common_datablocks::DataBlock; | ||
use common_exception::ErrorCode; | ||
use common_exception::Result; | ||
use common_pipeline_core::processors::port::InputPort; | ||
use common_pipeline_core::processors::processor::ProcessorPtr; | ||
|
||
use crate::processors::sinks::AsyncSink; | ||
use crate::processors::sinks::AsyncSinker; | ||
|
||
pub struct UnionReceiveSink { | ||
sender: Option<Sender<DataBlock>>, | ||
} | ||
|
||
impl UnionReceiveSink { | ||
pub fn create(sender: Option<Sender<DataBlock>>, input: Arc<InputPort>) -> ProcessorPtr { | ||
AsyncSinker::create(input, UnionReceiveSink { sender }) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl AsyncSink for UnionReceiveSink { | ||
const NAME: &'static str = "UnionReceiveSink"; | ||
|
||
async fn on_finish(&mut self) -> Result<()> { | ||
drop(self.sender.take()); | ||
Ok(()) | ||
} | ||
|
||
#[unboxed_simple] | ||
async fn consume(&mut self, data_block: DataBlock) -> Result<()> { | ||
if let Some(sender) = self.sender.as_ref() { | ||
if sender.send(data_block).await.is_err() { | ||
return Err(ErrorCode::UnexpectedError("UnionReceiveSink sender failed")); | ||
}; | ||
} | ||
Ok(()) | ||
} | ||
} |
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
141 changes: 141 additions & 0 deletions
141
src/query/service/src/pipelines/processors/transforms/transform_merge_block.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,141 @@ | ||
// Copyright 2022 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::any::Any; | ||
use std::sync::Arc; | ||
|
||
use async_channel::Receiver; | ||
use common_datablocks::DataBlock; | ||
use common_datavalues::DataSchemaRef; | ||
use common_exception::Result; | ||
use common_pipeline_core::processors::port::InputPort; | ||
use common_pipeline_core::processors::port::OutputPort; | ||
use common_pipeline_core::processors::processor::Event; | ||
use common_pipeline_core::processors::processor::ProcessorPtr; | ||
use common_pipeline_core::processors::Processor; | ||
|
||
pub struct TransformMergeBlock { | ||
finished: bool, | ||
input: Arc<InputPort>, | ||
output: Arc<OutputPort>, | ||
|
||
input_data: Option<DataBlock>, | ||
output_data: Option<DataBlock>, | ||
schema: DataSchemaRef, | ||
|
||
receiver: Receiver<DataBlock>, | ||
receiver_result: Option<DataBlock>, | ||
} | ||
|
||
impl TransformMergeBlock { | ||
pub fn try_create( | ||
input: Arc<InputPort>, | ||
output: Arc<OutputPort>, | ||
schema: DataSchemaRef, | ||
receiver: Receiver<DataBlock>, | ||
) -> Result<ProcessorPtr> { | ||
Ok(ProcessorPtr::create(Box::new(TransformMergeBlock { | ||
finished: false, | ||
input, | ||
output, | ||
input_data: None, | ||
output_data: None, | ||
schema, | ||
receiver, | ||
receiver_result: None, | ||
}))) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Processor for TransformMergeBlock { | ||
fn name(&self) -> &'static str { | ||
"TransformMergeBlock" | ||
} | ||
|
||
fn as_any(&mut self) -> &mut dyn Any { | ||
self | ||
} | ||
|
||
fn event(&mut self) -> Result<Event> { | ||
if self.output.is_finished() { | ||
self.input.finish(); | ||
return Ok(Event::Finished); | ||
} | ||
|
||
if !self.output.can_push() { | ||
self.input.set_not_need_data(); | ||
return Ok(Event::NeedConsume); | ||
} | ||
|
||
if let Some(output_data) = self.output_data.take() { | ||
self.output.push_data(Ok(output_data)); | ||
return Ok(Event::NeedConsume); | ||
} | ||
|
||
if self.input_data.is_some() || self.receiver_result.is_some() { | ||
return Ok(Event::Sync); | ||
} | ||
|
||
if let Ok(result) = self.receiver.try_recv() { | ||
self.receiver_result = Some(result); | ||
return Ok(Event::Sync); | ||
} | ||
|
||
if self.input.is_finished() { | ||
if !self.finished { | ||
return Ok(Event::Async); | ||
} | ||
self.output.finish(); | ||
xudong963 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Ok(Event::Finished); | ||
} | ||
|
||
if self.input.has_data() { | ||
self.input_data = Some(self.input.pull_data().unwrap()?); | ||
return Ok(Event::Sync); | ||
} | ||
|
||
self.input.set_need_data(); | ||
Ok(Event::NeedData) | ||
} | ||
|
||
fn process(&mut self) -> Result<()> { | ||
if let Some(input_data) = self.input_data.take() { | ||
if let Some(receiver_result) = self.receiver_result.take() { | ||
let data_block = | ||
DataBlock::create(self.schema.clone(), receiver_result.columns().to_vec()); | ||
self.output_data = Some(DataBlock::concat_blocks(&[input_data, data_block])?); | ||
} else { | ||
self.output_data = Some(input_data); | ||
} | ||
} else if let Some(receiver_result) = self.receiver_result.take() { | ||
let data_block = | ||
DataBlock::create(self.schema.clone(), receiver_result.columns().to_vec()); | ||
self.output_data = Some(data_block); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn async_process(&mut self) -> Result<()> { | ||
xudong963 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !self.finished { | ||
if let Ok(result) = self.receiver.recv().await { | ||
self.receiver_result = Some(result); | ||
return Ok(()); | ||
} | ||
self.finished = true; | ||
} | ||
Ok(()) | ||
} | ||
} |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.