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

Make SessionContext::enable_url_table consume self #12573

Merged
merged 1 commit into from
Sep 22, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Sep 21, 2024

Which issue does this PR close?

Fixes #12551

Rationale for this change

As described on #12551 the current non consuming API was confusing and caused silently ignored bugs

What changes are included in this PR?

  1. Make SessionContext::enable_url_table consume self
  2. Fix bug in example use
  3. Add an "into_builder" API to SessionContext to make it easier to work with the builder pattern
  4. Update documentation

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the core Core DataFusion crate label Sep 21, 2024
@alamb alamb marked this pull request as ready for review September 21, 2024 12:06
@@ -64,7 +64,7 @@ async fn main() -> Result<()> {
df.show().await?;

// dynamic query by the file path
ctx.enable_url_table();
let ctx = ctx.enable_url_table();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this example actually has the exact same bug I hit in #12551 -- namely the returned ctx has the table enabled, not the current one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for reminding this bug!

pub fn enable_url_table(&self) -> Self {
let state_ref = self.state();
pub fn enable_url_table(self) -> Self {
let current_catalog_list = Arc::clone(self.state.read().catalog_list());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this avoids copying the entire state just to copy the catalog list

Arc::clone(&factory) as Arc<dyn UrlTableFactory>,
));
let new_state = SessionStateBuilder::new_from_existing(self.state())
let ctx: SessionContext = self
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is likely just my obsession with trying to have clear Builder style APIs, but I think it reads more clearly here to to back and forth between the types

Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

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

Thanks @alamb. Overall looks good to me 👍

@@ -64,7 +64,7 @@ async fn main() -> Result<()> {
df.show().await?;

// dynamic query by the file path
ctx.enable_url_table();
let ctx = ctx.enable_url_table();
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for reminding this bug!

@alamb alamb added the api change Changes the API exposed to users of the crate label Sep 22, 2024
@alamb alamb merged commit f6a0ed0 into apache:main Sep 22, 2024
24 checks passed
@alamb
Copy link
Contributor Author

alamb commented Sep 22, 2024

Thanks @andygrove and @goldmedal

bgjackma pushed a commit to bgjackma/datafusion that referenced this pull request Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make SessionContext::enable_url_table consume self
3 participants