dtenedor commented on code in PR #60679:
URL: https://github.com/apache/spark/pull/60679#discussion_r4636246359


##########
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala:
##########
@@ -2063,6 +2063,109 @@ class InsertSuite extends DataSourceTest with 
SharedSparkSession {
     }
   }
 
+  private val legacyNullFieldOrWideDecimalDefault =
+    SQLConf.LEGACY_VECTORIZED_READER_FAIL_ON_NULL_FIELD_OR_WIDE_DECIMAL_DEFAULT
+
+  // Creates a table in `format` with two old rows, then adds columns whose 
existence defaults
+  // have a NULL field, a NULL array element, a NULL nested struct or a 
decimal whose unscaled
+  // value overflows a long, at the top level or in a struct and array (d, e, 
f, w); compact and
+  // wide decimals that fit in a long (i, l, c); and defaults that contain a 
map, which keep the
+  // old error: maps with a NULL or an overflowing decimal value, also nested 
in a struct (m, md,
+  // sm), and a struct with an ordinary map next to a NULL or an overflowing 
decimal (sn, sw).
+  private def withNullFieldAndWideDecimalDefaults(format: String)(f: => Unit): 
Unit = {
+    val wide = "99999999999999999999999999999999999999"
+    withSQLConf(
+      SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "true",
+      SQLConf.PARQUET_VECTORIZED_READER_NESTED_COLUMN_ENABLED.key -> "true",
+      SQLConf.ORC_VECTORIZED_READER_ENABLED.key -> "true",
+      SQLConf.ORC_VECTORIZED_READER_NESTED_COLUMN_ENABLED.key -> "true") {
+      withTable("t") {
+        // The table and its defaults are written with the legacy flag on (the 
reader's old
+        // behavior); the flag changes nothing the writer persists.
+        withSQLConf(legacyNullFieldOrWideDecimalDefault.key -> "true") {
+          sql(s"create table t(id int) using $format")
+          sql("insert into t values (1), (2)")
+          sql("alter table t add columns (" +
+            "s struct<tier: int, nickname: string> " +
+            "default named_struct('tier', 1, 'nickname', cast(null as 
string)), " +
+            "a struct<tier: int, scores: array<int>> " +

Review Comment:
   Added both in 42937cdf: `ta ARRAY<INT> DEFAULT array(1, NULL, 3)` (a 
top-level missing array column, through the array branch with `length = 
capacity`) and `as ARRAY<STRUCT<x: INT>> DEFAULT array(named_struct('x', 1), 
CAST(NULL AS STRUCT<x: INT>))` (through `appendStruct(true)` inside an array). 
Both read correctly for Parquet and ORC through V1 and V2.



##########
sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/WritableColumnVector.java:
##########
@@ -902,12 +969,12 @@ public Optional<Integer> appendObjects(int length, Object 
value) {
       int result = 0;
       for (int i = 0; i < length; ++i) {
         for (Object key : data.keyArray().array()) {
-          if (childColumns[0].appendObjects(1, key).isEmpty()) {
+          if (childColumns[0].appendObjectsImpl(1, key, false).isEmpty()) {

Review Comment:
   Changed in 42937cdf: the map branch now passes `fillNullsAndWideDecimals` 
through for keys and values. `containsMap` is now the only place that rule 
lives, so SPARK-60940 only has to remove that check.



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