-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-30475][SQL] File source V2: Push data filters for file listing #27157
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 8 commits
eeca939
1a65933
67d501a
d056350
689199b
8f63db1
0915b54
8ab97db
3fe4dc4
b1619b8
d181e38
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 |
|---|---|---|
|
|
@@ -28,20 +28,25 @@ import org.apache.spark.sql.types.StructType | |
|
|
||
| private[sql] object PruneFileSourcePartitions extends Rule[LogicalPlan] { | ||
|
|
||
| private def getPartitionKeyFilters( | ||
| private def getPartitionKeyFiltersAndDataFilters( | ||
| sparkSession: SparkSession, | ||
| relation: LeafNode, | ||
| partitionSchema: StructType, | ||
| filters: Seq[Expression], | ||
| output: Seq[AttributeReference]): ExpressionSet = { | ||
| output: Seq[AttributeReference]): (ExpressionSet, Seq[Expression]) = { | ||
| val normalizedFilters = DataSourceStrategy.normalizeExprs( | ||
| filters.filter(f => f.deterministic && !SubqueryExpression.hasSubquery(f)), output) | ||
| val partitionColumns = | ||
| relation.resolve(partitionSchema, sparkSession.sessionState.analyzer.resolver) | ||
| val partitionSet = AttributeSet(partitionColumns) | ||
| ExpressionSet(normalizedFilters.filter { f => | ||
| val partitionKeyFilters = ExpressionSet(normalizedFilters.filter { f => | ||
guykhazma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| f.references.subsetOf(partitionSet) | ||
| }) | ||
|
|
||
| val dataFilters = | ||
| normalizedFilters.filter(_.references.intersect(partitionSet).isEmpty) | ||
|
|
||
| (partitionKeyFilters, dataFilters) | ||
| } | ||
|
|
||
| private def rebuildPhysicalOperation( | ||
|
|
@@ -72,7 +77,7 @@ private[sql] object PruneFileSourcePartitions extends Rule[LogicalPlan] { | |
| _, | ||
| _)) | ||
| if filters.nonEmpty && fsRelation.partitionSchemaOption.isDefined => | ||
| val partitionKeyFilters = getPartitionKeyFilters( | ||
| val (partitionKeyFilters, _) = getPartitionKeyFiltersAndDataFilters( | ||
| fsRelation.sparkSession, logicalRelation, partitionSchema, filters, logicalRelation.output) | ||
| if (partitionKeyFilters.nonEmpty) { | ||
| val prunedFileIndex = catalogFileIndex.filterPartitions(partitionKeyFilters.toSeq) | ||
|
|
@@ -92,11 +97,13 @@ private[sql] object PruneFileSourcePartitions extends Rule[LogicalPlan] { | |
| case op @ PhysicalOperation(projects, filters, | ||
| v2Relation @ DataSourceV2ScanRelation(_, scan: FileScan, output)) | ||
| if filters.nonEmpty && scan.readDataSchema.nonEmpty => | ||
| val partitionKeyFilters = getPartitionKeyFilters(scan.sparkSession, | ||
| v2Relation, scan.readPartitionSchema, filters, output) | ||
| if (partitionKeyFilters.nonEmpty) { | ||
| val (partitionKeyFilters, dataFilters) = | ||
| getPartitionKeyFiltersAndDataFilters(scan.sparkSession, v2Relation, | ||
| scan.readPartitionSchema, filters, output) | ||
| // The dataFilters are pushed down only once | ||
| if (partitionKeyFilters.nonEmpty || (dataFilters.nonEmpty && scan.dataFilters.isEmpty)) { | ||
|
Contributor
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 reason for the condition Is that unlike the |
||
| val prunedV2Relation = | ||
| v2Relation.copy(scan = scan.withPartitionFilters(partitionKeyFilters.toSeq)) | ||
| v2Relation.copy(scan = scan.withFilters(partitionKeyFilters.toSeq, dataFilters)) | ||
| // The pushed down partition filters don't need to be reevaluated. | ||
| val afterScanFilters = | ||
| ExpressionSet(filters) -- partitionKeyFilters.filter(_.references.nonEmpty) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.