-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
refactor: Change SchemaProvider::table
to return Result<Option<..>
rather than Option<..>
#9307
Conversation
fce8dab
to
6cc8fc2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thanks @crepererum
please address the minor.
Basically I'm thinking to create a type alias for Result<Option> as such nested generics are hard to read
6cc8fc2
to
ef3b097
Compare
I agree on the readability aspects, but I also see the following counter points:
|
That is also true. Maybe if we can come up with short, concise and meaningful type name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @crepererum since it is an api change I'll wait for second reviewer.
@alamb @Jefffrey may help with the second review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR @crepererum and @comphead for the review.
I think returning a Result<Option<..>>
is somewhat common in the DataFusion APIs so this PR makes the APIs more consistent as well as fixing the issues identified in the PR description
For example in SchemaProvider
register_table
and deregister_table
both return Result<Option<..>>
:
fn register_table(
&self,
name: String,
table: Arc<dyn TableProvider>,
) -> Result<Option<Arc<dyn TableProvider>>> {
...
fn deregister_table(&self, name: &str) -> Result<Option<Arc<dyn TableProvider>>> {
...
I agree that Result<Option<Arc<dyn TableProvider>>>
is somewhat 🤮 to read, but as @crepererum and @comphead have pointed out there isn't an obviously better alternative
SchemaProvider::table
can failSchemaProvider::table
to return Result<Option<..>
rather than Option<..>
ef3b097
to
2cda63f
Compare
2cda63f
to
88fa976
Compare
Which issue does this PR close?
Closes #9305.
Rationale for this change
SchemaProvider::table
is async and clearly allows IO:https://github.com/apache/arrow-datafusion/blob/6fad5ed7a37c50b9c200f214c3e13b0e1f0cecbc/datafusion/core/src/catalog/schema.rs#L114-L116
However this method cannot fail. Casting errors to
None
is semantically wrong.What changes are included in this PR?
Change return type from
Option<Arc<dyn TableProvider>>
toResult<Option<Arc<dyn TableProvider>>, DataFusionError>
.Are these changes tested?
It compiles.
Are there any user-facing changes?
Breaking: Interface change.