[
https://issues.apache.org/jira/browse/SPARK-62289?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated SPARK-62289:
-----------------------------------
Labels: pull-request-available (was: )
> EXTRACT pushdown fails on SQL Server and Db2
> --------------------------------------------
>
> Key: SPARK-62289
> URL: https://issues.apache.org/jira/browse/SPARK-62289
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 4.0.0
> Reporter: Craiu Constantin-Tiberiu
> Priority: Major
> Labels: pull-request-available
>
> Filters on date parts such as {{year(ts) = 2024}} are pushed down as
> {{EXTRACT(<field> FROM ts)}} to every dialect that does not override
> {{visitExtract}}. SQL Server and Db2 do not, and neither accepts this SQL, so
> the query fails instead of returning rows.
> Filter pushdown is on by default ({{pushDownPredicate=true}}), so this
> affects normal reads.
> SQL Server: SQL Server has no EXTRACT (it uses DATEPART).
> {code:sql}
> -- Spark
> SELECT id FROM mssql.kgdxh23.dt WHERE year(ts) = 2024
> -- sent to SQL Server
> SELECT "id" FROM "kgdxh23"."dt" WHERE ("ts" IS NOT NULL) AND (EXTRACT(YEAR
> FROM CAST("ts" AS date)) = 2024)
> -- result
> SQLServerException: 'EXTRACT' is not a recognized built-in function name.
> {code}
> Db2: Db2 has EXTRACT, but not the fields DAY_OF_WEEK, DAY_OF_YEAR or
> YEAR_OF_WEEK.
> {code:sql}
> -- Spark
> SELECT id FROM db2.KGDXH23.P WHERE dayofweek(dt) = 2
> -- sent to Db2
> SELECT "ID" FROM "KGDXH23"."P" WHERE ("DT" IS NOT NULL) AND
> (((EXTRACT(DAY_OF_WEEK FROM "DT") % 7) + 1) = 2)
> -- result
> DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=DAY_OF_WEEK
> {code}
> With pushdown off, both queries return the expected rows.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]