From e3a58bec6293a1c6a21794bf08022719b969a56f Mon Sep 17 00:00:00 2001 From: fanng Date: Sun, 1 Sep 2024 19:32:44 +0800 Subject: [PATCH] support projection pushdown for datafusion iceberg --- crates/examples/src/datafusion_read_data.rs | 37 +++++++++++++++++++++ crates/examples/src/utils.rs | 31 +++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 crates/examples/src/datafusion_read_data.rs create mode 100644 crates/examples/src/utils.rs diff --git a/crates/examples/src/datafusion_read_data.rs b/crates/examples/src/datafusion_read_data.rs new file mode 100644 index 000000000..56fac6251 --- /dev/null +++ b/crates/examples/src/datafusion_read_data.rs @@ -0,0 +1,37 @@ +// 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::sync::Arc; + +use datafusion::prelude::SessionContext; +use iceberg_datafusion::IcebergCatalogProvider; + +mod utils; + +#[tokio::main] +async fn main() { + let iceberg_catalog = utils::get_rest_catalog(); + + let client = Arc::new(iceberg_catalog); + let catalog = Arc::new(IcebergCatalogProvider::try_new(client).await.unwrap()); + + let ctx = SessionContext::new(); + ctx.register_catalog("catalog", catalog); + let df = ctx.sql("select * from catalog.ns.table1").await.unwrap(); + let data = df.collect().await.unwrap(); + println!("{:?}", data); +} diff --git a/crates/examples/src/utils.rs b/crates/examples/src/utils.rs new file mode 100644 index 000000000..2784314f0 --- /dev/null +++ b/crates/examples/src/utils.rs @@ -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 std::env; + +use iceberg_catalog_rest::{RestCatalog, RestCatalogConfig}; + +fn get_catalog_uri_from_env() -> String { + env::var("CATALOG_URI").unwrap_or("http://localhost:8080".to_string()) +} + +pub fn get_rest_catalog() -> RestCatalog { + let config = RestCatalogConfig::builder() + .uri(get_catalog_uri_from_env()) + .build(); + RestCatalog::new(config) +}