Skip to content

Commit

Permalink
support projection pushdown for datafusion iceberg
Browse files Browse the repository at this point in the history
  • Loading branch information
FANNG1 committed Sep 1, 2024
1 parent 0d412b9 commit e3a58be
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
37 changes: 37 additions & 0 deletions crates/examples/src/datafusion_read_data.rs
Original file line number Diff line number Diff line change
@@ -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);
}
31 changes: 31 additions & 0 deletions crates/examples/src/utils.rs
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 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)
}

0 comments on commit e3a58be

Please sign in to comment.