Repository navigation
feat: plan Iceberg file tasks before execution #67
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
base: main
Are you sure you want to change the base?
Changes from all commits
016d097
1f3982e
0a88cee
15cc28e
58b8e63
ed625a2
6a510df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // 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. | ||
|
|
||
| use datafusion::common::extensions_options; | ||
| use datafusion::config::ConfigExtension; | ||
|
|
||
| extensions_options! { | ||
| /// Opt-in file planning during physical planning for local Iceberg scans. | ||
| pub struct IcebergPlanningConfig { | ||
| /// Discover and retain file tasks in TableProvider::scan instead of at execution. | ||
| pub eager_file_planning: bool, default = false | ||
| } | ||
| } | ||
|
|
||
| impl ConfigExtension for IcebergPlanningConfig { | ||
| const PREFIX: &'static str = "iceberg"; | ||
| } | ||
|
Comment on lines
+21
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good time to adopt the config structure proposed here: This was a suggestion given by @mbutrovich in #55 (comment) and I think it was on point, so maybe we can ship it here. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // 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. | ||
|
|
||
| //! Query-local file work selected before execution, independently of task assignment. | ||
|
|
||
| use std::mem::{size_of, size_of_val}; | ||
|
|
||
| use datafusion::common::Result; | ||
| use datafusion::execution::TaskContext; | ||
| use datafusion::execution::memory_pool::{MemoryConsumer, MemoryReservation}; | ||
| use futures::TryStreamExt; | ||
| use iceberg::scan::{FileScanTask, TableScan}; | ||
|
|
||
| use crate::to_datafusion_error; | ||
|
|
||
| /// File work selected by one Iceberg scan before assignment to output partitions. | ||
| /// | ||
| /// The tasks retain their bound predicates, projection, and delete references. Keeping | ||
| /// this value alive also keeps the query memory reservation for the retained tasks. | ||
| /// This is not a reader and contains no coordinator-local reader state. | ||
| #[derive(Debug)] | ||
| pub(crate) struct PlannedFileScan { | ||
| tasks: Vec<FileScanTask>, | ||
| _reservation: MemoryReservation, | ||
| } | ||
|
|
||
| impl PlannedFileScan { | ||
| /// Tasks in Iceberg's planning order. Assign each once per execution. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I don't think I know what "Iceberg's planning order" or "Assign each once per execution" mean. |
||
| pub(crate) fn tasks(&self) -> &[FileScanTask] { | ||
| &self.tasks | ||
| } | ||
|
|
||
| pub(crate) async fn collect(scan: TableScan, context: &TaskContext) -> Result<Self> { | ||
| let reservation = | ||
| MemoryConsumer::new("Iceberg file planning").register(context.memory_pool()); | ||
| let mut planned = Self { | ||
| tasks: Vec::new(), | ||
| _reservation: reservation, | ||
| }; | ||
| let mut stream = scan.plan_files().await.map_err(to_datafusion_error)?; | ||
| while let Some(task) = stream.try_next().await.map_err(to_datafusion_error)? { | ||
| // Allow for spare Vec capacity and allocator overhead; schemas and specs | ||
| // are shared Arcs, but paths and delete references are owned by each task. | ||
| planned | ||
| ._reservation | ||
| .try_grow(retained_size(&task).saturating_mul(2))?; | ||
| planned.tasks.push(task); | ||
| } | ||
| Ok(planned) | ||
| } | ||
| } | ||
|
|
||
| fn retained_size(task: &FileScanTask) -> usize { | ||
| let mut bytes = size_of::<FileScanTask>() | ||
| + task.data_file_path().len() | ||
| + size_of_val(task.project_field_ids()) | ||
| + size_of_val(task.deletes()) | ||
| + task.key_metadata().map_or(0, <[u8]>::len); | ||
| for delete in task.deletes() { | ||
| bytes = bytes | ||
| .saturating_add(delete.file_path().len()) | ||
| .saturating_add(delete.referenced_data_file().map_or(0, str::len)) | ||
| .saturating_add(delete.equality_ids().map_or(0, size_of_val)) | ||
| .saturating_add(delete.key_metadata().map_or(0, <[u8]>::len)); | ||
| } | ||
| bytes | ||
| } | ||
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.
I wouldn’t mention DataFusion Distributed here, to keep this project neutral with respect to its consumers.
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.
Sorry this is entirely an oversight on my part failing to catch this in the agent output.