Narendra Singh created SPARK-62278:
--------------------------------------

             Summary: Spark Connect infers precision 10 for decimal literals 
instead of the value's own precision
                 Key: SPARK-62278
                 URL: https://issues.apache.org/jira/browse/SPARK-62278
             Project: Spark
          Issue Type: Bug
          Components: Connect, PySpark
    Affects Versions: 4.3.0
            Reporter: Narendra Singh


In Spark Connect, F.lit(decimal.Decimal(...)) always gets at least precision 
10, because the Python client sends DecimalType() (precision 10, scale 0) and 
the server takes max(10, value precision). Classic PySpark uses the value's own 
precision and scale.

{code:python}
from decimal import Decimal
from pyspark.sql import functions as F

spark.range(1).select(F.lit(Decimal("1.230"))).schema[0].dataType
spark.range(1).select(F.lit(Decimal("1.5")) * 
F.lit(Decimal("2.25"))).schema[0].dataType
{code}

Classic:
{code}
DecimalType(4,3)
DecimalType(6,3)
{code}

Connect:
{code}
DecimalType(10,3)
DecimalType(21,3)
{code}

The wider type then flows into arithmetic, unions and CASE WHEN results, so the 
same code gives different result types on Connect and classic.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to