Skip to content
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

feat(batch,optimizer): support column pruning for iceberg source #16429

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/frontend/src/optimizer/plan_node/logical_iceberg_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ impl LogicalIcebergScan {
pub fn source_catalog(&self) -> Option<Rc<SourceCatalog>> {
self.core.catalog.clone()
}

pub fn clone_with_required_cols(&self, required_cols: &[usize]) -> Self {
assert!(!required_cols.is_empty());
let mut core = self.core.clone();
core.column_catalog = required_cols
.iter()
.map(|idx| core.column_catalog[*idx].clone())
.collect();
let base = PlanBase::new_logical_with_core(&core);

LogicalIcebergScan { base, core }
}
}

impl_plan_tree_node_for_leaf! {LogicalIcebergScan}
Expand All @@ -74,9 +86,14 @@ impl Distill for LogicalIcebergScan {

impl ColPrunable for LogicalIcebergScan {
fn prune_col(&self, required_cols: &[usize], _ctx: &mut ColumnPruningContext) -> PlanRef {
// TODO: support column pruning for iceberg scan
let mapping = ColIndexMapping::with_remaining_columns(required_cols, self.schema().len());
LogicalProject::with_mapping(self.clone().into(), mapping).into()
if required_cols.is_empty() {
let mapping =
ColIndexMapping::with_remaining_columns(required_cols, self.schema().len());
// If reuqiured_cols is empty, we use the first column of iceberg to avoid the empty schema.
LogicalProject::with_mapping(self.clone_with_required_cols(&[0]).into(), mapping).into()
} else {
self.clone_with_required_cols(required_cols).into()
}
}
}

Expand Down
Loading