asugranyes commented on PR #53695:
URL: https://github.com/apache/spark/pull/53695#issuecomment-4535677835

   @nchammas - Precisely, Spark's DecimalType doesn't model negative zero, so 
-0.0 without the d suffix is analyzed as a decimal literal and normalized to 
0.0 before any optimizer rule runs.
   
   ```scala
   spark.sql("select -0.0").explain(true)
   ```
   ``` shell
   == Analyzed Logical Plan ==
   0.0: decimal(1,1)
   Project [0.0 AS 0.0#51]
   +- OneRowRelation
   ```
   with the suffix (`-0.0d`) or via the DataFrame API (`Seq(-0.0).toDF("a")`), 
the literal is Double and the sign is preserved.
   
   ```scala
   Seq(-0.0).toDF("a").explain(true)
   ```
   ``` shell
   == Analyzed Logical Plan ==
   a: double
   Project [value#59 AS a#63]
   +- LocalRelation [value#59]
   ```
   Agree it's confusing and worth addressing.


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