NoahKusaba commented on code in PR #2638: URL: https://github.com/apache/datafusion-ballista/pull/2638#discussion_r4487992774
########## .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: Good catch. Pinned the Ballista crates to d151e327 (includes #2752) and dropped `ballista/**` from the triggers in eb78175a. Ill ########## 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: Done in 8f731f51: `try_encode` now refuses a scan with more than one partition, and the docs mention it. ########## 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: Documented in f11230e1: keep the `Arc` you registered to reach the concrete catalog. -- 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]
