LuciferYang opened a new pull request, #55894:
URL: https://github.com/apache/spark/pull/55894

   ### What changes were proposed in this pull request?
   
   Backport of #55890 to `branch-4.2`.
   
   `DowncastLongUpdater.decodeSingleDictionaryId` calls `values.putLong(...)`, 
but `DowncastLongUpdater` is only chosen when the target is a 32-bit Decimal 
(precision <= 9), whose column vector stores into `intData`, not `longData`. So 
`putLong` NPEs whenever this path runs.
   
   Switch the call to `putInt` with the same `(int) longValue` narrowing cast 
already used by `readValue` and `readValues`.
   
   ### Why are the changes needed?
   
   The bug has been latent since SPARK-35640 (Jun 2021). The path is only 
reachable when all three conditions hold:
   
   1. Parquet stores the column as INT64 + DECIMAL(p<=9). Spark's own writer 
emits INT32 for this case, so the file must come from another writer (Hive, 
Impala, ...).
   2. Spark reads it as a Decimal with precision <= 9.
   3. The vectorized reader has to eagerly drain buffered dictionary IDs -- 
typically when parquet-mr writes the column as a mix of dictionary-encoded and 
PLAIN pages and a non-dict page follows a dict page in the same batch. The 
normal lazy-dictionary path decodes at row read time via `ParquetDictionary` 
and never touches this updater method.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Reads that previously NPE'd now return correct values.
   
   ### How was this patch tested?
   
   Same regression test from #55890 backported to `branch-4.2`: writes INT64 + 
DECIMAL(9, 2) via parquet-mr's low-level writer with mix-cardinality data to 
force the dictionary -> PLAIN fallback. Without the fix it reproduces the NPE; 
with the fix it passes.
   
   ```
   build/sbt 'sql/testOnly *ParquetIOSuite -- -z "SPARK-56872"'
   ...
   [info] Tests: succeeded 1, failed 0
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No


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