-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-36351][SQL] Refactor filter push down in file source v2 #33650
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 18 commits
3eec42e
c3e07ac
f95b4a0
feea946
e9d598f
a6ae1c5
ff8a9d4
8f06107
c541315
eaebb4c
f61caa0
e04428b
ab6187c
5b41c61
3b9e2c6
73eea33
095a7b4
68ace26
f3b4d22
4700c08
3085bdf
da9fe2f
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * 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.internal.connector | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.Expression | ||
|
|
||
| /** | ||
| * A mix-in interface for {@link FileScanBuilder}. This can be used to push down partitionFilters | ||
| * and dataFilters to FileIndex in the format of catalyst Expression. | ||
| */ | ||
| trait SupportsPushDownCatalystFilters { | ||
| /** | ||
| * Pushes down partitionFilters and dataFilters to FileIndex in the format of catalyst | ||
| * Expression. These catalyst Expression filters are used for partition pruning. The dataFilters | ||
| * are also translated into data source filters and used for selecting records. | ||
| */ | ||
| def pushCatalystFilters(partitionFilters: Seq[Expression], dataFilters: Seq[Expression]): Unit | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,15 +19,14 @@ package org.apache.spark.sql.execution.datasources.v2 | |
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression, NamedExpression, PredicateHelper, SchemaPruning} | ||
| import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression, ExpressionSet, NamedExpression, PredicateHelper, SchemaPruning} | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression | ||
| import org.apache.spark.sql.catalyst.util.CharVarcharUtils | ||
| import org.apache.spark.sql.connector.expressions.FieldReference | ||
| import org.apache.spark.sql.connector.expressions.aggregate.Aggregation | ||
| import org.apache.spark.sql.connector.read.{Scan, ScanBuilder, SupportsPushDownAggregates, SupportsPushDownFilters, SupportsPushDownRequiredColumns} | ||
| import org.apache.spark.sql.connector.read.{Scan, ScanBuilder, SupportsPushDownFilters, SupportsPushDownRequiredColumns} | ||
| import org.apache.spark.sql.execution.datasources.DataSourceStrategy | ||
| import org.apache.spark.sql.execution.datasources.PushableColumnWithoutNestedColumn | ||
| import org.apache.spark.sql.execution.datasources.{DataSourceStrategy, DataSourceUtils, PushableColumnWithoutNestedColumn} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.sources | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
@@ -39,9 +38,9 @@ object PushDownUtils extends PredicateHelper { | |
| * @return pushed filter and post-scan filters. | ||
| */ | ||
| def pushFilters( | ||
| scanBuilder: ScanBuilder, | ||
| scanBuilderHolder: ScanBuilderHolder, | ||
cloud-fan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| filters: Seq[Expression]): (Seq[sources.Filter], Seq[Expression]) = { | ||
| scanBuilder match { | ||
| scanBuilderHolder.builder match { | ||
| case r: SupportsPushDownFilters => | ||
| // A map from translated data source leaf node filters to original catalyst filter | ||
| // expressions. For a `And`/`Or` predicate, it is possible that the predicate is partially | ||
|
|
@@ -71,6 +70,12 @@ object PushDownUtils extends PredicateHelper { | |
| } | ||
| (r.pushedFilters(), (untranslatableExprs ++ postScanFilters).toSeq) | ||
|
|
||
| case f: FileScanBuilder => | ||
| val (partitionFilters, dataFilters) = | ||
| DataSourceUtils.getPartitionKeyFiltersAndDataFilters( | ||
| f.getSparkSession, scanBuilderHolder.relation, f.readPartitionSchema(), filters) | ||
| f.pushCatalystFilters(ExpressionSet(partitionFilters).toSeq, dataFilters) | ||
| (Nil, dataFilters) | ||
| case _ => (Nil, filters) | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.