james-willis commented on code in PR #1125:
URL: https://github.com/apache/sedona-db/pull/1125#discussion_r3726832067


##########
rust/sedona-datasource/src/url_table.rs:
##########
@@ -0,0 +1,218 @@
+// 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.
+
+//! URL-as-table resolution for directory-shaped external formats.
+//!
+//! **Experimental**: the shape of this hook may change.
+//!
+//! DataFusion's [`enable_url_table`](SessionContext::enable_url_table)
+//! installs a resolver (`DynamicListTableFactory`) that always builds a
+//! `ListingTable` for a bare `FROM '<url>'`: it lists the files under the
+//! URL prefix, takes the first object it finds, and picks a file format by
+//! *that object's* extension. For a directory-shaped format like Zarr —
+//! where the "table" is the `.zarr` directory itself, not the files within
+//! it — this lists the directory contents and tries to parse an inner chunk
+//! (e.g. `zarr.json` or a raw binary chunk) as the wrong format, which fails.
+//!
+//! [`enable_sedona_url_table`] installs [`SedonaUrlTableFactory`] instead. It
+//! matches the URL's extension against the session's registered
+//! [`ExternalFormatSpec`](crate::spec::ExternalFormatSpec)s: when the match
+//! is a directory-shaped format
+//! 
([`list_single_object`](crate::spec::ExternalFormatSpec::list_single_object)
+//! `== true`), it builds a
+//! [`SingleObjectExternalTable`](crate::provider::SingleObjectExternalTable)
+//! (via [`external_table`]) that passes the URL through untouched. Everything
+//! else — the file-shaped formats DataFusion already handles (GeoParquet,
+//! CSV, ...) — delegates to DataFusion's default resolver unchanged.
+
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use datafusion::{
+    catalog::TableProvider,
+    datasource::{dynamic_file::DynamicListTableFactory, 
listing::ListingTableUrl},
+    execution::SessionState,
+    prelude::SessionContext,
+};
+use datafusion_catalog::{DynamicFileCatalog, UrlTableFactory};
+use datafusion_common::Result;
+use datafusion_session::SessionStore;
+
+use crate::{format::ExternalFormatFactory, provider::external_table};
+
+/// Install SedonaDB's URL-as-table resolver on `ctx`.
+///
+/// Drop-in replacement for DataFusion's
+/// [`SessionContext::enable_url_table`] that additionally routes
+/// directory-shaped external formats through the single-object table
+/// path. Mirrors `enable_url_table`'s wiring: it wraps the current catalog
+/// list in a [`DynamicFileCatalog`] backed by a [`SedonaUrlTableFactory`],
+/// then points the factory's session store at the (unchanged) session
+/// state so it can resolve registered file formats at query time.
+///
+/// **Experimental.**
+pub fn enable_sedona_url_table(ctx: SessionContext) -> SessionContext {

Review Comment:
   done



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

Reply via email to