dongjoon-hyun opened a new pull request, #558:
URL: https://github.com/apache/spark-connect-swift/pull/558

   ### What changes were proposed in this pull request?
   
   This PR aims to fix `DECIMAL` decoding to use the full signed 128-bit value.
   
   - `Decimal128Array.subscript` now reads the whole Arrow `Decimal128` value, 
which is a 128-bit little-endian two's complement integer. Previously, it read 
only the low 64 bits as an unsigned integer and always used a plus sign.
   - `ArrowArrayHolderImpl.loadArray` now uses `Decimal128Array` for 
`decimal128` children of `ARRAY` and `STRUCT` columns. Previously, it used 
`FixedArray<Decimal>`, which read the Arrow buffer as the raw memory of 
Foundation `Decimal`.
   
   ### Why are the changes needed?
   
   `DECIMAL` values are silently decoded wrong when they are negative or do not 
fit in 64 bits. This affects `DataFrame.collect()`, `Row.getAsDecimal`, and 
`DataFrame.collect(as:)`.
   
   | SQL | Scala `as[T]` | Swift (before) |
   |---|---|---|
   | `SELECT CAST(-1.5 AS DECIMAL(10,2)) AS v` | `-1.50` | 
`184467440737095514.66` |
   | `SELECT CAST(12345678901234567890.5 AS DECIMAL(38,2)) AS v` | 
`12345678901234567890.50` | `170827812586263823.94` |
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `DECIMAL` values are now decoded correctly, matching Scala 
`Dataset.as[T]`. This includes negative values, 38-digit values, and `DECIMAL` 
elements inside `ARRAY` and `STRUCT` columns.
   
   ### How was this patch tested?
   
   Pass the CIs with the newly added test cases. The expected values were 
verified with `spark-shell` 4.2.0.
   
   - `DataFrameTests.decimalValues` covers `collect()`, `Row.getAsDecimal`, and 
a nested `ARRAY<DECIMAL>`.
   - `CreateDataFrameTests.collectAsDecimal` covers `collect(as:)`.
   
   Both tests cover the following values:
   - `-1.5` as `DECIMAL(10,2)`
   - `12345678901234567890.50` as `DECIMAL(38,2)`
   - the max and min values of `DECIMAL(38,0)`
   - `-0.000000000000000001` as `DECIMAL(38,18)`
   - `0` and `NULL`
   
   ```bash
   swift test --no-parallel --filter 
'DataFrameTests|CreateDataFrameTests|RowTests|SQLTests'
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5


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