You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/09/30 00:49:17 UTC

[GitHub] [spark] sunchao opened a new pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

sunchao opened a new pull request #34149:
URL: https://github.com/apache/spark/pull/34149


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   Add a new test suite `ParquetVectorizedSuite` to provide more coverage on vectorized Parquet decoding logic, with different combinations on column index, dictionary, batch size, page size, etc.
   
   To facilitate the test, this also refactored `SpecificParquetRecordReaderBase` and makes the Parquet row group reader pluggable. 
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   Currently `ParquetIOSuite` and `ParquetColumnIndexSuite` only test on the high-level API which is insufficient, especially after the introduction of column index support, for which we want to cover various combinations involving row ranges, first row index, batch size, page size, etc.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   No.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   
   Added new test suite.
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719040354



##########
File path: sql/core/pom.xml
##########
@@ -112,6 +112,24 @@
       <groupId>org.apache.parquet</groupId>
       <artifactId>parquet-column</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-encoding</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-common</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-column</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>

Review comment:
       oh lol - I also confused `common` with `column`. 




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-931991542


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/48294/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-932068437


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/143782/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719036653



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],
+      values: Seq[Any],
+      maxDl: Int,
+      dictionaryEnabled: Boolean = false): Unit = {
+    val columnWriterStore = new ColumnWriteStoreV1(pageWriteStore,
+      ParquetProperties.builder()
+          .withPageSize(4096)
+          .withDictionaryEncoding(dictionaryEnabled)
+          .build())
+    val columnWriter = columnWriterStore.getColumnWriter(cd)
+
+    rls.zip(dls).zipWithIndex.foreach { case ((rl, dl), i) =>
+      if (dl < maxDl) {
+        columnWriter.writeNull(rl, dl)
+      } else {
+        cd.getPrimitiveType.getPrimitiveTypeName match {
+          case PrimitiveTypeName.INT32 =>
+            columnWriter.write(values(i).asInstanceOf[Int], rl, dl)
+          case PrimitiveTypeName.INT64 =>
+            columnWriter.write(values(i).asInstanceOf[Long], rl, dl)
+          case PrimitiveTypeName.BOOLEAN =>
+            columnWriter.write(values(i).asInstanceOf[Boolean], rl, dl)
+          case PrimitiveTypeName.FLOAT =>
+            columnWriter.write(values(i).asInstanceOf[Float], rl, dl)
+          case PrimitiveTypeName.DOUBLE =>
+            columnWriter.write(values(i).asInstanceOf[Double], rl, dl)
+          case PrimitiveTypeName.BINARY =>
+            columnWriter.write(Binary.fromString(values(i).asInstanceOf[String]), rl, dl)
+          case _ =>
+            throw new IllegalStateException(s"Unexpected type: " +
+                s"${cd.getPrimitiveType.getPrimitiveTypeName}")
+        }
+      }
+      columnWriterStore.endRecord()
+    }
+    columnWriterStore.flush()
+  }
+
+  private def checkAnswer(
+      totalRowCount: Int,
+      fileSchema: MessageType,
+      readStore: PageReadStore,
+      expected: Seq[Row],
+      batchSize: Int = NUM_VALUES): Unit = {
+    import collection.JavaConverters._
+
+    val recordReader = new VectorizedParquetRecordReader(
+      DateTimeUtils.getZoneId("EST"), "CORRECTED", "CORRECTED", true, batchSize)
+    recordReader.initialize(fileSchema, fileSchema,
+      TestParquetRowGroupReader(Seq(readStore)), totalRowCount)
+
+    // convert both actual and expected rows into collections
+    val schema = recordReader.sparkSchema
+    val expectedRowIt = ColumnVectorUtils.toBatch(
+      schema, MemoryMode.ON_HEAP, expected.iterator.asJava).rowIterator()
+
+    val rowOrdering = RowOrdering.createNaturalAscendingOrdering(schema.map(_.dataType))
+    var i = 0
+    while (expectedRowIt.hasNext && recordReader.nextKeyValue()) {
+      val expectedRow = expectedRowIt.next()
+      val actualRow = recordReader.getCurrentValue.asInstanceOf[InternalRow]
+      assert(rowOrdering.compare(expectedRow, actualRow) == 0, {
+        val expectedRowStr = toDebugString(schema, expectedRow)
+        val actualRowStr = toDebugString(schema, actualRow)
+        s"at index $i, expected row: $expectedRowStr doesn't match actual row: $actualRowStr"
+      })
+      i += 1
+    }
+  }
+
+  private def toDebugString(schema: StructType, row: InternalRow): String = {
+    if (row == null) "null"
+    else {
+      val fieldStrings = schema.fields.zipWithIndex.map { case (f, i) =>
+        f.dataType match {
+          case IntegerType =>
+            row.getInt(i).toString
+          case StringType =>
+            val utf8Str = row.getUTF8String(i)
+            if (utf8Str == null) "null"
+            else utf8Str.toString
+          case ArrayType(_, _) =>
+            val elements = row.getArray(i)
+            if (elements == null) "null"
+            else "[" + elements.array.mkString(", ") + "]"
+          case _ =>
+            throw new IllegalStateException(s"Unsupported data type: ${f.dataType}")

Review comment:
       For `Unsupported` case, maybe `IllegalArgumentException` is intuitive?

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],
+      values: Seq[Any],
+      maxDl: Int,
+      dictionaryEnabled: Boolean = false): Unit = {
+    val columnWriterStore = new ColumnWriteStoreV1(pageWriteStore,
+      ParquetProperties.builder()
+          .withPageSize(4096)
+          .withDictionaryEncoding(dictionaryEnabled)
+          .build())
+    val columnWriter = columnWriterStore.getColumnWriter(cd)
+
+    rls.zip(dls).zipWithIndex.foreach { case ((rl, dl), i) =>
+      if (dl < maxDl) {
+        columnWriter.writeNull(rl, dl)
+      } else {
+        cd.getPrimitiveType.getPrimitiveTypeName match {
+          case PrimitiveTypeName.INT32 =>
+            columnWriter.write(values(i).asInstanceOf[Int], rl, dl)
+          case PrimitiveTypeName.INT64 =>
+            columnWriter.write(values(i).asInstanceOf[Long], rl, dl)
+          case PrimitiveTypeName.BOOLEAN =>
+            columnWriter.write(values(i).asInstanceOf[Boolean], rl, dl)
+          case PrimitiveTypeName.FLOAT =>
+            columnWriter.write(values(i).asInstanceOf[Float], rl, dl)
+          case PrimitiveTypeName.DOUBLE =>
+            columnWriter.write(values(i).asInstanceOf[Double], rl, dl)
+          case PrimitiveTypeName.BINARY =>
+            columnWriter.write(Binary.fromString(values(i).asInstanceOf[String]), rl, dl)
+          case _ =>
+            throw new IllegalStateException(s"Unexpected type: " +
+                s"${cd.getPrimitiveType.getPrimitiveTypeName}")
+        }
+      }
+      columnWriterStore.endRecord()
+    }
+    columnWriterStore.flush()
+  }
+
+  private def checkAnswer(
+      totalRowCount: Int,
+      fileSchema: MessageType,
+      readStore: PageReadStore,
+      expected: Seq[Row],
+      batchSize: Int = NUM_VALUES): Unit = {
+    import collection.JavaConverters._
+
+    val recordReader = new VectorizedParquetRecordReader(
+      DateTimeUtils.getZoneId("EST"), "CORRECTED", "CORRECTED", true, batchSize)
+    recordReader.initialize(fileSchema, fileSchema,
+      TestParquetRowGroupReader(Seq(readStore)), totalRowCount)
+
+    // convert both actual and expected rows into collections
+    val schema = recordReader.sparkSchema
+    val expectedRowIt = ColumnVectorUtils.toBatch(
+      schema, MemoryMode.ON_HEAP, expected.iterator.asJava).rowIterator()
+
+    val rowOrdering = RowOrdering.createNaturalAscendingOrdering(schema.map(_.dataType))
+    var i = 0
+    while (expectedRowIt.hasNext && recordReader.nextKeyValue()) {
+      val expectedRow = expectedRowIt.next()
+      val actualRow = recordReader.getCurrentValue.asInstanceOf[InternalRow]
+      assert(rowOrdering.compare(expectedRow, actualRow) == 0, {
+        val expectedRowStr = toDebugString(schema, expectedRow)
+        val actualRowStr = toDebugString(schema, actualRow)
+        s"at index $i, expected row: $expectedRowStr doesn't match actual row: $actualRowStr"
+      })
+      i += 1
+    }
+  }
+
+  private def toDebugString(schema: StructType, row: InternalRow): String = {
+    if (row == null) "null"
+    else {
+      val fieldStrings = schema.fields.zipWithIndex.map { case (f, i) =>
+        f.dataType match {
+          case IntegerType =>
+            row.getInt(i).toString
+          case StringType =>
+            val utf8Str = row.getUTF8String(i)
+            if (utf8Str == null) "null"
+            else utf8Str.toString
+          case ArrayType(_, _) =>
+            val elements = row.getArray(i)
+            if (elements == null) "null"
+            else "[" + elements.array.mkString(", ") + "]"
+          case _ =>
+            throw new IllegalStateException(s"Unsupported data type: ${f.dataType}")

Review comment:
       For `Unsupported` case, maybe `IllegalArgumentException` is more intuitive?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930676457


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/48249/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA removed a comment on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-931946603


   **[Test build #143782 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/143782/testReport)** for PR 34149 at commit [`c11dc70`](https://github.com/apache/spark/commit/c11dc702b3a182f8f460be2e5e5cd17bd7072c5d).


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-932791474


   Thanks all!


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a change in pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719955993



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/SpecificParquetRecordReaderBase.java
##########
@@ -175,9 +181,24 @@ protected void initialize(String path, List<String> columns) throws IOException
         this.requestedSchema = ParquetSchemaConverter.EMPTY_MESSAGE();
       }
     }
-    reader.setRequestedSchema(requestedSchema);
+    fileReader.setRequestedSchema(requestedSchema);
     this.sparkSchema = new ParquetToSparkSchemaConverter(config).convert(requestedSchema);
-    this.totalRowCount = reader.getFilteredRecordCount();
+    this.totalRowCount = fileReader.getFilteredRecordCount();
+  }
+
+  protected void initialize(

Review comment:
       marked it with `@VisibleForTesting`




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719032464



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/SpecificParquetRecordReaderBase.java
##########
@@ -88,18 +90,20 @@ public void initialize(InputSplit inputSplit, TaskAttemptContext taskAttemptCont
       .builder(configuration)
       .withRange(split.getStart(), split.getStart() + split.getLength())
       .build();
-    this.reader = new ParquetFileReader(HadoopInputFile.fromPath(file, configuration), options);
-    this.fileSchema = reader.getFileMetaData().getSchema();
-    Map<String, String> fileMetadata = reader.getFileMetaData().getKeyValueMetaData();
+    ParquetFileReader fileReader =new ParquetFileReader(

Review comment:
       Space at `=new`.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sadikovi commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sadikovi commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719062009



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/VectorizedParquetRecordReader.java
##########
@@ -320,7 +331,7 @@ private void initializeInternal() throws IOException, UnsupportedOperationExcept
 
   private void checkEndOfRowGroup() throws IOException {
     if (rowsReturned != totalCountLoadedSoFar) return;
-    PageReadStore pages = reader.readNextFilteredRowGroup();
+    PageReadStore pages = reader.readNextRowGroup();

Review comment:
       Could you elaborate? Does `readNextRowGroup()` handle filtered row groups and column indexes, i.e. would it call `readNextFilteredRowGroup()` if column index is enabled?

##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/SpecificParquetRecordReaderBase.java
##########
@@ -222,4 +243,32 @@ public void close() throws IOException {
       throw new BadConfigurationException("could not instantiate read support class", e);
     }
   }
+
+  interface ParquetRowGroupReader extends Closeable {
+    /**
+     * Reads the next row group from this reader. Returns null if there is no more row group.
+     */
+    PageReadStore readNextRowGroup() throws IOException;
+  }
+
+  private static class ParquetRowGroupReaderImpl implements ParquetRowGroupReader {
+    private final ParquetFileReader reader;
+
+    ParquetRowGroupReaderImpl(ParquetFileReader reader) {
+      this.reader = reader;
+    }
+
+    @Override
+    public PageReadStore readNextRowGroup() throws IOException {
+      return reader.readNextFilteredRowGroup();
+    }
+
+    @Override
+    public void close() throws IOException {
+      if (reader != null) {
+        reader.close();
+      }
+    }
+  }
+

Review comment:
       My OCD again: would it be possible to remove the new line? 😄 




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719097291



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,

Review comment:
       `actual` -> `inputData`?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719097059



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],

Review comment:
       repLevels, defLevels? It is more readable.

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)

Review comment:
       ditto.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-932026997


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/48294/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719099478



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/SpecificParquetRecordReaderBase.java
##########
@@ -175,9 +181,24 @@ protected void initialize(String path, List<String> columns) throws IOException
         this.requestedSchema = ParquetSchemaConverter.EMPTY_MESSAGE();
       }
     }
-    reader.setRequestedSchema(requestedSchema);
+    fileReader.setRequestedSchema(requestedSchema);
     this.sparkSchema = new ParquetToSparkSchemaConverter(config).convert(requestedSchema);
-    this.totalRowCount = reader.getFilteredRecordCount();
+    this.totalRowCount = fileReader.getFilteredRecordCount();
+  }
+
+  protected void initialize(

Review comment:
       We can add a comment saying this is test only?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930749122


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/143738/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930749523


   cc @viirya @cloud-fan @dongjoon-hyun @sadikovi too


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719038379



##########
File path: sql/core/pom.xml
##########
@@ -112,6 +112,24 @@
       <groupId>org.apache.parquet</groupId>
       <artifactId>parquet-column</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-encoding</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-common</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-column</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>

Review comment:
       Sorry for making you confused. It's my 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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA removed a comment on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930652771


   **[Test build #143738 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/143738/testReport)** for PR 34149 at commit [`5c89eae`](https://github.com/apache/spark/commit/5c89eae0f8f1e84dea0e4b1f1f2edb47d6923dd1).


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-932061225


   **[Test build #143782 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/143782/testReport)** for PR 34149 at commit [`c11dc70`](https://github.com/apache/spark/commit/c11dc702b3a182f8f460be2e5e5cd17bd7072c5d).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719032369



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/SpecificParquetRecordReaderBase.java
##########
@@ -75,7 +77,7 @@
    */
   protected long totalRowCount;
 
-  protected ParquetFileReader reader;
+  protected ParquetRowGroupReader reader;

Review comment:
       IMO. This should be emphasized in the title instead of adding more test coverage. :)




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930695894


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/48249/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719032659



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/SpecificParquetRecordReaderBase.java
##########
@@ -88,18 +90,20 @@ public void initialize(InputSplit inputSplit, TaskAttemptContext taskAttemptCont
       .builder(configuration)
       .withRange(split.getStart(), split.getStart() + split.getLength())
       .build();
-    this.reader = new ParquetFileReader(HadoopInputFile.fromPath(file, configuration), options);
-    this.fileSchema = reader.getFileMetaData().getSchema();
-    Map<String, String> fileMetadata = reader.getFileMetaData().getKeyValueMetaData();
+    ParquetFileReader fileReader =new ParquetFileReader(
+      HadoopInputFile.fromPath(file, configuration), options);

Review comment:
       Maybe, 4-space indentation?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-932395560


   Thanks @dongjoon-hyun @sadikovi @viirya ! I've addressed most of your comments. Could you take another look?


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930692891


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/48249/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719032464



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/SpecificParquetRecordReaderBase.java
##########
@@ -88,18 +90,20 @@ public void initialize(InputSplit inputSplit, TaskAttemptContext taskAttemptCont
       .builder(configuration)
       .withRange(split.getStart(), split.getStart() + split.getLength())
       .build();
-    this.reader = new ParquetFileReader(HadoopInputFile.fromPath(file, configuration), options);
-    this.fileSchema = reader.getFileMetaData().getSchema();
-    Map<String, String> fileMetadata = reader.getFileMetaData().getKeyValueMetaData();
+    ParquetFileReader fileReader =new ParquetFileReader(

Review comment:
       nit. Split `=new`.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719040354



##########
File path: sql/core/pom.xml
##########
@@ -112,6 +112,24 @@
       <groupId>org.apache.parquet</groupId>
       <artifactId>parquet-column</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-encoding</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-common</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-column</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>

Review comment:
       oh lol - I was also confused :)




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719037406



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],
+      values: Seq[Any],
+      maxDl: Int,
+      dictionaryEnabled: Boolean = false): Unit = {
+    val columnWriterStore = new ColumnWriteStoreV1(pageWriteStore,
+      ParquetProperties.builder()
+          .withPageSize(4096)
+          .withDictionaryEncoding(dictionaryEnabled)
+          .build())
+    val columnWriter = columnWriterStore.getColumnWriter(cd)
+
+    rls.zip(dls).zipWithIndex.foreach { case ((rl, dl), i) =>
+      if (dl < maxDl) {
+        columnWriter.writeNull(rl, dl)
+      } else {
+        cd.getPrimitiveType.getPrimitiveTypeName match {
+          case PrimitiveTypeName.INT32 =>
+            columnWriter.write(values(i).asInstanceOf[Int], rl, dl)
+          case PrimitiveTypeName.INT64 =>
+            columnWriter.write(values(i).asInstanceOf[Long], rl, dl)
+          case PrimitiveTypeName.BOOLEAN =>
+            columnWriter.write(values(i).asInstanceOf[Boolean], rl, dl)
+          case PrimitiveTypeName.FLOAT =>
+            columnWriter.write(values(i).asInstanceOf[Float], rl, dl)
+          case PrimitiveTypeName.DOUBLE =>
+            columnWriter.write(values(i).asInstanceOf[Double], rl, dl)
+          case PrimitiveTypeName.BINARY =>
+            columnWriter.write(Binary.fromString(values(i).asInstanceOf[String]), rl, dl)
+          case _ =>
+            throw new IllegalStateException(s"Unexpected type: " +
+                s"${cd.getPrimitiveType.getPrimitiveTypeName}")
+        }
+      }
+      columnWriterStore.endRecord()
+    }
+    columnWriterStore.flush()
+  }
+
+  private def checkAnswer(
+      totalRowCount: Int,
+      fileSchema: MessageType,
+      readStore: PageReadStore,
+      expected: Seq[Row],
+      batchSize: Int = NUM_VALUES): Unit = {
+    import collection.JavaConverters._
+
+    val recordReader = new VectorizedParquetRecordReader(
+      DateTimeUtils.getZoneId("EST"), "CORRECTED", "CORRECTED", true, batchSize)
+    recordReader.initialize(fileSchema, fileSchema,
+      TestParquetRowGroupReader(Seq(readStore)), totalRowCount)
+
+    // convert both actual and expected rows into collections
+    val schema = recordReader.sparkSchema
+    val expectedRowIt = ColumnVectorUtils.toBatch(
+      schema, MemoryMode.ON_HEAP, expected.iterator.asJava).rowIterator()
+
+    val rowOrdering = RowOrdering.createNaturalAscendingOrdering(schema.map(_.dataType))
+    var i = 0
+    while (expectedRowIt.hasNext && recordReader.nextKeyValue()) {
+      val expectedRow = expectedRowIt.next()
+      val actualRow = recordReader.getCurrentValue.asInstanceOf[InternalRow]
+      assert(rowOrdering.compare(expectedRow, actualRow) == 0, {
+        val expectedRowStr = toDebugString(schema, expectedRow)
+        val actualRowStr = toDebugString(schema, actualRow)
+        s"at index $i, expected row: $expectedRowStr doesn't match actual row: $actualRowStr"
+      })
+      i += 1
+    }
+  }
+
+  private def toDebugString(schema: StructType, row: InternalRow): String = {
+    if (row == null) "null"
+    else {
+      val fieldStrings = schema.fields.zipWithIndex.map { case (f, i) =>
+        f.dataType match {
+          case IntegerType =>
+            row.getInt(i).toString
+          case StringType =>
+            val utf8Str = row.getUTF8String(i)
+            if (utf8Str == null) "null"
+            else utf8Str.toString
+          case ArrayType(_, _) =>
+            val elements = row.getArray(i)
+            if (elements == null) "null"
+            else "[" + elements.array.mkString(", ") + "]"
+          case _ =>
+            throw new IllegalStateException(s"Unsupported data type: ${f.dataType}")
+        }
+      }
+      fieldStrings.mkString(", ")
+    }
+  }
+
+  case class TestParquetRowGroupReader(groups: Seq[PageReadStore]) extends ParquetRowGroupReader {
+    private var index: Int = 0
+
+    override def readNextRowGroup(): PageReadStore = {
+      if (index == groups.length) {
+        null
+      } else {
+        val res = groups(index)
+        index += 1
+        res
+      }
+    }
+
+    override def close(): Unit = {}
+  }
+
+  private case class TestPageReadStore(
+      original: PageReadStore,

Review comment:
       Shall we use `wrapped` like line 404 for consistency?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-931966100


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/48294/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun closed pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun closed pull request #34149:
URL: https://github.com/apache/spark/pull/34149


   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719099608



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/VectorizedParquetRecordReader.java
##########
@@ -165,6 +166,16 @@ public void initialize(String path, List<String> columns) throws IOException,
     initializeInternal();
   }
 
+  @Override
+  public void initialize(

Review comment:
       test-only too?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-931946603


   **[Test build #143782 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/143782/testReport)** for PR 34149 at commit [`c11dc70`](https://github.com/apache/spark/commit/c11dc702b3a182f8f460be2e5e5cd17bd7072c5d).


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719031898



##########
File path: sql/core/pom.xml
##########
@@ -112,6 +112,24 @@
       <groupId>org.apache.parquet</groupId>
       <artifactId>parquet-column</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-encoding</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-common</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-column</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>

Review comment:
       This `parquet-column` test dependency seems to be duplicated with line 123.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-932026997


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/48294/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930749122


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/143738/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a change in pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719951394



##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/VectorizedParquetRecordReader.java
##########
@@ -320,7 +331,7 @@ private void initializeInternal() throws IOException, UnsupportedOperationExcept
 
   private void checkEndOfRowGroup() throws IOException {
     if (rowsReturned != totalCountLoadedSoFar) return;
-    PageReadStore pages = reader.readNextFilteredRowGroup();
+    PageReadStore pages = reader.readNextRowGroup();

Review comment:
       yes it will, since `ParquetRowGroupReaderImpl` calls `readNextFilteredRowGroup`. As an interface I want to make the name more general. For instance in test we can hook it up with another class that doesn't involve column index.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719103865



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),

Review comment:
       Isn't `toStrings` implicit?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719109666



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],
+      values: Seq[Any],
+      maxDl: Int,
+      dictionaryEnabled: Boolean = false): Unit = {
+    val columnWriterStore = new ColumnWriteStoreV1(pageWriteStore,
+      ParquetProperties.builder()
+          .withPageSize(4096)
+          .withDictionaryEncoding(dictionaryEnabled)
+          .build())
+    val columnWriter = columnWriterStore.getColumnWriter(cd)
+
+    rls.zip(dls).zipWithIndex.foreach { case ((rl, dl), i) =>
+      if (dl < maxDl) {
+        columnWriter.writeNull(rl, dl)
+      } else {
+        cd.getPrimitiveType.getPrimitiveTypeName match {
+          case PrimitiveTypeName.INT32 =>
+            columnWriter.write(values(i).asInstanceOf[Int], rl, dl)
+          case PrimitiveTypeName.INT64 =>
+            columnWriter.write(values(i).asInstanceOf[Long], rl, dl)
+          case PrimitiveTypeName.BOOLEAN =>
+            columnWriter.write(values(i).asInstanceOf[Boolean], rl, dl)
+          case PrimitiveTypeName.FLOAT =>
+            columnWriter.write(values(i).asInstanceOf[Float], rl, dl)
+          case PrimitiveTypeName.DOUBLE =>
+            columnWriter.write(values(i).asInstanceOf[Double], rl, dl)
+          case PrimitiveTypeName.BINARY =>
+            columnWriter.write(Binary.fromString(values(i).asInstanceOf[String]), rl, dl)
+          case _ =>
+            throw new IllegalStateException(s"Unexpected type: " +
+                s"${cd.getPrimitiveType.getPrimitiveTypeName}")
+        }
+      }
+      columnWriterStore.endRecord()
+    }
+    columnWriterStore.flush()
+  }
+
+  private def checkAnswer(
+      totalRowCount: Int,
+      fileSchema: MessageType,
+      readStore: PageReadStore,
+      expected: Seq[Row],
+      batchSize: Int = NUM_VALUES): Unit = {
+    import collection.JavaConverters._
+
+    val recordReader = new VectorizedParquetRecordReader(
+      DateTimeUtils.getZoneId("EST"), "CORRECTED", "CORRECTED", true, batchSize)
+    recordReader.initialize(fileSchema, fileSchema,
+      TestParquetRowGroupReader(Seq(readStore)), totalRowCount)
+
+    // convert both actual and expected rows into collections
+    val schema = recordReader.sparkSchema
+    val expectedRowIt = ColumnVectorUtils.toBatch(
+      schema, MemoryMode.ON_HEAP, expected.iterator.asJava).rowIterator()
+
+    val rowOrdering = RowOrdering.createNaturalAscendingOrdering(schema.map(_.dataType))
+    var i = 0
+    while (expectedRowIt.hasNext && recordReader.nextKeyValue()) {
+      val expectedRow = expectedRowIt.next()
+      val actualRow = recordReader.getCurrentValue.asInstanceOf[InternalRow]
+      assert(rowOrdering.compare(expectedRow, actualRow) == 0, {
+        val expectedRowStr = toDebugString(schema, expectedRow)
+        val actualRowStr = toDebugString(schema, actualRow)
+        s"at index $i, expected row: $expectedRowStr doesn't match actual row: $actualRowStr"
+      })
+      i += 1
+    }
+  }
+
+  private def toDebugString(schema: StructType, row: InternalRow): String = {
+    if (row == null) "null"
+    else {
+      val fieldStrings = schema.fields.zipWithIndex.map { case (f, i) =>
+        f.dataType match {
+          case IntegerType =>
+            row.getInt(i).toString
+          case StringType =>
+            val utf8Str = row.getUTF8String(i)
+            if (utf8Str == null) "null"
+            else utf8Str.toString
+          case ArrayType(_, _) =>
+            val elements = row.getArray(i)
+            if (elements == null) "null"
+            else "[" + elements.array.mkString(", ") + "]"
+          case _ =>
+            throw new IllegalStateException(s"Unsupported data type: ${f.dataType}")
+        }
+      }
+      fieldStrings.mkString(", ")
+    }
+  }
+
+  case class TestParquetRowGroupReader(groups: Seq[PageReadStore]) extends ParquetRowGroupReader {
+    private var index: Int = 0
+
+    override def readNextRowGroup(): PageReadStore = {
+      if (index == groups.length) {
+        null
+      } else {
+        val res = groups(index)
+        index += 1
+        res
+      }
+    }
+
+    override def close(): Unit = {}
+  }
+
+  private case class TestPageReadStore(
+      original: PageReadStore,
+      firstRowIndexes: Seq[Long],
+      rangesOpt: Option[Seq[(Long, Long)]] = None) extends PageReadStore {

Review comment:
       rowIndexRangesOpt?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930652771


   **[Test build #143738 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/143738/testReport)** for PR 34149 at commit [`5c89eae`](https://github.com/apache/spark/commit/5c89eae0f8f1e84dea0e4b1f1f2edb47d6923dd1).


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719031898



##########
File path: sql/core/pom.xml
##########
@@ -112,6 +112,24 @@
       <groupId>org.apache.parquet</groupId>
       <artifactId>parquet-column</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-encoding</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-common</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-column</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>

Review comment:
       ~This `parquet-column` test dependency seems to be duplicated with line 123.~ Oops. My bad. I confused with `common` and `column`.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719122592



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],
+      values: Seq[Any],
+      maxDl: Int,
+      dictionaryEnabled: Boolean = false): Unit = {
+    val columnWriterStore = new ColumnWriteStoreV1(pageWriteStore,
+      ParquetProperties.builder()
+          .withPageSize(4096)

Review comment:
       oh, this is size in bytes.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719036303



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],
+      values: Seq[Any],
+      maxDl: Int,
+      dictionaryEnabled: Boolean = false): Unit = {
+    val columnWriterStore = new ColumnWriteStoreV1(pageWriteStore,
+      ParquetProperties.builder()
+          .withPageSize(4096)
+          .withDictionaryEncoding(dictionaryEnabled)
+          .build())
+    val columnWriter = columnWriterStore.getColumnWriter(cd)
+
+    rls.zip(dls).zipWithIndex.foreach { case ((rl, dl), i) =>
+      if (dl < maxDl) {
+        columnWriter.writeNull(rl, dl)
+      } else {
+        cd.getPrimitiveType.getPrimitiveTypeName match {
+          case PrimitiveTypeName.INT32 =>
+            columnWriter.write(values(i).asInstanceOf[Int], rl, dl)
+          case PrimitiveTypeName.INT64 =>
+            columnWriter.write(values(i).asInstanceOf[Long], rl, dl)
+          case PrimitiveTypeName.BOOLEAN =>
+            columnWriter.write(values(i).asInstanceOf[Boolean], rl, dl)
+          case PrimitiveTypeName.FLOAT =>
+            columnWriter.write(values(i).asInstanceOf[Float], rl, dl)
+          case PrimitiveTypeName.DOUBLE =>
+            columnWriter.write(values(i).asInstanceOf[Double], rl, dl)
+          case PrimitiveTypeName.BINARY =>
+            columnWriter.write(Binary.fromString(values(i).asInstanceOf[String]), rl, dl)
+          case _ =>
+            throw new IllegalStateException(s"Unexpected type: " +
+                s"${cd.getPrimitiveType.getPrimitiveTypeName}")
+        }
+      }
+      columnWriterStore.endRecord()
+    }
+    columnWriterStore.flush()
+  }
+
+  private def checkAnswer(
+      totalRowCount: Int,
+      fileSchema: MessageType,
+      readStore: PageReadStore,
+      expected: Seq[Row],
+      batchSize: Int = NUM_VALUES): Unit = {
+    import collection.JavaConverters._
+
+    val recordReader = new VectorizedParquetRecordReader(
+      DateTimeUtils.getZoneId("EST"), "CORRECTED", "CORRECTED", true, batchSize)
+    recordReader.initialize(fileSchema, fileSchema,
+      TestParquetRowGroupReader(Seq(readStore)), totalRowCount)
+
+    // convert both actual and expected rows into collections
+    val schema = recordReader.sparkSchema
+    val expectedRowIt = ColumnVectorUtils.toBatch(
+      schema, MemoryMode.ON_HEAP, expected.iterator.asJava).rowIterator()
+
+    val rowOrdering = RowOrdering.createNaturalAscendingOrdering(schema.map(_.dataType))
+    var i = 0
+    while (expectedRowIt.hasNext && recordReader.nextKeyValue()) {
+      val expectedRow = expectedRowIt.next()
+      val actualRow = recordReader.getCurrentValue.asInstanceOf[InternalRow]
+      assert(rowOrdering.compare(expectedRow, actualRow) == 0, {
+        val expectedRowStr = toDebugString(schema, expectedRow)
+        val actualRowStr = toDebugString(schema, actualRow)
+        s"at index $i, expected row: $expectedRowStr doesn't match actual row: $actualRowStr"
+      })
+      i += 1
+    }
+  }
+
+  private def toDebugString(schema: StructType, row: InternalRow): String = {
+    if (row == null) "null"
+    else {
+      val fieldStrings = schema.fields.zipWithIndex.map { case (f, i) =>
+        f.dataType match {
+          case IntegerType =>
+            row.getInt(i).toString
+          case StringType =>
+            val utf8Str = row.getUTF8String(i)
+            if (utf8Str == null) "null"
+            else utf8Str.toString
+          case ArrayType(_, _) =>
+            val elements = row.getArray(i)
+            if (elements == null) "null"
+            else "[" + elements.array.mkString(", ") + "]"

Review comment:
       Shall we use a short form?
   ```scala
   - "[" + elements.array.mkString(", ") + "]"
   + elements.array.mkString("[", ", ", "]")
   ```




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719098660



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),
+            batchSize, dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and nulls") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          val valuesWithNulls = VALUES.zipWithIndex.map {
+            case (v, i) => if (i % 2 == 0) null else v
+          }
+          testPrimitiveString(None, None, pageSizes, valuesWithNulls, batchSize, valuesWithNulls,
+            dictionaryEnabled)
+
+          val ranges = Seq((5L, 7L))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq("f", null, "h"),
+            batchSize, valuesWithNulls, dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges and first row indexes") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      Seq(true, false).foreach { dictionaryEnabled =>
+        // Single page
+        val firstRowIndex = 10
+        var ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 15, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 39))
+        testPrimitiveString(Some(Seq(firstRowIndex)), Some(ranges), Seq(VALUES.length),
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes:  [ [10, 16), [20, 26), [30, 37), [40, 47) ]
+        // Values:       [ [0,  6),  [6,  12), [12, 19), [19, 26) ]
+        var pageSizes = Seq(6, 6, 7, 7)
+        var firstRowIndexes = Seq(10L, 20, 30, 40)
+
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 25))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 9, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 35))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 14, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((15, 60))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          5 to 19, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((12, 22), (28, 38))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          toStrings(Seq(2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18)), batchSize,
+          dictionaryEnabled = dictionaryEnabled)
+
+        // Row indexes: [ [10, 11), [40, 52), [100, 112), [200, 201) ]
+        // Values:      [ [0, 1),   [1, 13),  [13, 25),   [25, 26]   ]
+        pageSizes = Seq(1, 12, 12, 1)
+        firstRowIndexes = Seq(10L, 40, 100, 200)
+        ranges = Seq((0L, 9L))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((300, 350))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq.empty, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((50, 80))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          (11 to 12), batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((0, 150))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          0 to 24, batchSize, dictionaryEnabled = dictionaryEnabled)
+
+        // with nulls
+        val valuesWithNulls = VALUES.zipWithIndex.map {
+          case (v, i) => if (i % 2 == 0) null else v
+        }
+        ranges = Seq((20, 45)) // select values in [1, 5]
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq("b", null, "d", null, "f"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+
+        ranges = Seq((8, 12), (80, 104))
+        testPrimitiveString(Some(firstRowIndexes), Some(ranges), pageSizes,
+          Seq(null, "n", null, "p", null, "r"), batchSize, valuesWithNulls,
+          dictionaryEnabled = dictionaryEnabled)
+      }
+    }
+  }
+
+  private def testPrimitiveString(
+      firstRowIndexesOpt: Option[Seq[Long]],
+      rangesOpt: Option[Seq[(Long, Long)]],
+      pageSizes: Seq[Int],
+      expected: Seq[String],
+      batchSize: Int,
+      actual: Seq[String] = VALUES,
+      dictionaryEnabled: Boolean = false): Unit = {
+    assert(pageSizes.sum == actual.length)
+    firstRowIndexesOpt.foreach(a => assert(pageSizes.length == a.length))
+
+    val isRequiredStr = if (!expected.contains(null)) "required" else "optional"
+    val parquetSchema: MessageType = MessageTypeParser.parseMessageType(
+      s"""message root {
+         | $isRequiredStr binary a(UTF8);
+         |}
+         |""".stripMargin
+    )
+    val maxDef = if (actual.contains(null)) 1 else 0
+    val ty = parquetSchema.asGroupType().getType("a").asPrimitiveType()
+    val cd = new ColumnDescriptor(Seq("a").toArray, ty, 0, maxDef)
+    val rls = Array.fill[Int](actual.length)(0)
+    val dls = actual.map(v => if (v == null) 0 else 1)
+
+    val memPageStore = new MemPageStore(expected.length)
+
+    var i = 0
+    val pageFirstRowIndexes = ArrayBuffer.empty[Long]
+    pageSizes.foreach { size =>
+      pageFirstRowIndexes += i
+      writeDataPage(cd, memPageStore, rls.slice(i, i + size), dls.slice(i, i + size),
+        actual.slice(i, i + size), maxDef, dictionaryEnabled)
+      i += size
+    }
+
+    checkAnswer(expected.length, parquetSchema,
+      TestPageReadStore(memPageStore, firstRowIndexesOpt.getOrElse(pageFirstRowIndexes).toSeq,
+        rangesOpt), expected.map(i => Row(i)), batchSize)
+  }
+
+  /**
+   * Write a single data page using repetition levels (`rls`), definition levels (`dls`) and
+   * values (`values`) provided.
+   *
+   * Note that this requires `rls`, `dls` and `values` to have the same number of elements. For
+   * null values, the corresponding slots in `values` will be skipped.
+   */
+  private def writeDataPage(
+      cd: ColumnDescriptor,
+      pageWriteStore: PageWriteStore,
+      rls: Seq[Int],
+      dls: Seq[Int],
+      values: Seq[Any],
+      maxDl: Int,
+      dictionaryEnabled: Boolean = false): Unit = {
+    val columnWriterStore = new ColumnWriteStoreV1(pageWriteStore,
+      ParquetProperties.builder()
+          .withPageSize(4096)

Review comment:
       Isn't the page size equal to `values.length`?




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-932068437


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/143782/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a change in pull request #34149: [SPARK-36891][SQL] Refactor SpecificParquetRecordReaderBase and add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719957586



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala
##########
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources.parquet
+
+import java.util.{Optional, PrimitiveIterator}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.language.implicitConversions
+
+import org.apache.parquet.column.{ColumnDescriptor, ParquetProperties}
+import org.apache.parquet.column.impl.ColumnWriteStoreV1
+import org.apache.parquet.column.page._
+import org.apache.parquet.column.page.mem.MemPageStore
+import org.apache.parquet.io.ParquetDecodingException
+import org.apache.parquet.io.api.Binary
+import org.apache.parquet.schema.{MessageType, MessageTypeParser}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+
+import org.apache.spark.memory.MemoryMode
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
+import org.apache.spark.sql.execution.datasources.parquet.SpecificParquetRecordReaderBase.ParquetRowGroupReader
+import org.apache.spark.sql.execution.vectorized.ColumnVectorUtils
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+/**
+ * A test suite on the vectorized Parquet reader. Unlike `ParquetIOSuite`, this focuses on
+ * low-level decoding logic covering column index, dictionary, different batch and page sizes, etc.
+ */
+class ParquetVectorizedSuite extends QueryTest with ParquetTest with SharedSparkSession {
+  private val VALUES: Seq[String] = ('a' to 'z').map(_.toString)
+  private val NUM_VALUES: Int = VALUES.length
+  private val BATCH_SIZE_CONFIGS: Seq[Int] = Seq(1, 3, 5, 7, 10, 20, 40)
+  private val PAGE_SIZE_CONFIGS: Seq[Seq[Int]] = Seq(Seq(6, 6, 7, 7), Seq(4, 9, 4, 9))
+
+  implicit def toStrings(ints: Seq[Int]): Seq[String] = ints.map(i => ('a' + i).toChar.toString)
+
+  test("primitive type - no column index") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          testPrimitiveString(None, None, pageSizes, VALUES, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+        }
+      }
+    }
+  }
+
+  test("primitive type - column index with ranges") {
+    BATCH_SIZE_CONFIGS.foreach { batchSize =>
+      PAGE_SIZE_CONFIGS.foreach { pageSizes =>
+        Seq(true, false).foreach { dictionaryEnabled =>
+          var ranges = Seq((0L, 9L))
+          testPrimitiveString(None, Some(ranges), pageSizes, 0 to 9, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((30, 50))
+          testPrimitiveString(None, Some(ranges), pageSizes, Seq.empty, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((15, 25))
+          testPrimitiveString(None, Some(ranges), pageSizes, 15 to 19, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((19, 20))
+          testPrimitiveString(None, Some(ranges), pageSizes, 19 to 20, batchSize,
+            dictionaryEnabled = dictionaryEnabled)
+
+          ranges = Seq((0, 3), (5, 7), (15, 18))
+          testPrimitiveString(None, Some(ranges), pageSizes,
+            toStrings(Seq(0, 1, 2, 3, 5, 6, 7, 15, 16, 17, 18)),

Review comment:
       Somehow in this case it doesn't work and will fail to compile




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a change in pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #34149:
URL: https://github.com/apache/spark/pull/34149#discussion_r719032426



##########
File path: sql/core/pom.xml
##########
@@ -112,6 +112,24 @@
       <groupId>org.apache.parquet</groupId>
       <artifactId>parquet-column</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-encoding</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-common</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.parquet</groupId>
+      <artifactId>parquet-column</artifactId>
+      <scope>test</scope>
+      <classifier>tests</classifier>
+    </dependency>

Review comment:
       oops you are right - not sure why I had two of these.




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930695894


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/48249/
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #34149: [SPARK-36891][SQL] Add more coverage on vectorized Parquet decoding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34149:
URL: https://github.com/apache/spark/pull/34149#issuecomment-930748486


   **[Test build #143738 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/143738/testReport)** for PR 34149 at commit [`5c89eae`](https://github.com/apache/spark/commit/5c89eae0f8f1e84dea0e4b1f1f2edb47d6923dd1).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org