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: implement IcebergTableProviderFactory for datafusion #600

Merged
merged 5 commits into from
Nov 1, 2024

Conversation

yukkit
Copy link
Contributor

@yukkit yukkit commented Sep 3, 2024

resolve #586

TODO:

  1. Supplement unit tests and add validation of data
  2. Add examples of how to integrate into DataFusion

Copy link
Collaborator

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

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

Thanks @yukkit for this pr! Generally looks good to me, I've left minor points to improve.

if !table_partition_cols.is_empty() {
return Err(Error::new(
ErrorKind::FeatureUnsupported,
"Partition columns cannot be specified",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of returning different errors for each check, I think a more appropriate message would be like

Currently we only support reading existing icebergs tables in external table command. To create new table, please use catalog provider.

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 roughly understand your intention. First, inform the user that external tables currently only support read operations, but this doesn't mean write operations won't be supported in the future. Secondly, provide a method for creating a new table.

// Field { name: "y", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {"PARQUET:field_id": "2"} },
// Field { name: "z", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {"PARQUET:field_id": "3"} }
let actual_schema = table_provider.schema();
let expected_schema_str = "Field { name: \"x\", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {\"PARQUET:field_id\": \"1\"} }, Field { name: \"y\", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {\"PARQUET:field_id\": \"2\"} }, Field { name: \"z\", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {\"PARQUET:field_id\": \"3\"} }";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pure format string comparison doesn't sound like a good idea to me. It would be better to use schema builder api to create schema and compare them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good


#[derive(Default)]
#[non_exhaustive]
pub struct IcebergTableProviderFactory {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to provide some doc to explain its usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I will add doc for it

Comment on lines +181 to +177
fn complement_namespace_if_necessary(table_name: &TableReference) -> Cow<'_, TableReference> {
match table_name {
TableReference::Bare { table } => {
Cow::Owned(TableReference::partial("default", table.as_ref()))
}
other => Cow::Borrowed(other),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please pay attention to this function, because when DataFusion creates external tables, it only creates bare TableReference, which does not include a schema. However, when constructing TableIdent in Iceberg, the 'schema' is required. Does anyone have a good approach for handling compatibility?

Choose a reason for hiding this comment

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

I ran into an issue with external tables only creating bare TableReference as well - do you know if thats the intended behavior or if its a bug in datafusion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Yeah weve got a ticket created for that now. thanks @yukkit

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does anyone have a good approach for handling compatibility?

I'm not quite familiar with datafusion, but typicall it should be registered with current namespace? For example, a user has executed use ns1 before registering this table, then ideally this table should be register under ns1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liurenjie1024 You’re right. When creating an external table in DataFusion without specifying a schema, it will to being created under the default schema. In this case, the table name passed to TableProviderFactory does not include schema information. However, TableIdent requires a namespace, so I use "default" to populate this value. Anyway, the IcebergTableProvider doesn't actually rely on the specific content of TableIdent, so it has no impact when used as an external table in DataFusion (at least as things stand).

@yukkit
Copy link
Contributor Author

yukkit commented Sep 11, 2024

@liurenjie1024 Please help review the PR again when you get a chance

@yukkit
Copy link
Contributor Author

yukkit commented Sep 27, 2024

remind @liurenjie1024

Copy link
Collaborator

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

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

Thanks @yukkit for this pr, LGTM! Just some minor problems to fix, others are great!

/// An error will be returned if any unsupported feature, such as partition columns,
/// order expressions, constraints, or column defaults, is detected in the table creation command.
#[derive(Default)]
#[non_exhaustive]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I don't quite understand why we need to add this annotation here?

Comment on lines +181 to +177
fn complement_namespace_if_necessary(table_name: &TableReference) -> Cow<'_, TableReference> {
match table_name {
TableReference::Bare { table } => {
Cow::Owned(TableReference::partial("default", table.as_ref()))
}
other => Cow::Borrowed(other),
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does anyone have a good approach for handling compatibility?

I'm not quite familiar with datafusion, but typicall it should be registered with current namespace? For example, a user has executed use ns1 before registering this table, then ideally this table should be register under ns1?

@liurenjie1024
Copy link
Collaborator

remind @liurenjie1024

Sorry for late reply, would you mind to fix comments and resolve conflicts?

@shehabgamin shehabgamin mentioned this pull request Oct 12, 2024
@liurenjie1024
Copy link
Collaborator

Thanks @yukkit for this pr!

@liurenjie1024 liurenjie1024 merged commit b8f088e into apache:main Nov 1, 2024
16 checks passed
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 TableProviderFactory for a IcebergTableFactory
3 participants