This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 0d52f01d106d [SPARK-61460][SQL] Fix vectorized Parquet reader memory
growth when a struct in an array or map has a NullType field
0d52f01d106d is described below
commit 0d52f01d106dcde2098f3536f81c798f2ea6eba0
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Wed Nov 11 11:52:40 2026 -0800
[SPARK-61460][SQL] Fix vectorized Parquet reader memory growth when a
struct in an array or map has a NullType field
### What changes were proposed in this pull request?
This PR aims to fix `ParquetColumnVector.reset()` to skip only missing
columns, so that the repetition and definition levels of a `NullType` column
are reset for each batch.
Since SPARK-54220 (#52922), `WritableColumnVector.isAllNull()` is true for
a `NullType` column as well as for a missing column, and
`ParquetColumnVector.reset()` returns early for both. However, a `NullType`
column in the file still has a column reader, which writes its repetition and
definition levels for each batch. A parent struct shares and resets only the
levels of its last non-missing field. So, the levels of a `NullType` field that
is not the last field, e.g. `n` in `array<stru [...]
`assemble()` keeps its `isAllNull()` check because it does nothing for a
primitive column like a `NullType` column.
### Why are the changes needed?
Inside an array or a map, the column reader appends to these level vectors,
so they grow with every batch and hold all levels of the file split until the
reader is closed. For example, after reading 1,000,000 rows of `array<struct<n:
void, a: int>>` with 4 elements each (a 9.2 MB file), each level vector of `n`
holds 4,000,000 integers (about 16 MB), while those of `a` stay at the batch
size.
This bug exists since Apache Spark 4.1.0
([v4.1.0](https://github.com/apache/spark/releases/tag/v4.1.0), 2025-12-11).
### Does this PR introduce _any_ user-facing change?
No. The query results are the same. Only the memory usage of the vectorized
Parquet reader is fixed for such schemas.
### How was this patch tested?
Pass the CIs with the newly added test case. Without this fix, the new test
case fails like the following.
```
- SPARK-61460: Vectorized reader resets the levels of a NullType field for
each batch *** FAILED ***
2 did not equal 1 (ParquetVectorizedSuite.scala:915)
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
Closes #60343 from dongjoon-hyun/SPARK-61460.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
skip-checks: true
---
.../datasources/parquet/ParquetColumnVector.java | 8 +++--
.../parquet/ParquetVectorizedSuite.scala | 39 ++++++++++++++++++++++
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git
a/sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java
b/sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java
index 002b7569a6e0..23578a684000 100644
---
a/sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java
+++
b/sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java
@@ -194,7 +194,8 @@ final class ParquetColumnVector {
}
return;
}
- // nothing to do if the column itself is missing
+ // nothing to do if the column itself is missing or is a NullType column.
Unlike `reset()`,
+ // this can skip a NullType column because it is primitive, so there is
nothing to assemble.
if (vector.isAllNull()) return;
DataType type = column.sparkType();
@@ -216,8 +217,9 @@ final class ParquetColumnVector {
* (used to store values, definition levels, and repetition levels) for this
and all its children.
*/
void reset() {
- // nothing to do if the column itself is missing
- if (vector.isAllNull()) return;
+ // nothing to do if the column itself is missing. A NullType column is not
missing: its
+ // column reader still writes repetition and definition levels for each
batch.
+ if (vector.isMissing()) return;
vector.reset();
if (repetitionLevels != null) {
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
index 783d8282f2bb..15980fbc2469 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
@@ -885,6 +885,45 @@ class ParquetVectorizedSuite extends ParquetTest with
SharedSparkSession {
}
}
+ test("SPARK-61460: Vectorized reader resets the levels of a NullType field
for each batch") {
+ withTempPath { dir =>
+ val schema = new StructType().add("c",
+ ArrayType(new StructType().add("n", NullType).add("a", IntegerType)))
+ val rows = (0 until 3).map(i => Row(Seq(Row(null, i))))
+ spark.createDataFrame(spark.sparkContext.parallelize(rows, numSlices =
1), schema)
+ .write.parquet(dir.getCanonicalPath)
+
+ withSQLConf(SQLConf.PARQUET_VECTORIZED_READER_BATCH_SIZE.key -> "1") {
+ val file = TestUtils.listDirectory(dir).head
+ val reader = createVectorizedReader(file, schema, offheapEnabled =
false)
+ try {
+ var numBatches = 0
+ while (reader.nextKeyValue()) {
+ // The i-th batch has one row, whose `c` is `[{null, i}]`.
+ val batch = reader.resultBatch()
+ assert(batch.numRows == 1)
+ val c = batch.column(0).getArray(0)
+ assert(c.numElements == 1)
+ val element = c.getStruct(0, 2)
+ assert(element.isNullAt(0))
+ assert(element.getInt(1) == numBatches)
+
+ // `n` is not the last field, so the struct does not share and
reset its levels.
+ val n = ParquetTestAccess.columnVectors(reader).head
+ .asInstanceOf[ParquetColumnVector].getLeaves.get(0)
+ assert(n.getValueVector.dataType == NullType)
+ assert(n.getRepetitionLevelVector.getElementsAppended == 1)
+ assert(n.getDefinitionLevelVector.getElementsAppended == 1)
+ numBatches += 1
+ }
+ assert(numBatches == 3)
+ } finally {
+ reader.close()
+ }
+ }
+ }
+ }
+
private def truncateTypeTest(
testName: String,
readType: DataType,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]