-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25699][SQL] Partially push down conjunctive predicated in ORC #22684
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -79,6 +79,23 @@ private[orc] object OrcFilters extends Logging { | |
| dataTypeMap: Map[String, DataType], | ||
| expression: Filter, | ||
| builder: Builder): Option[Builder] = { | ||
| createBuilder(dataTypeMap, expression, builder, canPartialPushDownConjuncts = true) | ||
| } | ||
|
|
||
| /** | ||
| * @param dataTypeMap a map from the attribute name to its data type. | ||
| * @param expression the input filter predicates. | ||
| * @param builder the input SearchArgument.Builder. | ||
| * @param canPartialPushDownConjuncts whether a subset of conjuncts of predicates can be pushed | ||
| * down safely. Pushing ONLY one side of AND down is safe to | ||
| * do at the top level or none of its ancestors is NOT and OR. | ||
| * @return the builder so far. | ||
| */ | ||
| private def createBuilder( | ||
| dataTypeMap: Map[String, DataType], | ||
| expression: Filter, | ||
| builder: Builder, | ||
| canPartialPushDownConjuncts: Boolean): Option[Builder] = { | ||
| def isSearchableType(dataType: DataType): Boolean = dataType match { | ||
| // Only the values in the Spark types below can be recognized by | ||
| // the `SearchArgumentImpl.BuilderImpl.boxLiteral()` method. | ||
|
|
@@ -90,32 +107,52 @@ private[orc] object OrcFilters extends Logging { | |
|
|
||
| expression match { | ||
| case And(left, right) => | ||
| // At here, it is not safe to just convert one side if we do not understand the | ||
| // other side. Here is an example used to explain the reason. | ||
| // At here, it is not safe to just convert one side and remove the other side | ||
| // if we do not understand what the parent filters are. | ||
| // | ||
| // Here is an example used to explain the reason. | ||
| // Let's say we have NOT(a = 2 AND b in ('1')) and we do not understand how to | ||
| // convert b in ('1'). If we only convert a = 2, we will end up with a filter | ||
| // NOT(a = 2), which will generate wrong results. | ||
| // Pushing one side of AND down is only safe to do at the top level. | ||
| // You can see ParquetRelation's initializeLocalJobFunc method as an example. | ||
| for { | ||
| _ <- buildSearchArgument(dataTypeMap, left, newBuilder) | ||
| _ <- buildSearchArgument(dataTypeMap, right, newBuilder) | ||
| lhs <- buildSearchArgument(dataTypeMap, left, builder.startAnd()) | ||
| rhs <- buildSearchArgument(dataTypeMap, right, lhs) | ||
| } yield rhs.end() | ||
| // | ||
| // Pushing one side of AND down is only safe to do at the top level or in the child | ||
| // AND before hitting NOT or OR conditions, and in this case, the unsupported predicate | ||
| // can be safely removed. | ||
| val leftBuilderOption = | ||
| createBuilder(dataTypeMap, left, newBuilder, canPartialPushDownConjuncts) | ||
| val rightBuilderOption = | ||
| createBuilder(dataTypeMap, right, newBuilder, canPartialPushDownConjuncts) | ||
| (leftBuilderOption, rightBuilderOption) match { | ||
|
Member
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. ditto |
||
| case (Some(_), Some(_)) => | ||
| for { | ||
| lhs <- createBuilder(dataTypeMap, left, | ||
| builder.startAnd(), canPartialPushDownConjuncts) | ||
| rhs <- createBuilder(dataTypeMap, right, lhs, canPartialPushDownConjuncts) | ||
| } yield rhs.end() | ||
|
|
||
| case (Some(_), None) if canPartialPushDownConjuncts => | ||
| createBuilder(dataTypeMap, left, builder, canPartialPushDownConjuncts) | ||
|
|
||
| case (None, Some(_)) if canPartialPushDownConjuncts => | ||
| createBuilder(dataTypeMap, right, builder, canPartialPushDownConjuncts) | ||
|
|
||
| case _ => None | ||
| } | ||
|
|
||
| case Or(left, right) => | ||
| for { | ||
| _ <- buildSearchArgument(dataTypeMap, left, newBuilder) | ||
| _ <- buildSearchArgument(dataTypeMap, right, newBuilder) | ||
| lhs <- buildSearchArgument(dataTypeMap, left, builder.startOr()) | ||
| rhs <- buildSearchArgument(dataTypeMap, right, lhs) | ||
| _ <- createBuilder(dataTypeMap, left, newBuilder, canPartialPushDownConjuncts = false) | ||
| _ <- createBuilder(dataTypeMap, right, newBuilder, canPartialPushDownConjuncts = false) | ||
| lhs <- createBuilder(dataTypeMap, left, | ||
| builder.startOr(), canPartialPushDownConjuncts = false) | ||
| rhs <- createBuilder(dataTypeMap, right, lhs, canPartialPushDownConjuncts = false) | ||
| } yield rhs.end() | ||
|
|
||
| case Not(child) => | ||
| for { | ||
| _ <- buildSearchArgument(dataTypeMap, child, newBuilder) | ||
| negate <- buildSearchArgument(dataTypeMap, child, builder.startNot()) | ||
| _ <- createBuilder(dataTypeMap, child, newBuilder, canPartialPushDownConjuncts = false) | ||
| negate <- createBuilder(dataTypeMap, | ||
| child, builder.startNot(), canPartialPushDownConjuncts = false) | ||
| } yield negate.end() | ||
|
|
||
| // NOTE: For all case branches dealing with leaf predicates below, the additional `startAnd()` | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Nit, can you make the format the same as
leftBuilderOption? Also, add another empty line before(leftBuilderOption, rightBuilderOption). Thanks.