dongjoon-hyun commented on a change in pull request #27965: [SPARK-31205][SQL]
support string literal as the second argument of date_add/date_sub functions
URL: https://github.com/apache/spark/pull/27965#discussion_r395790680
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
##########
@@ -1043,6 +1045,34 @@ object TypeCoercion {
}
}
}
+
+ /**
+ * A special rule to support string literal as the second argument of
date_add/date_sub functions,
+ * to keep backward compatibility as a temporary workaround.
+ * TODO(SPARK-28589): implement ANSI type type coercion and handle string
literals.
+ */
+ object StringLiteralCoercion extends TypeCoercionRule {
Review comment:
This causes a behavior difference in arithmatic operations, too. Could you
describe the following change in the PR description?
**2.4.5 and 3.0.0-preview2**
```
scala> sql("select (cast('2020-03-28' AS DATE) + '1')").show
org.apache.spark.sql.AnalysisException: cannot resolve '(CAST('2020-03-28'
AS DATE) + CAST('1' AS DOUBLE))' due to data type mismatch: differing types in
'(CAST('2020-03-28' AS DATE) + CAST('1' AS DOUBLE))' (date and double).; line 1
pos 8;
```
This PR.
```
scala> sql("select (cast('2020-03-28' AS DATE) + '1')").show
+-------------------------------------+
|date_add(CAST(2020-03-28 AS DATE), 1)|
+-------------------------------------+
| 2020-03-29|
+-------------------------------------+
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]