-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-34952][SQL] Aggregate (Min/Max/Count) push down for Parquet #32049
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 all commits
8d0256d
3b7a170
a4b054a
d576cf6
a66a87c
e561cc2
d52a72c
60b495d
d954727
a505e7f
d118eaf
9af611f
d277701
743bc8a
346485e
ed7c19d
52b0b98
6df2ae1
d0a61f8
91f013c
4fbe666
a5833ef
a60c9a1
475c0f7
564e6de
1648070
ccdc543
7540b59
2c889c6
5c2b630
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,51 @@ | ||
| /* | ||
| * 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.connector.read; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.Aggregation; | ||
|
|
||
| /** | ||
| * A mix-in interface for {@link ScanBuilder}. Data source can implement this interface to | ||
| * push down aggregates. Depends on the data source implementation, the aggregates may not | ||
| * be able to push down, or partially push down and have a final aggregate at Spark. | ||
| * For example, "SELECT min(_1) FROM t GROUP BY _2" can be pushed down to data source, | ||
| * the partially aggregated result min(_1) grouped by _2 will be returned to Spark, and | ||
| * then have a final aggregation. | ||
| * {{{ | ||
| * Aggregate [_2#10], [min(_2#10) AS min(_1)#16] | ||
| * +- RelationV2[_2#10, min(_1)#18] | ||
| * }}} | ||
| * | ||
| * When pushing down operators, Spark pushes down filters to the data source first, then push down | ||
| * aggregates or apply column pruning. Depends on data source implementation, aggregates may or | ||
| * may not be able to be pushed down with filters. If pushed filters still need to be evaluated | ||
| * after scanning, aggregates can't be pushed down. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Evolving | ||
| public interface SupportsPushDownAggregates extends ScanBuilder { | ||
|
|
||
| /** | ||
| * Pushes down Aggregation to datasource. The order of the datasource scan output columns should | ||
| * be: grouping columns, aggregate columns (in the same order as the aggregate functions in | ||
| * the given Aggregation). | ||
| */ | ||
| boolean pushAggregation(Aggregation aggregation); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * 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.connector.expressions | ||
|
|
||
| import org.apache.spark.sql.types.DataType | ||
|
|
||
| // Aggregate Functions in SQL statement. | ||
| // e.g. SELECT COUNT(EmployeeID), Max(salary), deptID FROM dept GROUP BY deptID | ||
| // aggregateExpressions are (COUNT(EmployeeID), Max(salary)), groupByColumns are (deptID) | ||
| case class Aggregation(aggregateExpressions: Seq[AggregateFunc], | ||
| groupByColumns: Seq[Expression]) | ||
|
|
||
| abstract class AggregateFunc | ||
|
|
||
| case class Min(column: Expression, dataType: DataType) extends AggregateFunc | ||
| case class Max(column: Expression, dataType: DataType) extends AggregateFunc | ||
| case class Sum(column: Expression, dataType: DataType, isDistinct: Boolean) | ||
| extends AggregateFunc | ||
| case class Count(column: Expression, dataType: DataType, isDistinct: Boolean) | ||
| extends AggregateFunc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -772,6 +772,12 @@ object SQLConf { | |
| .checkValue(threshold => threshold >= 0, "The threshold must not be negative.") | ||
| .createWithDefault(10) | ||
|
|
||
| val PARQUET_AGGREGATE_PUSHDOWN_ENABLED = buildConf("spark.sql.parquet.aggregatePushdown") | ||
|
||
| .doc("Enables Parquet aggregate push-down optimization when set to true.") | ||
|
||
| .version("3.2.0") | ||
| .booleanConf | ||
| .createWithDefault(false) | ||
|
|
||
| val PARQUET_WRITE_LEGACY_FORMAT = buildConf("spark.sql.parquet.writeLegacyFormat") | ||
| .doc("If true, data will be written in a way of Spark 1.4 and earlier. For example, decimal " + | ||
| "values will be written in Apache Parquet's fixed-length byte array format, which other " + | ||
|
|
@@ -3423,6 +3429,8 @@ class SQLConf extends Serializable with Logging { | |
| def parquetFilterPushDownInFilterThreshold: Int = | ||
| getConf(PARQUET_FILTER_PUSHDOWN_INFILTERTHRESHOLD) | ||
|
|
||
| def parquetAggregatePushDown: Boolean = getConf(PARQUET_AGGREGATE_PUSHDOWN_ENABLED) | ||
|
|
||
| def orcFilterPushDown: Boolean = getConf(ORC_FILTER_PUSHDOWN_ENABLED) | ||
|
|
||
| def isOrcSchemaMergingEnabled: Boolean = getConf(ORC_SCHEMA_MERGING_ENABLED) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,8 @@ class SparkOptimizer( | |
|
|
||
| override def earlyScanPushDownRules: Seq[Rule[LogicalPlan]] = | ||
| // TODO: move SchemaPruning into catalyst | ||
| SchemaPruning :: V2ScanRelationPushDown :: V2Writes :: PruneFileSourcePartitions :: Nil | ||
| SchemaPruning :: V2ScanRelationPushDown :: V2Writes :: | ||
| PruneFileSourcePartitions :: Nil | ||
|
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. nit: unnecessary change? |
||
|
|
||
| override def defaultBatches: Seq[Batch] = (preOptimizationBatches ++ super.defaultBatches :+ | ||
| Batch("Optimize Metadata Only Query", Once, OptimizeMetadataOnlyQuery(catalog)) :+ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.