<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Aggregate_pushdown</id>
	<title>Aggregate pushdown - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Aggregate_pushdown"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Aggregate_pushdown&amp;action=history"/>
	<updated>2026-12-06T00:07:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Aggregate_pushdown&amp;diff=119&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Aggregate_pushdown&amp;diff=119&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:32Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Aggregate pushdown&lt;br /&gt;
| also_known_as   = Aggregation pushdown, metadata-only aggregation&lt;br /&gt;
| field           = Query optimization&lt;br /&gt;
| key_parts       = Connector interface for aggregates, file footer or table metadata statistics (row counts, min, max, null counts), fallback to a normal scan&lt;br /&gt;
| implementations = [[Apache Spark]] (Data Source V2), [[Apache Iceberg]], [[Apache Parquet]] and ORC readers in Spark, JDBC sources&lt;br /&gt;
| related         = [[Predicate pushdown]], [[Column pruning]], [[Apache Parquet]], [[Data Source V2]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (SupportsPushDownAggregates.java, AggregatePushDownUtils.scala, ParquetScanBuilder.scala, ParquetScan.scala, SQLConf.scala, docs/sql-data-sources-jdbc.md), Spark JIRA SPARK-34952 and SPARK-36645, parquet.thrift at apache-parquet-format-2.12.0, and the Apache Iceberg 1.12.0 Spark source and configuration docs}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Aggregate pushdown&amp;#039;&amp;#039;&amp;#039; is a query optimization in which an engine hands an aggregate such as &amp;lt;code&amp;gt;COUNT(*)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MIN(col)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;MAX(col)&amp;lt;/code&amp;gt; to the data source, which answers it from metadata or computes it itself, instead of returning every row for the engine to aggregate.&amp;lt;ref name=&amp;quot;spda&amp;quot; /&amp;gt; For file formats like [[Apache Parquet]], the answer can come from statistics in the file footers without reading data pages; for [[Apache Iceberg]], it can come from the per-file statistics in the table metadata. In [[Apache Spark]], aggregate pushdown is part of the Data Source V2 API.&lt;br /&gt;
&lt;br /&gt;
== How does aggregate pushdown work in Apache Spark? ==&lt;br /&gt;
A Data Source V2 connector opts in by implementing &amp;lt;code&amp;gt;SupportsPushDownAggregates&amp;lt;/code&amp;gt; on its &amp;lt;code&amp;gt;ScanBuilder&amp;lt;/code&amp;gt; (since Spark 3.2.0). Spark calls &amp;lt;code&amp;gt;pushAggregation&amp;lt;/code&amp;gt; with the aggregate functions and grouping expressions; the source returns true if it can handle them. A source may complete the aggregation fully or only partially, in which case Spark adds a final aggregate on top of the source&amp;#039;s output.&amp;lt;ref name=&amp;quot;spda&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/SupportsPushDownAggregates.java |title=SupportsPushDownAggregates.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The API was added in SPARK-34952, fixed in 3.2.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-34952 |title=SPARK-34952: DS V2 Aggregate push down |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark pushes filters to the source first and aggregates second. If a pushed filter must still be evaluated after the scan, the aggregate cannot be pushed, because the source&amp;#039;s answer would include rows that the filter later removes.&amp;lt;ref name=&amp;quot;spda&amp;quot; /&amp;gt; For Parquet and ORC footers the rule is stricter: any filter on a data column blocks pushdown, because the statistics describe all rows and not only those that pass the filter.&amp;lt;ref name=&amp;quot;utils&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/AggregatePushDownUtils.scala |title=AggregatePushDownUtils.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do Parquet footers answer COUNT, MIN and MAX? ==&lt;br /&gt;
A Parquet file footer records the number of rows in the file and in each row group, and optional column chunk statistics, including &amp;lt;code&amp;gt;min_value&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;max_value&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;null_count&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;thrift&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/parquet-format/blob/apache-parquet-format-2.12.0/src/main/thrift/parquet.thrift |title=parquet.thrift (apache-parquet-format-2.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; From these values a reader can compute &amp;lt;code&amp;gt;COUNT(*)&amp;lt;/code&amp;gt; as the sum of row counts, &amp;lt;code&amp;gt;COUNT(col)&amp;lt;/code&amp;gt; as row count minus null count, and &amp;lt;code&amp;gt;MIN&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt; as the smallest or largest bound, without decoding any data page.&lt;br /&gt;
&lt;br /&gt;
Spark&amp;#039;s Parquet and ORC aggregate pushdown, added in Spark 3.3.0 (SPARK-36645), works this way.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-36645 |title=SPARK-36645: Aggregate (Min/Max/Count) push down for Parquet |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It is off by default and is enabled with &amp;lt;code&amp;gt;spark.sql.parquet.aggregatePushdown&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.sql.orc.aggregatePushdown&amp;lt;/code&amp;gt; (both default false, since 3.3.0). The setting&amp;#039;s documentation warns that if statistics are missing from any file footer, Spark throws an exception.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
spark.conf.set(&amp;quot;spark.sql.parquet.aggregatePushdown&amp;quot;, &amp;quot;true&amp;quot;)&lt;br /&gt;
spark.read.parquet(&amp;quot;/data/events&amp;quot;).selectExpr(&amp;quot;count(*)&amp;quot;, &amp;quot;max(event_id)&amp;quot;).explain()&lt;br /&gt;
# On the V2 Parquet scan path, the scan metadata lists the pushed aggregates under PushedAggregation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What are the limits of Parquet and ORC aggregate pushdown in Spark? ==&lt;br /&gt;
At Spark 4.3.0, the rules in &amp;lt;code&amp;gt;AggregatePushDownUtils&amp;lt;/code&amp;gt; are:&amp;lt;ref name=&amp;quot;utils&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Functions.&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;MIN&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;COUNT(col)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;COUNT(*)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;COUNT(DISTINCT ...)&amp;lt;/code&amp;gt; and other aggregates are not pushed.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Types for MIN and MAX.&amp;#039;&amp;#039;&amp;#039; Boolean, byte, short, integer, long, float, double, date and time. Timestamps are excluded because the INT96 sort order is undefined; strings, binary and decimals are excluded because they can be stored as Parquet binary values, whose minimum and maximum may be truncated.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;No data filters.&amp;#039;&amp;#039;&amp;#039; Any filter on a data column blocks pushdown. A filter on a partition column is allowed.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Grouping.&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; is pushed only when the grouping columns are exactly the table&amp;#039;s partition columns.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;No partition columns in MIN or MAX&amp;#039;&amp;#039;&amp;#039;, because the footer has no statistics for them.&lt;br /&gt;
&lt;br /&gt;
The pushdown is implemented in the Data Source V2 Parquet and ORC scans.&amp;lt;ref name=&amp;quot;scanbuilder&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/parquet/ParquetScanBuilder.scala |title=ParquetScanBuilder.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In Spark 4.3.0 the built-in &amp;lt;code&amp;gt;parquet&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;orc&amp;lt;/code&amp;gt; sources still use the V1 code path by default, because they are in the internal setting &amp;lt;code&amp;gt;spark.sql.sources.useV1SourceList&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;avro,csv,json,kafka,orc,parquet,text&amp;lt;/code&amp;gt;), so the pushdown applies only when Spark reads these formats through the V2 path.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Aggregate pushdown in Apache Iceberg ==&lt;br /&gt;
[[Apache Iceberg]]&amp;#039;s Spark connector answers aggregates from the column statistics stored in its manifest files. The feature is controlled by &amp;lt;code&amp;gt;spark.sql.iceberg.aggregate-push-down.enabled&amp;lt;/code&amp;gt; (default true), and covers &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MIN&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;COUNT&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;icebergconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/docs/docs/spark-configuration.md |title=Spark Configuration (Iceberg 1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Iceberg 1.12.0, the Spark scan builder skips aggregate pushdown when:&amp;lt;ref name=&amp;quot;icebergsb&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkScanBuilder.java |title=SparkScanBuilder.java (apache-iceberg-1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* the query has a &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt;;&lt;br /&gt;
* any data file in the scan has row-level delete files, since deleted rows would be counted;&lt;br /&gt;
* the column&amp;#039;s metrics mode is &amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt;, or is &amp;lt;code&amp;gt;counts&amp;lt;/code&amp;gt; and the query asks for &amp;lt;code&amp;gt;MIN&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt;;&lt;br /&gt;
* the query asks for &amp;lt;code&amp;gt;MIN&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt; of a string or binary column, because stored bounds may be truncated;&lt;br /&gt;
* the table is a metadata table rather than the main table.&lt;br /&gt;
&lt;br /&gt;
When pushdown succeeds, Iceberg plans the files, computes the result from their statistics, and returns it to Spark as a local scan of one row, so no data file is opened.&amp;lt;ref name=&amp;quot;icebergsb&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Aggregate pushdown to JDBC sources ==&lt;br /&gt;
For the JDBC data source, the &amp;lt;code&amp;gt;pushDownAggregate&amp;lt;/code&amp;gt; option (default true) lets Spark send aggregates to the database. The Spark documentation notes that aggregates are pushed only if all the aggregate functions and their related filters can be pushed, and that Spark still applies a final aggregate unless &amp;lt;code&amp;gt;numPartitions&amp;lt;/code&amp;gt; is 1 or the group-by key equals &amp;lt;code&amp;gt;partitionColumn&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-data-sources-jdbc.html |title=JDBC To Other Databases (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How can you tell if an aggregate was pushed? ==&lt;br /&gt;
In &amp;lt;code&amp;gt;EXPLAIN&amp;lt;/code&amp;gt; output, a V2 Parquet or ORC scan with a pushed aggregate lists &amp;lt;code&amp;gt;PushedAggregation&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;PushedGroupBy&amp;lt;/code&amp;gt; in its metadata.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/parquet/ParquetScan.scala |title=ParquetScan.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A JDBC scan lists &amp;lt;code&amp;gt;PushedAggregates&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;PushedGroupByExpressions&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala |title=DataSourceScanExec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For Iceberg, a pushed aggregate replaces the batch scan with a local scan, and the Iceberg logs record the reason whenever pushdown is skipped.&amp;lt;ref name=&amp;quot;icebergsb&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Predicate pushdown]]&lt;br /&gt;
* [[Column pruning]]&lt;br /&gt;
* [[Apache Parquet]]&lt;br /&gt;
* [[Apache Iceberg]]&lt;br /&gt;
* [[Data Source V2]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>