XiaoHongbo-Hope commented on code in PR #144: URL: https://github.com/apache/paimon-rust/pull/144#discussion_r2958897519
########## crates/paimon/src/common/options.rs: ########## @@ -0,0 +1,185 @@ +// 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. + +//! Configuration options for Paimon catalog. + +use std::collections::HashMap; + +/// Catalog configuration options. +pub struct CatalogOptions; + +impl CatalogOptions { + /// Catalog URI. + pub const URI: &'static str = "uri"; + + /// Metastore type (default: "filesystem"). + pub const METASTORE: &'static str = "metastore"; + + /// Warehouse path. + pub const WAREHOUSE: &'static str = "warehouse"; + + /// Token provider type. + pub const TOKEN_PROVIDER: &'static str = "token.provider"; + + /// Authentication token. + pub const TOKEN: &'static str = "token"; + + /// Prefix for catalog resources. + pub const PREFIX: &'static str = "prefix"; +} + +/// Configuration options container. +/// +/// This is a simple key-value store for catalog configuration. +#[derive(Debug, Clone, Default)] +pub struct Options { + data: HashMap<String, String>, +} + +impl Options { + /// Create a new empty Options instance. + pub fn new() -> Self { + Options { + data: HashMap::new(), + } + } + + /// Create Options from a HashMap. + pub fn from_map(data: HashMap<String, String>) -> Self { + Options { data } + } + + /// Get the underlying HashMap. + pub fn to_map(&self) -> &HashMap<String, String> { + &self.data + } + + /// Get a value by key. + pub fn get(&self, key: &str) -> Option<&String> { + self.data.get(key) + } + + /// Get a value by key with a default. + pub fn get_or_default(&self, key: &str, default: &str) -> String { + self.data + .get(key) + .cloned() + .unwrap_or_else(|| default.to_string()) + } + + /// Set a key-value pair. + pub fn set(&mut self, key: impl Into<String>, value: impl Into<String>) { + self.data.insert(key.into(), value.into()); + } + + /// Check if a key exists. + pub fn contains(&self, key: &str) -> bool { + self.data.contains_key(key) + } + + /// Remove a key. + pub fn remove(&mut self, key: &str) -> Option<String> { + self.data.remove(key) + } + + /// Merge another Options into this one, overwriting existing keys. + pub fn merge(&mut self, other: &Options) { + for (key, value) in &other.data { + self.data.insert(key.clone(), value.clone()); Review Comment: Double check here, user options should be first. -- 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]
