alamb commented on code in PR #13722:
URL: https://github.com/apache/datafusion/pull/13722#discussion_r1893176204


##########
datafusion-examples/examples/remote_catalog.rs:
##########
@@ -0,0 +1,404 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// 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.
+
+/// This example shows how to implement the DataFusion [`CatalogProvider`] API
+/// for catalogs that are remote (require network access) and/or offer only
+/// asynchronous APIs such as [Polaris], [Unity], and [Hive].
+///
+/// Integrating with this catalogs is a bit more complex than with local
+/// catalogs because calls like `ctx.sql("SELECT * FROM db.schm.tbl")` may need
+/// to perform remote network requests, but many Catalog APIs are synchronous.
+/// See the documentation on [`CatalogProvider`] for more details.
+///
+/// [`CatalogProvider`]: datafusion_catalog::CatalogProvider
+///
+/// [Polaris]: https://github.com/apache/polaris
+/// [Unity]: https://github.com/unitycatalog/unitycatalog
+/// [Hive]: https://hive.apache.org/
+use arrow::array::record_batch;
+use arrow_schema::{Field, Fields, Schema, SchemaRef};
+use async_trait::async_trait;
+use datafusion::catalog::{SchemaProvider, TableProvider};
+use datafusion::common::DataFusionError;
+use datafusion::common::Result;
+use datafusion::execution::SendableRecordBatchStream;
+use datafusion::physical_plan::memory::MemoryExec;
+use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
+use datafusion::physical_plan::ExecutionPlan;
+use datafusion::prelude::{DataFrame, SessionContext};
+use datafusion_catalog::Session;
+use datafusion_common::{
+    assert_batches_eq, internal_datafusion_err, plan_err, TableReference,
+};
+use datafusion_expr::{Expr, TableType};
+use futures::TryStreamExt;
+use std::any::Any;
+use std::sync::{Arc, Mutex};
+
+#[tokio::main]
+async fn main() -> Result<()> {
+    // As always, we create a session context to interact with DataFusion
+    let ctx = SessionContext::new();
+
+    // Make a connection to the remote catalog, asynchronously, and configure 
it
+    let remote_catalog_interface = RemoteCatalogInterface::connect().await?;
+
+    // Register a SchemaProvider for tables in a schema named "remote_schema".
+    //
+    // This will let DataFusion query tables such as
+    // `datafusion.remote_schema.remote_table`
+    let remote_schema: Arc<dyn SchemaProvider> =
+        Arc::new(RemoteSchema::new(Arc::new(remote_catalog_interface)));
+    ctx.catalog("datafusion")
+        .ok_or_else(|| internal_datafusion_err!("default catalog was not 
installed"))?
+        .register_schema("remote_schema", Arc::clone(&remote_schema))?;
+
+    // Here is a query that selects data from a table in the remote catalog.
+    let sql = "SELECT * from remote_schema.remote_table";
+
+    // While the `SessionContext::sql` interface is async, but it does not
+    // support asynchronous access to catalogs, so the following query errors.
+    let results = ctx.sql(sql).await;
+    assert_eq!(
+        results.unwrap_err().to_string(),
+        "Error during planning: table 'datafusion.remote_schema.remote_table' 
not found"
+    );
+
+    // Instead, to use a remote catalog, we must use lower level APIs on

Review Comment:
   > Ok, tomorrow turned into next week but here we go: #13800
   
   LOL this is the story of my life the last 2 weeks



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