You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "himadripal (via GitHub)" <gi...@apache.org> on 2024/11/14 05:32:13 UTC

Re: [I] Implement Spark-compatible cast between decimals with different precision and scale [datafusion-comet]

himadripal commented on issue #375:
URL: https://github.com/apache/datafusion-comet/issues/375#issuecomment-2475453842

   I was trying to take a look at this one - I added this test in the CometCastSuite -
   
   ```scala 
   test("cast between decimals with different precision and scale") {
       val df = generateDecimalsPrecision38Scale18()
         val df1 = df.withColumn("b", col("a").cast(DataTypes.createDecimalType(10, 2)))
       df.show(false)
       df1.show(false)
       castTest(generateDecimalsPrecision38Scale18(), DataTypes.createDecimalType(6, 2))
     }
   ```
   
   It gives me result like this 
   ```sql 
   +----------------------------------------+----------+
   |a                                       |b         |
   +----------------------------------------+----------+
   |-99999999999999999999.999999999999000000|null      |
   |-9223372036854775808.234567000000000000 |null      |
   |-9223372036854775807.123123000000000000 |null      |
   |-2147483648.123123123000000000          |null      |
   |-2147483647.123123123000000000          |null      |
   |-123456.789000000000000000              |-123456.79|
   |0E-18                                   |0.00      |
   |123456.789000000000000000               |123456.79 |
   |2147483647.123123123000000000           |null      |
   |2147483648.123123123000000000           |null      |
   |9223372036854775807.123123000000000000  |null      |
   |9223372036854775808.234567000000000000  |null      |
   |99999999999999999999.999999999999000000 |null      |
   |null                                    |null      |
   +----------------------------------------+----------+
   ````
   But `castTest` fails with the following assertion error -
   ```scala
   Expected only Comet native operators, but found Sort.
   plan: Sort [a#7 ASC NULLS FIRST], true, 0
   +- Project [a#7, cast(a#7 as decimal(6,2)) AS a#9]
      +- CometCoalesce Coalesce 1, [a#7], 1
         +- CometScan parquet [a#7] Batched: true, DataFilters: [], Format: CometParquet, Location: InMemoryFileIndex(1 paths)[file:/private/var/folders/jx/23vwhfzn2ts493_2twyz1dpc0000gn/T/spark-ef..., PartitionFilters: [], PushedFilters: [], ReadSchema: struct<a:decimal(38,18)>
   ```
   So from the actual code perspective it seems to be working, @viirya  can you provide some guidance here?


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org