-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-33278][SQL] Improve the performance for FIRST_VALUE #30178
Closed
Closed
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
4a6f903
Reuse completeNextStageWithFetchFailure
beliefer 96456e2
Merge remote-tracking branch 'upstream/master'
beliefer 4314005
Merge remote-tracking branch 'upstream/master'
beliefer d6af4a7
Merge remote-tracking branch 'upstream/master'
beliefer f69094f
Merge remote-tracking branch 'upstream/master'
beliefer b86a42d
Merge remote-tracking branch 'upstream/master'
beliefer 2ac5159
Merge branch 'master' of github.com:beliefer/spark
beliefer 9021d6c
Merge remote-tracking branch 'upstream/master'
beliefer 74a2ef4
Merge branch 'master' of github.com:beliefer/spark
beliefer 9828158
Merge remote-tracking branch 'upstream/master'
beliefer 9cd1aaf
Merge remote-tracking branch 'upstream/master'
beliefer abfcbb9
Merge remote-tracking branch 'upstream/master'
beliefer 07c6c81
Merge remote-tracking branch 'upstream/master'
beliefer 580130b
Merge remote-tracking branch 'upstream/master'
beliefer 3712808
Merge branch 'master' of github.com:beliefer/spark
beliefer 6107413
Merge remote-tracking branch 'upstream/master'
beliefer 4b799b4
Merge remote-tracking branch 'upstream/master'
beliefer ee0ecbf
Merge remote-tracking branch 'upstream/master'
beliefer 596bc61
Merge remote-tracking branch 'upstream/master'
beliefer 0164e2f
Merge remote-tracking branch 'upstream/master'
beliefer 90b79fc
Merge remote-tracking branch 'upstream/master'
beliefer 2cef3a9
Merge remote-tracking branch 'upstream/master'
beliefer c26b64f
Merge remote-tracking branch 'upstream/master'
beliefer 2e02cd2
Merge remote-tracking branch 'upstream/master'
beliefer a6d0741
Merge remote-tracking branch 'upstream/master'
beliefer 181186c
Improve the performance for first_value
beliefer 82e5b2c
Merge remote-tracking branch 'upstream/master'
beliefer 70bbf5d
Merge remote-tracking branch 'upstream/master'
beliefer 66dfcb2
Merge branch 'master' into SPARK-33278
beliefer 879d6c7
Reactor code
beliefer 57c7ef1
Fix compatible
beliefer 7b99d27
Add test case.
beliefer 0c953ff
Update golden files.
beliefer 2f3fbda
Update golden files
beliefer 7c4dcdc
Optimize code
beliefer 3170320
Delete OptimizeWindowFunctionsSuite.scala
beliefer 1b4533d
Optimize code
beliefer e296eb6
Merge branch 'SPARK-33278' of github.com:beliefer/spark into SPARK-33278
beliefer f851a4c
Add test case.
beliefer fd7e02e
Revert some code.
beliefer 72ceacc
Optimize code
beliefer 68d3388
Optimize code
beliefer 3a7f4e7
Optimize code
beliefer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
76 changes: 76 additions & 0 deletions
76
...src/test/scala/org/apache/spark/sql/catalyst/optimizer/OptimizeWindowFunctionsSuite.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalyst.optimizer | ||
|
||
import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
import org.apache.spark.sql.catalyst.dsl.plans._ | ||
import org.apache.spark.sql.catalyst.expressions._ | ||
import org.apache.spark.sql.catalyst.expressions.aggregate.First | ||
import org.apache.spark.sql.catalyst.plans.PlanTest | ||
import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan} | ||
import org.apache.spark.sql.catalyst.rules.RuleExecutor | ||
|
||
class OptimizeWindowFunctionsSuite extends PlanTest { | ||
object Optimize extends RuleExecutor[LogicalPlan] { | ||
val batches = Batch("OptimizeWindowFunctions", FixedPoint(10), | ||
OptimizeWindowFunctions) :: Nil | ||
} | ||
|
||
val testRelation = LocalRelation('a.double, 'b.double, 'c.string) | ||
val a = testRelation.output(0) | ||
val b = testRelation.output(1) | ||
val c = testRelation.output(2) | ||
|
||
test("replace first(col) by nth_value(col, 1)") { | ||
val inputPlan = testRelation.select( | ||
WindowExpression( | ||
First(a, false).toAggregateExpression(), | ||
WindowSpecDefinition(b :: Nil, c.asc :: Nil, | ||
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow)))) | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val correctAnswer = testRelation.select( | ||
WindowExpression( | ||
NthValue(a, Literal(1), false), | ||
WindowSpecDefinition(b :: Nil, c.asc :: Nil, | ||
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow)))) | ||
|
||
val optimized = Optimize.execute(inputPlan) | ||
assert(optimized == correctAnswer) | ||
} | ||
|
||
test("can't replace first(col) by nth_value(col, 1) if the window frame type is row") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
val inputPlan = testRelation.select( | ||
WindowExpression( | ||
First(a, false).toAggregateExpression(), | ||
WindowSpecDefinition(b :: Nil, c.asc :: Nil, | ||
SpecifiedWindowFrame(RangeFrame, UnboundedPreceding, CurrentRow)))) | ||
|
||
val optimized = Optimize.execute(inputPlan) | ||
assert(optimized == inputPlan) | ||
} | ||
|
||
test("can't replace first(col) by nth_value(col, 1) if the window frame isn't ordered") { | ||
val inputPlan = testRelation.select( | ||
WindowExpression( | ||
First(a, false).toAggregateExpression(), | ||
WindowSpecDefinition(b :: Nil, Nil, | ||
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow)))) | ||
|
||
val optimized = Optimize.execute(inputPlan) | ||
assert(optimized == inputPlan) | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
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.
shall we also check if the lower bound is
UnboundedPreceding
? otherwise we can't use the offset optimization for nth_value andfirst
is probably faster thannth_value(1)
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.
OK. I created the #30419 to make this check.