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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/orc/OrcPartitionReaderFactory.scala:
##########
@@ -64,6 +64,8 @@ case class OrcPartitionReaderFactory(
   private val isCaseSensitive = sqlConf.caseSensitiveAnalysis
   private val capacity = sqlConf.orcVectorizedReaderBatchSize
   private val orcFilterPushDown = sqlConf.orcFilterPushDown
+  private val fillNullsAndWideDecimalDefaults =

Review Comment:
   The conf read is gone, but I added V2 coverage anyway, since the V2 reader 
factories reach `appendObjects` too. Setting `USE_V1_SOURCE_LIST` to "" does 
not change how the catalog table reads: the plan still has a 
`FileSourceScanExec`. So the test also reads the table's files by path with the 
table schema, which carries the existence defaults, and no V1 fallback. It 
asserts the plan has a `BatchScanExec`, so each column is read through both 
`ParquetPartitionReaderFactory` and `OrcPartitionReaderFactory`. The 
map-containing error reads run on V1 only. On V2 they trip the suite's 
leaked-stream check: the V2 factories do not close a file whose batch fails to 
initialize. That is pre-existing and not related to this change, so I left a 
comment there rather than changing the factories here.



##########
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>> " +
+            "default named_struct('tier', 1, 'scores', array(1, null, 3)), " +
+            "n struct<x: int, inner: struct<y: int>> " +
+            "default named_struct('x', 1, 'inner', cast(null as struct<y: 
int>)), " +
+            s"d decimal(38, 0) default $wide, " +
+            "e decimal(19, 0) default -9999999999999999999, " +
+            "f decimal(38, 30) default 1.5, " +
+            "i decimal(9, 2) default 1.25, " +
+            "l decimal(18, 0) default 999999999999999999, " +
+            "c decimal(38, 10) default 123.5, " +
+            "w struct<v: decimal(38, 0), vs: array<decimal(38, 0)>> " +
+            s"default named_struct('v', $wide, 'vs', array($wide)), " +
+            "m map<string, int> default map('a', cast(null as int), 'b', 2), " 
+
+            s"md map<string, decimal(38, 0)> default map('a', $wide), " +
+            "sm struct<m: map<string, decimal(38, 0)>> " +
+            s"default named_struct('m', map('a', $wide)), " +
+            "sn struct<n: int, m: map<string, int>> " +
+            "default named_struct('n', cast(null as int), 'm', map('a', 1, 
'b', 2)), " +
+            "sw struct<v: decimal(38, 0), m: map<string, int>> " +
+            s"default named_struct('v', $wide, 'm', map('a', 1, 'b', 2)))")
+        }
+        f
+      }
+    }
+  }
+
+  private val fixedColumns = Seq("s", "a", "n", "d", "e", "f", "w")
+  private val mapColumns = Seq("m", "md", "sm", "sn", "sw")
+  private val controlColumns = Seq("i", "l", "c")
+  private val controlValues =
+    Seq(BigDecimal("1.25"), BigDecimal("999999999999999999"), 
BigDecimal("123.5"))
+
+  // Asserts that reading `column` fails with FAILED_READ_FILE caused by the 
old reader error.
+  private def assertOldReadError(column: String, clue: String): Unit = {

Review Comment:
   The legacy test is gone with the conf. The remaining check for 
map-containing defaults now passes each column's expected cause: `Cannot assign 
default column value` for `m`, `sn` and `am`, and `BigInteger out of long 
range` for `md`, `sm` and `sw`.



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