Uh oh!
There was an error while loading. Please reload this page.
[SPARK-17892] [SQL] [2.0] Do Not Optimize Query in CTAS More Than Once #15048 - #15502
Closed
gatorsmile wants to merge 4 commits into
Closed
[SPARK-17892] [SQL] [2.0] Do Not Optimize Query in CTAS More Than Once #15048#15502gatorsmile wants to merge 4 commits into
gatorsmile wants to merge 4 commits into
Conversation
SparkQA
commented
Oct 15, 2016
Test build #67018 has finished for PR 15502 at commit
|
gatorsmile
commented
Oct 17, 2016
MemberAuthor
cc @yhuai@hvanhovell@cloud-fan I guess this needs to be merged to 2.0.2 ASAP? |
| child: LogicalPlan, | ||
| overwrite: Boolean, | ||
| ifNotExists: Boolean) | ||
| extends LogicalPlan with Command { |
Contributor
There was a problem hiding this comment.
why it's not a command anymore?
MemberAuthor
There was a problem hiding this comment.
In the Command, this PR requires the child must be empty . Should we convert InsertIntoHiveTable to a non-child Command?
Just FYI, in Spark 2.1, InsertIntoTable is still a LogicalPlan instead of a Command.
Contributor
There was a problem hiding this comment.
ah i see, this command is gone in 2.1
asfgit pushed a commit
that referenced
this pull request
Oct 17, 2016
…15048 ### What changes were proposed in this pull request? This PR is to backport #15048 and #15459. However, in 2.0, we do not have a unified logical node `CreateTable` and the analyzer rule `PreWriteCheck` is also different. To minimize the code changes, this PR adds a new rule `AnalyzeCreateTableAsSelect`. Please treat it as a new PR to review. Thanks! As explained in #14797: >Some analyzer rules have assumptions on logical plans, optimizer may break these assumption, we should not pass an optimized query plan into QueryExecution (will be analyzed again), otherwise we may some weird bugs. For example, we have a rule for decimal calculation to promote the precision before binary operations, use PromotePrecision as placeholder to indicate that this rule should not apply twice. But a Optimizer rule will remove this placeholder, that break the assumption, then the rule applied twice, cause wrong result. We should not optimize the query in CTAS more than once. For example, ```Scala spark.range(99, 101).createOrReplaceTempView("tab1") val sqlStmt = "SELECT id, cast(id as long) * cast('1.0' as decimal(38, 18)) as num FROM tab1" sql(s"CREATE TABLE tab2 USING PARQUET AS $sqlStmt") checkAnswer(spark.table("tab2"), sql(sqlStmt)) ``` Before this PR, the results do not match ``` == Results == !== Correct Answer - 2 == == Spark Answer - 2 == ![100,100.000000000000000000] [100,null] [99,99.000000000000000000] [99,99.000000000000000000] ``` After this PR, the results match. ``` +---+----------------------+ |id |num | +---+----------------------+ |99 |99.000000000000000000 | |100|100.000000000000000000| +---+----------------------+ ``` In this PR, we do not treat the `query` in CTAS as a child. Thus, the `query` will not be optimized when optimizing CTAS statement. However, we still need to analyze it for normalizing and verifying the CTAS in the Analyzer. Thus, we do it in the analyzer rule `PreprocessDDL`, because so far only this rule needs the analyzed plan of the `query`. ### How was this patch tested? Author: gatorsmile <gatorsmile@gmail.com> Closes#15502 from gatorsmile/ctasOptimize2.0.
cloud-fan
commented
Oct 17, 2016
Contributor
LGTM, merging to 2.0! |
gatorsmile
commented
Oct 17, 2016
MemberAuthor
Thanks! Close it now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR is to backport #15048 and #15459.
However, in 2.0, we do not have a unified logical node
CreateTableand the analyzer rulePreWriteCheckis also different. To minimize the code changes, this PR adds a new ruleAnalyzeCreateTableAsSelect. Please treat it as a new PR to review. Thanks!As explained in #14797:
We should not optimize the query in CTAS more than once. For example,
Before this PR, the results do not match
After this PR, the results match.
In this PR, we do not treat the
queryin CTAS as a child. Thus, thequerywill not be optimized when optimizing CTAS statement. However, we still need to analyze it for normalizing and verifying the CTAS in the Analyzer. Thus, we do it in the analyzer rulePreprocessDDL, because so far only this rule needs the analyzed plan of thequery.How was this patch tested?