dongjoon-hyun commented on code in PR #60343:
URL: https://github.com/apache/spark/pull/60343#discussion_r4540980094


##########
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:
   Thank you, @viirya. I added a note to `assemble()` on why it can keep 
`isAllNull()`: a `NullType` column is primitive, so there is nothing to 
assemble, unlike the levels that `reset()` has to clear.
   



##########
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:
   Sure. The test now checks that each batch has one row and that `c` of the 
i-th batch is `[{null, i}]`. These checks also pass without this fix, while the 
level checks fail, as expected since this is not a correctness issue.
   



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