toutane commented on code in PR #2298: URL: https://github.com/apache/iceberg-rust/pull/2298#discussion_r3110991920
########## crates/integrations/datafusion/src/physical_plan/partitioned_scan.rs: ########## @@ -0,0 +1,171 @@ +// 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 std::any::Any; +use std::sync::Arc; + +use datafusion::arrow::datatypes::SchemaRef as ArrowSchemaRef; +use datafusion::error::Result as DFResult; +use datafusion::execution::{SendableRecordBatchStream, TaskContext}; +use datafusion::physical_expr::EquivalenceProperties; +use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType}; +use datafusion::physical_plan::stream::RecordBatchStreamAdapter; +use datafusion::physical_plan::{DisplayAs, ExecutionPlan, Partitioning, PlanProperties}; +use futures::TryStreamExt; +use iceberg::arrow::ArrowReaderBuilder; +use iceberg::io::FileIO; +use iceberg::scan::FileScanTask; + +use crate::to_datafusion_error; + +/// A DataFusion [`ExecutionPlan`] that reads one [`FileScanTask`] per partition. +/// +/// Display information (projection, predicate) is derived at runtime from the output schema and +/// the tasks rather than stored as dedicated struct fields. +#[derive(Debug, Clone)] +pub struct IcebergPartitionedScan { + tasks: Vec<FileScanTask>, + file_io: FileIO, + plan_properties: Arc<PlanProperties>, +} + +impl IcebergPartitionedScan { + pub fn new(tasks: Vec<FileScanTask>, file_io: FileIO, schema: ArrowSchemaRef) -> Self { + let n_partitions = tasks.len(); + let plan_properties = Self::compute_properties(schema, n_partitions); + Self { + tasks, + file_io, + plan_properties, + } + } + + pub fn tasks(&self) -> &[FileScanTask] { + &self.tasks + } + + pub fn file_io(&self) -> &FileIO { + &self.file_io + } + + fn compute_properties(schema: ArrowSchemaRef, n_partitions: usize) -> Arc<PlanProperties> { + Arc::new(PlanProperties::new( + EquivalenceProperties::new(schema), + Partitioning::UnknownPartitioning(n_partitions), + EmissionType::Incremental, + Boundedness::Bounded, + )) + } +} + +impl ExecutionPlan for IcebergPartitionedScan { + fn name(&self) -> &str { + "IcebergPartitionedScan" + } + + fn as_any(&self) -> &dyn Any { + self + } + + fn children(&self) -> Vec<&Arc<dyn ExecutionPlan + 'static>> { + vec![] + } + + fn with_new_children( + self: Arc<Self>, + _children: Vec<Arc<dyn ExecutionPlan>>, + ) -> DFResult<Arc<dyn ExecutionPlan>> { + Ok(self) Review Comment: Yes, you're right thanks! Pushed a fix that returns a `DataFusionError::Internal`, matching the pattern used in `IcebergCommitExec::with_new_children`. Side note: `IcebergTableScan::with_new_children` has the same issue. This could be the subject of another PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
