kszucs commented on code in PR #2375:
URL: https://github.com/apache/iceberg-rust/pull/2375#discussion_r3221101656


##########
crates/storage/opendal/src/hf.rs:
##########
@@ -0,0 +1,348 @@
+// 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.
+
+//! HuggingFace Hub storage backend.
+
+use std::collections::HashMap;
+
+use iceberg::io::{HF_ENDPOINT, HF_REVISION, HF_TOKEN};
+use iceberg::{Error, ErrorKind, Result};
+use opendal::{Configurator, Operator, OperatorUri};
+
+use crate::utils::from_opendal_error;
+
+// ---------------------------------------------------------------------------
+// Minimal URI parser — extracts only what the caller needs.
+// TODO: remove once opendal-service-hf exports its URI parser publicly.
+// ---------------------------------------------------------------------------
+
+/// Repository type of a HuggingFace Hub repository.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum HfRepoType {
+    /// Model repository (`models/` prefix).
+    Model,
+    /// Dataset repository (`datasets/` prefix).
+    Dataset,
+    /// Spaces application repository (`spaces/` prefix).
+    Space,
+    /// XET-backed object-storage bucket (`buckets/` prefix).
+    Bucket,
+}
+
+impl HfRepoType {
+    /// Parse a repo-type keyword (singular or plural) into the corresponding 
variant.
+    fn parse(s: &str) -> Option<Self> {
+        match s.to_lowercase().replace(' ', "").as_str() {
+            "model" | "models" => Some(Self::Model),
+            "dataset" | "datasets" => Some(Self::Dataset),
+            "space" | "spaces" => Some(Self::Space),
+            "bucket" | "buckets" => Some(Self::Bucket),
+            _ => None,
+        }
+    }
+
+    fn canonical(self) -> &'static str {
+        match self {
+            Self::Model => "models",
+            Self::Dataset => "datasets",
+            Self::Space => "spaces",
+            Self::Bucket => "buckets",
+        }
+    }
+}
+
+/// Parsed HuggingFace URI: `hf://<repo_type>/<repo_id>[@<revision>][/<path>]`.
+///
+/// `repo_type` must be explicitly specified — there is no implicit default.
+/// Only the fields required by this crate are stored; revision is consumed
+/// during parsing but not retained.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub(crate) struct HfUri {

Review Comment:
   Almost identical to HfUri in opendal just not exposed yet.



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