andygrove commented on code in PR #2638: URL: https://github.com/apache/datafusion-ballista/pull/2638#discussion_r4486657749
########## .github/workflows/iceberg.yml: ########## @@ -0,0 +1,72 @@ +# 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. + + +# ballista-iceberg is its own workspace, outside Ballista's, so it doesn't +# block Ballista's build or release; this workflow checks it separately. +name: Ballista Iceberg + +concurrency: + group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} + cancel-in-progress: true + +on: + push: + branches: [ "main" ] + paths: + - "ballista/**" Review Comment: The separate workspace is a good call, but the path deps on `../../ballista/*` plus the `ballista/**` trigger mean it still moves in lockstep with main. I checked against the DataFusion 56 pin in #2718 and `cargo metadata --locked` here fails, so this workflow would go red on that PR and stay red on main until the integration catches up. Any dependency bump inside `ballista/*` trips `--locked` too. Since #2752 isn't in a release yet, could we pin the Ballista crates to a git rev of this repo for now (one that includes #2752) and drop `ballista/**` from the triggers? Then switch to crates.io once 56 ships. That gives the real release boundary wirybeaver was asking for. ########## integrations/iceberg/src/physical_codec.rs: ########## @@ -0,0 +1,110 @@ +// 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. + +//! Sends Iceberg scans from the scheduler to executors. + +use std::sync::Arc; + +use ballista_core::serde::BallistaPhysicalExtensionCodec; +use datafusion::arrow::datatypes::SchemaRef; +use datafusion::common::{Result, not_impl_err}; +use datafusion::datasource::source::DataSourceExec; +use datafusion::execution::TaskContext; +use datafusion::physical_plan::ExecutionPlan; +use datafusion_proto::physical_plan::{ + ComposedPhysicalExtensionCodec, PhysicalExtensionCodec, + PhysicalProtoConverterExtension, +}; +use iceberg::expr::Predicate; +use iceberg_datafusion::read::IcebergDataSource; +use serde::{Deserialize, Serialize}; + +use crate::wire::{self, TableWire}; + +#[derive(Debug, Serialize, Deserialize)] +struct ScanWire { + table: TableWire, + snapshot_id: Option<i64>, + /// The scan's output schema, already projected. + schema: SchemaRef, + predicate: Option<Predicate>, + fetch: Option<usize>, +} + +/// A [`PhysicalExtensionCodec`] for scans of an [`IcebergDataSource`]. It +/// fails on anything else, so compose it after other codecs with +/// [`ComposedPhysicalExtensionCodec`], as [`register_iceberg`] does. +/// +/// [`register_iceberg`]: crate::register_iceberg +#[derive(Debug, Default)] +pub struct IcebergPhysicalCodec; + +impl IcebergPhysicalCodec { + /// Composes `codec`, or Ballista's when `None`, with this codec after it. + pub(crate) fn after( + codec: Option<Arc<dyn PhysicalExtensionCodec>>, + ) -> Arc<dyn PhysicalExtensionCodec> { + let codec = + codec.unwrap_or_else(|| Arc::new(BallistaPhysicalExtensionCodec::default())); + Arc::new(ComposedPhysicalExtensionCodec::new(vec![ + codec, + Arc::new(Self), + ])) + } +} + +impl PhysicalExtensionCodec for IcebergPhysicalCodec { + fn try_decode( + &self, + buf: &[u8], + _inputs: &[Arc<dyn ExecutionPlan>], + _ctx: &TaskContext, + _proto_converter: &dyn PhysicalProtoConverterExtension, + ) -> Result<Arc<dyn ExecutionPlan>> { + let scan: ScanWire = wire::decode(buf)?; + let source = IcebergDataSource::builder(scan.table.load()?, scan.schema) + .with_snapshot_id(scan.snapshot_id) + .with_predicate(scan.predicate) + .with_fetch(scan.fetch) + .build()?; + Ok(DataSourceExec::from_data_source(source)) + } + + fn try_encode( Review Comment: One guard I'd like before this lands. `IcebergDataSource` reports a single partition at the pinned rev, but once upstream splits scans into partitions, Ballista's per-task restriction doesn't know how to slice a custom `DataSource`. Each task would then read every partition and rows would come back duplicated. Could `try_encode` refuse a scan with more than one partition, with a `not_impl_err` pointing at the limitation? Then the dependency bump that changes this fails loudly instead of returning wrong results. ########## integrations/iceberg/src/catalog.rs: ########## @@ -0,0 +1,290 @@ +// 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. + +//! Pins catalog-backed tables to one version while a query is planned. + +use std::collections::HashMap; +use std::sync::Arc; + +use async_trait::async_trait; +use datafusion::arrow::datatypes::SchemaRef; +use datafusion::catalog::view::ViewTable; +use datafusion::catalog::{ + CatalogProvider, CatalogProviderList, SchemaProvider, Session, TableProvider, +}; +use datafusion::common::tree_node::{Transformed, TreeNodeRecursion}; +use datafusion::common::{DataFusionError, Result, not_impl_err}; +use datafusion::datasource::source::DataSourceExec; +use datafusion::datasource::{DefaultTableSource, TableType, provider_as_source}; +use datafusion::logical_expr::dml::InsertOp; +use datafusion::logical_expr::{ + Expr, LogicalPlan, TableProviderFilterPushDown, TableScan, +}; +use datafusion::physical_plan::ExecutionPlan; +use futures::future::try_join_all; +use iceberg::TableIdent; +use iceberg::table::Table; +use iceberg_datafusion::read::IcebergDataSource; +use iceberg_datafusion::{IcebergCatalogTableProvider, to_datafusion_error}; + +/// A session's catalogs, serving each catalog-backed Iceberg table as a +/// [`PinnedTable`], and each view with its Iceberg tables pinned again. +/// +/// DataFusion looks up each table a query names once, while planning it, so +/// every scan of a table in the query reads the same version, and encoding the +/// plan needs no I/O. A view stores the plan it was created with, so its tables +/// are pinned again each time a query names it, and it reads the latest +/// versions, as it would in DataFusion. +#[derive(Debug)] +pub(crate) struct PinningCatalogList(pub(crate) Arc<dyn CatalogProviderList>); + +impl CatalogProviderList for PinningCatalogList { + fn register_catalog( + &self, + name: String, + catalog: Arc<dyn CatalogProvider>, + ) -> Option<Arc<dyn CatalogProvider>> { + self.0.register_catalog(name, catalog) + } + + fn catalog_names(&self) -> Vec<String> { + self.0.catalog_names() + } + + fn catalog(&self, name: &str) -> Option<Arc<dyn CatalogProvider>> { Review Comment: Small one. Since `PinningCatalogList::catalog` wraps every catalog, `ctx.catalog("x")` no longer downcasts to its concrete type after `register_iceberg`. Maybe worth a line in the docs, or exposing the inner catalog so embedders can reach it. -- 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]
