You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "QuakeWang (via GitHub)" <gi...@apache.org> on 2024/08/22 06:45:01 UTC
[PR] feat: add catalog API [paimon-rust]
QuakeWang opened a new pull request, #62:
URL: https://github.com/apache/paimon-rust/pull/62
fix: #52
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#issuecomment-2321121559
Also invite @Aitozi for a reivew.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1738572006
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
+
+ /// Lists all tables in the specified database.
+ async fn list_tables(&self, database_name: &str) -> Result<Vec<String>>;
+
+ /// Checks if a table exists.
+ async fn table_exists(&self, identifier: &Identifier) -> Result<bool> {
+ match self.get_table(identifier).await {
+ Ok(_) => Ok(true),
+ Err(e) => match e {
+ crate::error::Error::TableNotExist { .. } => Ok(false),
+ _ => Err(e),
+ },
+ }
+ }
+
+ /// Drops a table.
+ async fn drop_table(&self, identifier: &Identifier, ignore_if_not_exists: bool) -> Result<()>;
+
+ /// Creates a new table.
+ async fn create_table(
+ &self,
+ identifier: &Identifier,
+ schema: TableSchema,
+ ignore_if_exists: bool,
+ ) -> Result<()>;
+
+ /// Renames a table.
+ async fn rename_table(
+ &self,
+ from_table: &Identifier,
+ to_table: &Identifier,
+ ignore_if_not_exists: bool,
+ ) -> Result<()>;
+
+ /// Alters an existing table.
+ async fn alter_table(
+ &self,
+ identifier: &Identifier,
+ changes: Vec<SchemaChange>,
+ ignore_if_not_exists: bool,
+ ) -> Result<()>;
+
+ /// Drops a partition from the specified table.
+ async fn drop_partition(
+ &self,
+ identifier: &Identifier,
+ partitions: &HashMap<String, String>,
+ ) -> Result<()>;
+
+ /// Returns whether this catalog is case-sensitive.
+ fn case_sensitive(&self) -> bool {
Review Comment:
I believe we can consolidate those metadata-related items into a single API.
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
Review Comment:
Implementing `Table` makes this trait non-object safe. Perhaps we could return a `Table` struct instead.
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
+
+ /// Lists all tables in the specified database.
+ async fn list_tables(&self, database_name: &str) -> Result<Vec<String>>;
+
+ /// Checks if a table exists.
+ async fn table_exists(&self, identifier: &Identifier) -> Result<bool> {
Review Comment:
It's a bit surprising that we use `Identifier` in some places but not in others. Shouldn't we be consistent?
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
+
+ /// Lists all tables in the specified database.
+ async fn list_tables(&self, database_name: &str) -> Result<Vec<String>>;
+
+ /// Checks if a table exists.
+ async fn table_exists(&self, identifier: &Identifier) -> Result<bool> {
+ match self.get_table(identifier).await {
+ Ok(_) => Ok(true),
+ Err(e) => match e {
+ crate::error::Error::TableNotExist { .. } => Ok(false),
+ _ => Err(e),
+ },
+ }
+ }
+
+ /// Drops a table.
+ async fn drop_table(&self, identifier: &Identifier, ignore_if_not_exists: bool) -> Result<()>;
+
+ /// Creates a new table.
+ async fn create_table(
+ &self,
+ identifier: &Identifier,
+ schema: TableSchema,
+ ignore_if_exists: bool,
+ ) -> Result<()>;
+
+ /// Renames a table.
+ async fn rename_table(
+ &self,
+ from_table: &Identifier,
+ to_table: &Identifier,
+ ignore_if_not_exists: bool,
+ ) -> Result<()>;
+
+ /// Alters an existing table.
+ async fn alter_table(
+ &self,
+ identifier: &Identifier,
+ changes: Vec<SchemaChange>,
+ ignore_if_not_exists: bool,
+ ) -> Result<()>;
+
+ /// Drops a partition from the specified table.
+ async fn drop_partition(
+ &self,
+ identifier: &Identifier,
+ partitions: &HashMap<String, String>,
+ ) -> Result<()>;
+
+ /// Returns whether this catalog is case-sensitive.
+ fn case_sensitive(&self) -> bool {
+ true
+ }
+}
+
+/// Identifies an object in a catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Identifier.java#L35>
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct Identifier {
+ database: String,
+ table: String,
+}
+
+impl Identifier {
+ pub const UNKNOWN_DATABASE: &'static str = "unknown";
+
+ /// Create a new identifier.
+ pub fn new(database: String, table: String) -> Self {
+ Self { database, table }
+ }
+
+ /// Get the table name.
+ pub fn database_name(&self) -> &str {
+ &self.database
+ }
+
+ /// Get the table name.
+ pub fn object_name(&self) -> &str {
+ &self.table
+ }
+
+ /// Get the full name of the identifier.
+ pub fn full_name(&self) -> String {
+ if self.database == Self::UNKNOWN_DATABASE {
+ self.table.clone()
+ } else {
+ format!("{}.{}", self.database, self.table)
+ }
+ }
+
+ /// Get the full name of the identifier with a specified character.
+ pub fn escaped_full_name(&self) -> String {
+ self.escaped_full_name_with_char('`')
+ }
+
+ /// Get the full name of the identifier with a specified character.
+ pub fn escaped_full_name_with_char(&self, escape_char: char) -> String {
+ format!(
+ "{0}{1}{0}.{0}{2}{0}",
+ escape_char, self.database, self.table
+ )
+ }
+
+ /// Create a new identifier.
+ pub fn create(db: &str, table: &str) -> Self {
+ Self::new(db.to_string(), table.to_string())
+ }
+}
+
+impl fmt::Display for Identifier {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{}", self.full_name())
+ }
+}
+
+/// A table provides basic abstraction for a table type and table scan, and table read.
+///
+/// Impl Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/table/Table.java#L41>
+pub trait Table {
Review Comment:
I feel like `Table` should be a struct instead of a trait.
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
Review Comment:
The catalog is integrated with file I/O, which is somewhat surprising to me.
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
Review Comment:
Using `const` will make this trait non-object safe, preventing users from invoking `Catalog` through `Arc<dyn Catalog>`. How about introducing a new API, such as `info`, for this purpose?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(catalog): add catalog API [paimon-rust]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#issuecomment-2717952450
I believe this PR is good to go.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1741947129
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
Review Comment:
I need some input from @JingsongLi, @SteNicholas, and @Aitozi: Should a catalog be coupled with a specific file I/O?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(catalog): add catalog API [paimon-rust]
Posted by "JiaQiTang98 (via GitHub)" <gi...@apache.org>.
JiaQiTang98 commented on PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#issuecomment-2717834623
Hi teams, any update about the PR? Can we merge it and do something based on it?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1741686346
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
Review Comment:
> The catalog is integrated with file I/O, which is somewhat surprising to me.
The [FileIO fileIO()](https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L55) function can be found at here. Do you have some good suggestions to deal this?
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
Review Comment:
> Implementing `Table` makes this trait non-object safe. Perhaps we could return a `Table` struct instead.
Ok, I will create a Table struct instead of trait.
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
+
+ /// Lists all tables in the specified database.
+ async fn list_tables(&self, database_name: &str) -> Result<Vec<String>>;
+
+ /// Checks if a table exists.
+ async fn table_exists(&self, identifier: &Identifier) -> Result<bool> {
Review Comment:
> It's a bit surprising that we use `Identifier` in some places but not in others. Shouldn't we be consistent?
In the Java version, `Identifier` is usually used for table-related methods.
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
Review Comment:
> Do APIs like `lockFactory` need to be added?
I think this PR will add the struct and definition first, maybe we can add some APIs like `lockFactory` in the further PRs.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(catalog): add catalog API [paimon-rust]
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1750118340
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
Review Comment:
@QuakeWang, @Xuanwo, @Aitozi, the warehoused path is required to determine which FileIO to use. This interface makes sense to me.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "zmlcc (via GitHub)" <gi...@apache.org>.
zmlcc commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1748306164
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
Review Comment:
> > In the java version,`Table` interface represents various specialized table types. Is it possible to define a simple `Table` struct in rust ? What about returning `Box<dyn Table>` instead?
>
> Maybe we will not use `dyn`, when returning `Box<dyn Table>` has some error like `error[E0404]: expected trait, found struct Table`. In Rust, `dyn` is used for dynamic dispatch with trait objects.
Why `Box<dyn Table>` would give `error[E0404]` ? It should not when using properly.
I think in many cases, the return value of `get_table` needs to be downcast to a concrete type, so it makes sense to use `dyn Table`.
Alternatively, maybe using `enum Table` is feasible
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(catalog): add catalog API [paimon-rust]
Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#issuecomment-2733856141
> @QuakeWang Hi, do you mind if I continue your job?
Sorry I've been busy recently and didn't check back sooner. Please feel free to do this with this as planned.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "Aitozi (via GitHub)" <gi...@apache.org>.
Aitozi commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1742909401
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
Review Comment:
Currently, the catalog is bind with a warehouse path which determines the fileIO. So these two things are coupled in current shape, and the table's schema are also retrieved from the filesystem. Also like to see some inputs from @JingsongLi @SteNicholas
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1748018186
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
+
+ /// Lists all tables in the specified database.
+ async fn list_tables(&self, database_name: &str) -> Result<Vec<String>>;
+
+ /// Checks if a table exists.
+ async fn table_exists(&self, identifier: &Identifier) -> Result<bool> {
+ match self.get_table(identifier).await {
+ Ok(_) => Ok(true),
+ Err(e) => match e {
+ crate::error::Error::TableNotExist { .. } => Ok(false),
+ _ => Err(e),
+ },
+ }
+ }
+
+ /// Drops a table.
+ async fn drop_table(&self, identifier: &Identifier, ignore_if_not_exists: bool) -> Result<()>;
+
+ /// Creates a new table.
+ async fn create_table(
+ &self,
+ identifier: &Identifier,
+ schema: TableSchema,
+ ignore_if_exists: bool,
+ ) -> Result<()>;
+
+ /// Renames a table.
+ async fn rename_table(
+ &self,
+ from_table: &Identifier,
+ to_table: &Identifier,
+ ignore_if_not_exists: bool,
+ ) -> Result<()>;
+
+ /// Alters an existing table.
+ async fn alter_table(
+ &self,
+ identifier: &Identifier,
+ changes: Vec<SchemaChange>,
+ ignore_if_not_exists: bool,
+ ) -> Result<()>;
+
+ /// Drops a partition from the specified table.
+ async fn drop_partition(
+ &self,
+ identifier: &Identifier,
+ partitions: &HashMap<String, String>,
+ ) -> Result<()>;
+
+ /// Returns whether this catalog is case-sensitive.
+ fn case_sensitive(&self) -> bool {
+ true
+ }
+}
+
+/// Identifies an object in a catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Identifier.java#L35>
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct Identifier {
+ database: String,
+ table: String,
+}
+
+impl Identifier {
+ pub const UNKNOWN_DATABASE: &'static str = "unknown";
+
+ /// Create a new identifier.
+ pub fn new(database: String, table: String) -> Self {
+ Self { database, table }
+ }
+
+ /// Get the table name.
+ pub fn database_name(&self) -> &str {
+ &self.database
+ }
+
+ /// Get the table name.
+ pub fn object_name(&self) -> &str {
+ &self.table
+ }
+
+ /// Get the full name of the identifier.
+ pub fn full_name(&self) -> String {
+ if self.database == Self::UNKNOWN_DATABASE {
+ self.table.clone()
+ } else {
+ format!("{}.{}", self.database, self.table)
+ }
+ }
+
+ /// Get the full name of the identifier with a specified character.
+ pub fn escaped_full_name(&self) -> String {
+ self.escaped_full_name_with_char('`')
+ }
+
+ /// Get the full name of the identifier with a specified character.
+ pub fn escaped_full_name_with_char(&self, escape_char: char) -> String {
+ format!(
+ "{0}{1}{0}.{0}{2}{0}",
+ escape_char, self.database, self.table
+ )
+ }
+
+ /// Create a new identifier.
+ pub fn create(db: &str, table: &str) -> Self {
+ Self::new(db.to_string(), table.to_string())
+ }
+}
+
+impl fmt::Display for Identifier {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{}", self.full_name())
+ }
+}
+
+/// A table provides basic abstraction for a table type and table scan, and table read.
+///
+/// Impl Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/table/Table.java#L41>
+pub trait Table {
Review Comment:
I will create a simple `Table` struct as the return value of the get_table method. With more design details about `Table` we can create a new issue for discussion. What do you think of it?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1748002247
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
Review Comment:
> In the java version,`Table` interface represents various specialized table types. Is it possible to define a simple `Table` struct in rust ? What about returning `Box<dyn Table>` instead?
Maybe we will not use `dyn`, when returning `Box<dyn Table>` has some error like `error[E0404]: expected trait, found struct Table`. In Rust, `dyn` is used for dynamic dispatch with trait objects.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(catalog): add catalog API [paimon-rust]
Posted by "JiaQiTang98 (via GitHub)" <gi...@apache.org>.
JiaQiTang98 commented on PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#issuecomment-2719618829
@QuakeWang Hi, do you mind if I continue your job?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1741675036
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
Review Comment:
OK, I will do it later.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "zmlcc (via GitHub)" <gi...@apache.org>.
zmlcc commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1746640296
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
+ /// Returns the catalog options.
+ fn options(&self) -> &HashMap<String, String>;
+
+ /// Returns the FileIO instance.
+ fn file_io(&self) -> &FileIO;
+
+ /// Lists all databases in this catalog.
+ async fn list_databases(&self) -> Result<Vec<String>>;
+
+ /// Checks if a database exists in this catalog.
+ async fn database_exists(&self, database_name: &str) -> Result<bool>;
+
+ /// Creates a new database.
+ async fn create_database(
+ &self,
+ name: &str,
+ ignore_if_exists: bool,
+ properties: Option<HashMap<String, String>>,
+ ) -> Result<()>;
+
+ /// Loads database properties.
+ async fn load_database_properties(&self, name: &str) -> Result<HashMap<String, String>>;
+
+ /// Drops a database.
+ async fn drop_database(
+ &self,
+ name: &str,
+ ignore_if_not_exists: bool,
+ cascade: bool,
+ ) -> Result<()>;
+
+ /// Returns a Table instance for the specified identifier.
+ async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
Review Comment:
In the java version,`Table` interface represents various specialized table types. Is it possible to define a simple `Table` struct in rust ?
What about returning `Box<dyn Table>` instead?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add catalog API [paimon-rust]
Posted by "XuQianJin-Stars (via GitHub)" <gi...@apache.org>.
XuQianJin-Stars commented on code in PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#discussion_r1739632972
##########
crates/paimon/src/catalog/mod.rs:
##########
@@ -0,0 +1,254 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt;
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use chrono::Duration;
+
+use crate::error::Result;
+use crate::io::FileIO;
+use crate::spec::{RowType, SchemaChange, TableSchema};
+
+/// This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
+///
+/// Impl References: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java#L42>
+#[async_trait]
+pub trait Catalog: Send + Sync {
+ const DEFAULT_DATABASE: &'static str = "default";
+ const SYSTEM_TABLE_SPLITTER: &'static str = "$";
+ const SYSTEM_DATABASE_NAME: &'static str = "sys";
+
+ /// Returns the warehouse root path containing all database directories in this catalog.
+ fn warehouse(&self) -> &str;
+
Review Comment:
Do APIs like `lockFactory` need to be added?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(catalog): add catalog API [paimon-rust]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #62:
URL: https://github.com/apache/paimon-rust/pull/62#issuecomment-2717955091
> Hi teams, any update about the PR? Can we merge it and do something based on it?
I believe there some unresolved comments left: https://github.com/apache/paimon-rust/pull/62#discussion_r1738563385
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org