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

fix: analyze/optimize plan in CREATE TABLE AS SELECT #6610

Merged
merged 1 commit into from
Jun 9, 2023

Conversation

jackwener
Copy link
Member

Which issue does this PR close?

Closes #.

Rationale for this change

related #5821.

we need analyze plan to make plan valid.

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@jackwener jackwener requested a review from alamb June 9, 2023 10:39
@github-actions github-actions bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) labels Jun 9, 2023
@jackwener jackwener marked this pull request as draft June 9, 2023 10:41
@jackwener jackwener marked this pull request as ready for review June 9, 2023 10:44
@jackwener
Copy link
Member Author

If plan didn't be analyzed, it will fail to execute in

                let schema = Arc::new(input.schema().as_ref().into());
                let physical = DataFrame::new(self.state(), input);
                let batches: Vec<_> = physical.collect_partitioned().await?;
                let table = Arc::new(MemTable::try_new(schema, batches)?);

@jackwener jackwener changed the title feat: analyze/optimize plan in CREATE TABLE AS SELECT fix: analyze/optimize plan in CREATE TABLE AS SELECT Jun 9, 2023
@@ -495,6 +495,7 @@ impl SessionContext {
}

let input = Arc::try_unwrap(input).unwrap_or_else(|e| e.as_ref().clone());
let input = self.state().optimize(&input)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

That is important 👍

I wonder if there is any test we can add to cover this case and prevent a regression?

Copy link
Member Author

@jackwener jackwener Jun 9, 2023

Choose a reason for hiding this comment

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

I have tried to add test to cover this case, but failed.
Because when I try to add test explain to show plan tree, but if sql is explain, df don't execute these code.
So I don't know how to cover it.

@alamb
Copy link
Contributor

alamb commented Jun 9, 2023

Thanks @jackwener

@alamb alamb merged commit 95c4681 into apache:main Jun 9, 2023
@jackwener jackwener deleted the analyzer branch June 9, 2023 13:39
jayzhan211 pushed a commit to jayzhan211/datafusion that referenced this pull request Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants