-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-32295][SQL] Add not null and size > 0 filters before inner explode/inline to benefit from predicate pushdown #29092
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8cfa6af
InferFiltersFromGenerate
tanelk ffe43d7
Don't infer for foldable
tanelk 3fc4b12
style
tanelk c3f9063
address comments
tanelk 9797856
Merge branch 'master' into SPARK-32295
tanelk 6cc7b15
address comments
tanelk a25bd6f
address comments
tanelk 3bbff2c
Restore foldable check
tanelk d4089ca
Add explanaiton
tanelk e3a0205
Clean up operatorOptimizationRuleSet
tanelk b7a7c49
Better comment
tanelk 857c007
Remove redundant code from UT
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 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
63 changes: 63 additions & 0 deletions
63
...rc/test/scala/org/apache/spark/sql/catalyst/optimizer/InferFiltersFromGenerateSuite.scala
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * 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.plans._ | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.rules.RuleExecutor | ||
| import org.apache.spark.sql.types.IntegerType | ||
|
|
||
| class InferFiltersFromGenerateSuite extends PlanTest { | ||
| object Optimize extends RuleExecutor[LogicalPlan] { | ||
| val batches = Batch("Infer Filters", Once, InferFiltersFromGenerate) :: Nil | ||
| } | ||
|
|
||
| val testRelation = LocalRelation('a.array(IntegerType)) | ||
|
|
||
| Seq( | ||
| (e: Expression) => Explode(e), | ||
| (e: Expression) => PosExplode(e) | ||
| ).foreach(f => { | ||
| val explode = f('a) | ||
| test("Infer filters from " + explode) { | ||
| val originalQuery = testRelation.generate(explode).analyze | ||
| val correctAnswer = testRelation | ||
| .where(IsNotNull('a) && Size('a) > 0) | ||
|
tanelk marked this conversation as resolved.
|
||
| .generate(explode) | ||
| .analyze | ||
| val optimized = Optimize.execute(originalQuery) | ||
| comparePlans(optimized, correctAnswer) | ||
| } | ||
|
|
||
| test("Don't infer filters from outer " + explode) { | ||
| val originalQuery = testRelation.generate(explode, outer = true).analyze | ||
| val optimized = Optimize.execute(originalQuery) | ||
| comparePlans(optimized, originalQuery) | ||
| } | ||
|
|
||
| val foldableExplode = f(CreateArray(Seq(Literal(0), Literal(1)))) | ||
| test("Don't infer filters from " + foldableExplode) { | ||
| val originalQuery = testRelation.generate(foldableExplode).analyze | ||
| val optimized = Optimize.execute(originalQuery) | ||
| comparePlans(optimized, originalQuery) | ||
| } | ||
| }) | ||
| } | ||
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.
Why did you put this rule only in this batch? https://github.com/apache/spark/pull/29092/files#diff-a636a87d8843eeccca90140be91d4fafR82
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.
I'm sorry, I don't get the question.
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.
Ah, ok. Looks okay as it is. Since
operatorOptimizationRuleSethasInferFiltersFromConstraints, I thought we'd better to putInferFiltersFromConstraints/InferFiltersFromGeneratethere together.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.
Actually the
InferFiltersFromConstraintsis allways filtered out from theoperatorOptimizationRuleSet:spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
Lines 120 to 123 in 5ce321d
I think it is very misleading , perhaps we could remove it from there and avoid further confusion?
It was asked in the original PR, put looks like it was forgotten:
https://github.com/apache/spark/pull/19149/files#r157777935
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.
Yea, but I also don't know why. cc: @cloud-fan
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.
I don't quite remember, maybe we can remove it.
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.
I went ahead and removed it from the
operatorOptimizationRuleSet. All the tests are still passing as was expected.