viirya commented on code in PR #60343:
URL: https://github.com/apache/spark/pull/60343#discussion_r4540914918


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala:
##########
@@ -885,6 +885,36 @@ 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()) {
+            numBatches += 1
+            // `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)

Review Comment:
   nit: could we also check the batch content here, e.g. that `c` is `[{null, 
i}]` for the i-th batch? The existing `SPARK-54220: NullType` test reads a 
single batch, so nothing covers a nested `NullType` field across batches yet.



##########
sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java:
##########
@@ -216,8 +216,9 @@ void assemble() {
    * (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;

Review Comment:
   nit: `assemble()` right above keeps `isAllNull()` under a comment that still 
says "the column itself is missing". Could you add a short note there on why it 
differs from this one, so the two guards don't get unified later by mistake?



-- 
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]

Reply via email to