cloud-fan commented on code in PR #59717:
URL: https://github.com/apache/spark/pull/59717#discussion_r4545407722


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetVectorizedSuite.scala:
##########
@@ -1032,6 +1132,82 @@ class ParquetVectorizedSuite extends ParquetTest with 
SharedSparkSession {
     columnWriterStore.flush()
   }
 
+  /**
+   * The file schema and the element column of an optional array column `_1`, 
whose elements are
+   * of the Parquet primitive type `elementType`, annotated with `logicalType` 
if given.
+   */
+  private def arraySchema(
+      elementType: String,
+      logicalType: Option[String] = None): (MessageType, ColumnDescriptor) = {
+    val annotation = logicalType.map(t => s" ($t)").getOrElse("")
+    val parquetSchema = MessageTypeParser.parseMessageType(
+      s"""message root {
+         |  optional group _1 (LIST) {
+         |    repeated group list {
+         |      optional $elementType a$annotation;
+         |    }
+         |  }
+         |}
+         |""".stripMargin)
+    val ty = parquetSchema.getType("_1", "list", "a").asPrimitiveType()
+    (parquetSchema, new ColumnDescriptor(Array("_1", "list", "a"), ty, 1, 3))
+  }
+
+  /** A data page given as its repetition levels, definition levels and 
values. */
+  private case class EncodedPage(
+      repetitionLevels: Seq[Int],
+      definitionLevels: Seq[Int],
+      values: Seq[Any],
+      dictionaryEncoded: Boolean)
+
+  /**
+   * Returns a row group with a single column chunk made of `pages`, in order, 
each PLAIN or
+   * dictionary encoded. Parquet writers normally fall back from dictionary to 
PLAIN for good, so
+   * a dictionary page after a PLAIN one can't be produced with 
`writeDataPage` alone. The

Review Comment:
   **Nit (P3):** `writeDataPage` builds a new `ColumnWriteStoreV1` on every 
call (line 1101), so parquet-mr's permanent fallback to PLAIN never carries 
from one call to the next. `testPrimitiveString` and 
`testNestedStringArrayOneLevel` already write several pages into one 
`MemPageStore`, one call per page. Two calls into one store, PLAIN and then 
dictionary-encoded, would give the layout of the first four SPARK-60490 tests.
   
   From reading parquet-column 1.18.1, what actually forces one store per page 
is the page store. Every dictionary-encoded `writeDataPage` call flushes its 
own dictionary page, a `MemPageStore` keeps one `MemPageWriter` per column, and 
`MemPageWriter.writeDictionaryPage` throws `ParquetEncodingException("Only one 
dictionary page per block")` once a dictionary page is set. So the separate 
stores are needed only for layouts with more than one dictionary-encoded page, 
like the dictionary/PLAIN/dictionary test. A maintainer who trusts the current 
wording could try to simplify the helper and hit that exception, or miss that 
two `writeDataPage` calls into one store already cover a single 
PLAIN-to-dictionary switch. Suggested wording:
   
   ```suggestion
      * dictionary encoded. Each dictionary-encoded `writeDataPage` call writes 
its own dictionary
      * page, and a `MemPageStore` allows only one per column, so each page is 
written to its own
      * store and the data pages are then combined behind a single dictionary 
page. The
   ```
   
   **Verification:**
   - **Inspection:** Read the revised helper documentation and confirm that it 
attributes the need for one store per page to the in-memory page writer 
accepting only one dictionary page per column chunk, with each 
dictionary-encoded write producing its own dictionary page, that it no longer 
blames writer fallback, and that the diff touches only the comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to