-
Notifications
You must be signed in to change notification settings - Fork 3k
Spark-3.0: Fix UnresolvedException for some filters in rewrite_data_files #3794
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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 |
|---|---|---|
|
|
@@ -20,7 +20,10 @@ | |
| package org.apache.spark.sql.execution.datasources | ||
|
|
||
| import org.apache.iceberg.spark.SparkFilters | ||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.SparkSession | ||
| import org.apache.spark.sql.catalyst.expressions.Expression | ||
| import org.apache.spark.sql.catalyst.plans.logical.Filter | ||
|
|
||
| object SparkExpressionConverter { | ||
|
|
||
|
|
@@ -30,4 +33,18 @@ object SparkExpressionConverter { | |
| // But these two conversions already exist and well tested. So, we are going with this approach. | ||
| SparkFilters.convert(DataSourceStrategy.translateFilter(sparkExpression, supportNestedPredicatePushdown = true).get) | ||
| } | ||
|
|
||
| @throws[AnalysisException] | ||
| def collectResolvedSparkExpression(session: SparkSession, tableName: String, where: String): Expression = { | ||
| var expression: Expression = null | ||
| // Add a dummy prefix linking to the table to collect the resolved spark expression from optimized plan. | ||
| val prefix = String.format("SELECT 42 from %s where ", tableName) | ||
| val logicalPlan = session.sessionState.sqlParser.parsePlan(prefix + where) | ||
| val optimizedLogicalPlan = session.sessionState.executePlan(logicalPlan).optimizedPlan | ||
|
Member
Author
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. The only change compared to spark-3.2 PR is this. |
||
| optimizedLogicalPlan.collectFirst { | ||
| case filter: Filter => | ||
| expression = filter.expressions.head | ||
| } | ||
| expression | ||
| } | ||
| } | ||
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: Usually we try to avoid formatting only changes (even if they are the correct formatting), as the larger diff makes it harder for people that maintain forks to cherry-pick commits. If you aren’t changing the line, I’d suggest leaving it as is.
Same comment applies to all formatting only changes within a PR. 😊
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.
Agree. But I got a specific comment to fix indentation for this file in the spark-3.2 PR. Hence adopting it here also.
But I think checkstyle should catch over indented code in PR, so it can be caught and fixed in the respective PR itself. Let me explore why it is not catching