-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: integrate segment pruning into pipeline (#17126)
* refactor: integrate segment pruning into pipeline * chore: fix unit test and clean code
- Loading branch information
Showing
7 changed files
with
168 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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 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 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
43 changes: 43 additions & 0 deletions
43
src/query/storages/fuse/src/pruning_pipeline/lazy_segment_meta.rs
This file contains 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,43 @@ | ||
// 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::fmt::Debug; | ||
use std::fmt::Formatter; | ||
|
||
use databend_common_expression::local_block_meta_serde; | ||
use databend_common_expression::BlockMetaInfo; | ||
use databend_common_expression::BlockMetaInfoPtr; | ||
|
||
use crate::SegmentLocation; | ||
|
||
pub struct LazySegmentMeta { | ||
pub segment_location: SegmentLocation, | ||
} | ||
|
||
impl LazySegmentMeta { | ||
pub fn create(segment_location: SegmentLocation) -> BlockMetaInfoPtr { | ||
Box::new(LazySegmentMeta { segment_location }) | ||
} | ||
} | ||
|
||
impl Debug for LazySegmentMeta { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("LazySegmentMeta").finish() | ||
} | ||
} | ||
|
||
local_block_meta_serde!(LazySegmentMeta); | ||
|
||
#[typetag::serde(name = "lazy_segment_meta")] | ||
impl BlockMetaInfo for LazySegmentMeta {} |
This file contains 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 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
86 changes: 86 additions & 0 deletions
86
src/query/storages/fuse/src/pruning_pipeline/segment_prune_transform.rs
This file contains 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,86 @@ | ||
// 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 databend_common_exception::ErrorCode; | ||
use databend_common_exception::Result; | ||
use databend_common_expression::BlockMetaInfoDowncast; | ||
use databend_common_expression::DataBlock; | ||
use databend_common_expression::SEGMENT_NAME_COL_NAME; | ||
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_transforms::AsyncAccumulatingTransform; | ||
use databend_common_pipeline_transforms::AsyncAccumulatingTransformer; | ||
|
||
use crate::pruning::PruningContext; | ||
use crate::pruning::SegmentPruner; | ||
use crate::pruning_pipeline::pruned_segment_meta::PrunedSegmentMeta; | ||
use crate::pruning_pipeline::LazySegmentMeta; | ||
|
||
pub struct SegmentPruneTransform { | ||
pub segment_pruner: Arc<SegmentPruner>, | ||
pub pruning_ctx: Arc<PruningContext>, | ||
} | ||
|
||
impl SegmentPruneTransform { | ||
pub fn create( | ||
input: Arc<InputPort>, | ||
output: Arc<OutputPort>, | ||
segment_pruner: Arc<SegmentPruner>, | ||
pruning_context: Arc<PruningContext>, | ||
) -> Result<ProcessorPtr> { | ||
Ok(ProcessorPtr::create(AsyncAccumulatingTransformer::create( | ||
input, | ||
output, | ||
SegmentPruneTransform { | ||
segment_pruner, | ||
pruning_ctx: pruning_context, | ||
}, | ||
))) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncAccumulatingTransform for SegmentPruneTransform { | ||
const NAME: &'static str = "SegmentPruneTransform"; | ||
|
||
async fn transform(&mut self, mut data: DataBlock) -> Result<Option<DataBlock>> { | ||
if let Some(ptr) = data.take_meta() { | ||
if let Some(meta) = LazySegmentMeta::downcast_from(ptr) { | ||
let location = meta.segment_location; | ||
if let Some(pruner) = &self.pruning_ctx.internal_column_pruner { | ||
if !pruner.should_keep(SEGMENT_NAME_COL_NAME, &location.location.0) { | ||
return Ok(None); | ||
} | ||
} | ||
let mut pruned_segments = self.segment_pruner.pruning(vec![location]).await?; | ||
|
||
if pruned_segments.is_empty() { | ||
return Ok(None); | ||
} | ||
|
||
debug_assert!(pruned_segments.len() == 1); | ||
|
||
return Ok(Some(DataBlock::empty_with_meta(PrunedSegmentMeta::create( | ||
pruned_segments.pop().unwrap(), | ||
)))); | ||
} | ||
} | ||
Err(ErrorCode::Internal( | ||
"Cannot downcast meta to LazySegmentMeta", | ||
)) | ||
} | ||
} |