xbattlax commented on code in PR #2029:
URL: https://github.com/apache/iceberg-rust/pull/2029#discussion_r2697353400


##########
crates/examples/src/datafusion_integration.rs:
##########
@@ -0,0 +1,170 @@
+// 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.
+
+//! Example demonstrating DataFusion integration with Apache Iceberg.
+//!
+//! This example shows how to:
+//! - Set up an Iceberg catalog with DataFusion
+//! - Create tables using SQL
+//! - Insert and query data
+//! - Query metadata tables
+
+use std::collections::HashMap;
+use std::sync::Arc;
+
+use datafusion::execution::context::SessionContext;
+use datafusion::execution::session_state::SessionStateBuilder;
+use iceberg::memory::{MEMORY_CATALOG_WAREHOUSE, MemoryCatalogBuilder};
+use iceberg::{Catalog, CatalogBuilder, NamespaceIdent};
+use iceberg_datafusion::{IcebergCatalogProvider, IcebergTableProviderFactory};
+use tempfile::TempDir;
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+    // Create a temporary directory for the warehouse
+    let temp_dir = TempDir::new()?;
+    let warehouse_path = temp_dir.path().to_str().unwrap().to_string();
+
+    // ANCHOR: catalog_setup
+    // Create an in-memory Iceberg catalog
+    let iceberg_catalog = MemoryCatalogBuilder::default()
+        .load(
+            "memory",
+            HashMap::from([(MEMORY_CATALOG_WAREHOUSE.to_string(), 
warehouse_path)]),
+        )
+        .await?;
+
+    // Create a namespace for our tables
+    let namespace = NamespaceIdent::new("demo".to_string());
+    iceberg_catalog
+        .create_namespace(&namespace, HashMap::new())
+        .await?;
+
+    // Create the IcebergCatalogProvider and register it with DataFusion
+    let catalog_provider =
+        
Arc::new(IcebergCatalogProvider::try_new(Arc::new(iceberg_catalog)).await?);
+
+    let ctx = SessionContext::new();
+    ctx.register_catalog("iceberg", catalog_provider);

Review Comment:
   Good call, fixed!



-- 
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]

Reply via email to