Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(catalog): add catalog API #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

QuakeWang
Copy link
Contributor

fix: #52

/// 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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will do it later.

fn options(&self) -> &HashMap<String, String>;

/// Returns the FileIO instance.
fn file_io(&self) -> &FileIO;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catalog is integrated with file I/O, which is somewhat surprising to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catalog is integrated with file I/O, which is somewhat surprising to me.

The FileIO fileIO() function can be found at here. Do you have some good suggestions to deal this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need some input from @JingsongLi, @SteNicholas, and @Aitozi: Should a catalog be coupled with a specific file I/O?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuakeWang, @Xuanwo, @Aitozi, the warehoused path is required to determine which FileIO to use. This interface makes sense to me.

) -> Result<()>;

/// Returns a Table instance for the specified identifier.
async fn get_table(&self, identifier: &Identifier) -> Result<impl Table>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing Table makes this trait non-object safe. Perhaps we could return a Table struct instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit surprising that we use Identifier in some places but not in others. Shouldn't we be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

) -> Result<()>;

/// Returns whether this catalog is case-sensitive.
fn case_sensitive(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can consolidate those metadata-related items into a single API.

/// 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like Table should be a struct instead of a trait.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Xuanwo
Copy link
Member

Xuanwo commented Aug 30, 2024

Also invite @Aitozi for a review.


/// Returns the warehouse root path containing all database directories in this catalog.
fn warehouse(&self) -> &str;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do APIs like lockFactory need to be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SteNicholas SteNicholas changed the title feat: add catalog API feat(catalog): add catalog API Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the Catalog API
6 participants