-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-39784][SQL] Put Literal values on the right side of the data source filter after translating Catalyst Expression to data source filter #37197
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
Changes from 1 commit
f742b20
fa4d57a
a708ad6
47e30c4
1e94c53
324dd87
99b6c45
a4e8170
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ import org.apache.spark.sql.catalyst.plans.logical._ | |
| import org.apache.spark.sql.catalyst.util.{toPrettySQL, ResolveDefaultColumns, V2ExpressionBuilder} | ||
| import org.apache.spark.sql.connector.catalog.{Identifier, StagingTableCatalog, SupportsDelete, SupportsNamespaces, SupportsPartitionManagement, SupportsWrite, Table, TableCapability, TableCatalog, TruncatableTable} | ||
| import org.apache.spark.sql.connector.catalog.index.SupportsIndex | ||
| import org.apache.spark.sql.connector.expressions.FieldReference | ||
| import org.apache.spark.sql.connector.expressions.{FieldReference, LiteralValue} | ||
| import org.apache.spark.sql.connector.expressions.filter.{And => V2And, Not => V2Not, Or => V2Or, Predicate} | ||
| import org.apache.spark.sql.connector.read.LocalScan | ||
| import org.apache.spark.sql.connector.read.streaming.{ContinuousStream, MicroBatchStream} | ||
|
|
@@ -502,11 +502,31 @@ private[sql] object DataSourceV2Strategy { | |
|
|
||
| private def translateLeafNodeFilterV2(predicate: Expression): Option[Predicate] = { | ||
| predicate match { | ||
| case PushablePredicate(expr) => Some(expr) | ||
| case PushablePredicate(expr) => | ||
| if (expr.children().length == 2) { | ||
| expr.children()(0) match { | ||
| case LiteralValue(_, _) => | ||
| Some(new Predicate(flipComparisonFilterName(expr.name()), | ||
|
||
| Array(expr.children()(1), expr.children()(0)))) | ||
| case _ => Some(expr) | ||
| } | ||
| } else { | ||
| Some(expr) | ||
| } | ||
| case _ => None | ||
| } | ||
| } | ||
|
|
||
| private def flipComparisonFilterName(filterName: String): String = { | ||
| filterName match { | ||
| case ">" => "<" | ||
| case "<" => ">" | ||
| case ">=" => "<=" | ||
| case "<=" => ">=" | ||
| case _ => filterName | ||
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Tries to translate a Catalyst [[Expression]] into data source [[Filter]]. | ||
| * | ||
|
|
||
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.
could this be written into something like
expr.children() match { case Literal :: xs =>