sunchao commented on code in PR #60084:
URL: https://github.com/apache/spark/pull/60084#discussion_r4543591883
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/parquet/ParquetScanBuilder.scala:
##########
@@ -95,7 +95,29 @@ case class ParquetScanBuilder(
}
override def pushAggregation(aggregation: Aggregation): Boolean = {
- if (!sparkSession.sessionState.conf.parquetAggregatePushDown) {
+ val sqlConf = sparkSession.sessionState.conf
+ if (!sqlConf.parquetAggregatePushDown) {
+ return false
+ }
+ // With field ID reading, the reader matches columns by field ID rather
than by name (see
+ // `ParquetReadSupport.clipParquetGroupFields`), but the footer statistics
are looked up by
+ // name, so the two could pick different columns.
+ if (sqlConf.parquetFieldIdReadEnabled &&
ParquetUtils.hasFieldIds(dataSchema)) {
Review Comment:
Can this guard use the effective Hadoop configuration that the reader uses?
With session `spark.sql.parquet.fieldId.read.enabled=false`, a read can still
enable ID matching with `.option("spark.sql.parquet.fieldId.read.enabled",
"true")`. `newHadoopConfWithOptions` copies that option into the configuration,
and `ParquetReadSupport.getRequestedSchema` reads the flag from there.
I wrote a single Parquet column `b BIGINT` with field ID 5 and values `100,
200, NULL`, then read it as `a BIGINT` with ID 5 using that option and the
vectorized reader. The ordinary read and base pushdown return `COUNT(a) = 2`
and `MAX(a) = 200`. This guard still admits head pushdown, which searches by
name, returns `COUNT(a) = 0`, and raises `NO_MIN_MAX` for `MAX(a)`.
Reading the same flag and default from the builder's `hadoopConf` would
cover both session configuration and per-read overrides. Could the field-ID
test exercise the option with the session flag false as well?
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetUtils.scala:
##########
@@ -368,9 +387,11 @@ object ParquetUtils extends Logging {
}
isCount = true
if (!isPartitionCol) {
- index = dataSchema.getFieldIndex(colName).getOrElse(-1)
- // Count(*) includes the null values, but Count(colName) doesn't.
- rowCount -= getNumNulls(filePath, blockMetaData, index)
+ index = columnIndex(colName)
+ // Count(*) includes the null values, but Count(colName)
doesn't. A column the
+ // file does not have is all null.
+ rowCount -= (if (index < 0) block.getRowCount
Review Comment:
A field absent from a file can still have a non-null existence default. The
ordinary reader populates the missing vector from the requested field's
`EXISTS_DEFAULT` metadata.
[ParquetColumnVector](https://github.com/apache/spark/blob/7fe7cf5bbe034b70ffccacf0ef90aac6628a3caa/sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java#L76-L99)
For a file containing just `x BIGINT` with values `7, 7`, read with a
nullable `z BIGINT` field created using `.withExistenceDefaultValue("CAST(7 AS
BIGINT)")`. The ordinary scan returns `COUNT(z) = 2` and `MAX(z) = 7`. With
pushdown the new missing-leaf branch returns `COUNT(z) = 0` and a separate
`MAX(z)` raises `NO_MIN_MAX`.
Could the scan builder decline aggregates referencing a data field with an
existence default until the footer path can apply that default? The current
missing-column fixture only covers the case where the missing value is NULL.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetUtils.scala:
##########
@@ -323,12 +324,30 @@ object ParquetUtils extends Logging {
private[sql] def getPushedDownAggResult(
footer: ParquetMetadata,
filePath: String,
- dataSchema: StructType,
+ isCaseSensitive: Boolean,
partitionSchema: StructType,
aggregation: Aggregation)
: (Array[PrimitiveType], Array[Any]) = {
- val footerFileMetaData = footer.getFileMetaData
- val fields = footerFileMetaData.getSchema.getFields
+ // The column chunks of a row group follow the leaf columns of the file
schema, and a nested
+ // column has one chunk per leaf, so a column's position among the
top-level fields is not
+ // the index of its chunk. The file may also order its columns differently
from the data
+ // schema. Aggregates are only pushed down for top-level primitive
columns, so find the
+ // chunk index by matching the column name against the top-level leaves of
the file schema.
+ // Returns -1 if the file does not have the column.
+ val leafColumns = footer.getFileMetaData.getSchema.getColumns
Review Comment:
Can the leaf lookup be initialized lazily? `COUNT(*)` reads the row counts
and never calls `columnIndex`, but this eager `getColumns` still builds paths
and descriptors for every leaf in every file. In an isolated JVM probe against
Parquet 1.18.1, a 2,000-leaf schema allocated about 150 KiB per `getColumns`
call, versus zero for the old `getFields` accessor. Deferring the lookup keeps
that allocation off the row-count-only path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]