Aleksandar Trajković created SPARK-62386:
--------------------------------------------

             Summary: Pushed JDBC casts between arrays still round each element 
on PostgreSQL
                 Key: SPARK-62386
                 URL: https://issues.apache.org/jira/browse/SPARK-62386
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 5.0.0
            Reporter: Aleksandar Trajković


SPARK-58372 makes casts from FLOAT, DOUBLE and DECIMAL to an integral type that 
are pushed down to JDBC sources truncate toward zero like Spark, or stay in 
Spark when the dialect can't truncate. It checks only the top-level types of 
the cast, so a cast between arrays whose element cast drops a fraction is still 
pushed as a plain cast.

For example, on PostgreSQL, with the default ANSI mode, CAST(a AS ARRAY<INT>) 
over a float8[] column is sent as CAST("a" AS INTEGER[]). PostgreSQL rounds 
each element, so a pushed filter, group-by key or sort key over the cast can 
return different rows than Spark. For a = {1.6} and b = {1.4}, WHERE CAST(a AS 
ARRAY<INT>) = CAST(b AS ARRAY<INT>) drops the row in PostgreSQL ({2} vs {1}) 
but keeps it in Spark ([1] vs [1]).

This applies at any nesting depth, for arrays of FLOAT, DOUBLE or DECIMAL with 
a nonzero scale cast to arrays of an integral type. PostgreSQL is the only 
built-in dialect that maps array cast targets (PostgresDialect.getJDBCType), so 
the gap is limited to it.

Suggested fix: in JdbcDialect.JDBCSQLBuilder.visitCast, unwrap a cast between 
arrays to its innermost element types, and keep it in Spark when the element 
cast drops a fraction unless truncateFractionalValue returns the value 
unchanged for the element type. 
spark.sql.legacy.jdbc.roundIntegralCastPushdown.enabled should keep restoring 
the previous SQL.




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