beliefer commented on code in PR #43694:
URL: https://github.com/apache/spark/pull/43694#discussion_r1385910298
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -785,17 +786,19 @@ case class Cast(
buildCast[Boolean](_, b => if (b) 1 else 0)
case DateType =>
buildCast[Int](_, d => null)
- case TimestampType if ansiEnabled =>
+ case TimestampType =>
buildCast[Long](_, t => {
val longValue = timestampToLong(t)
if (longValue == longValue.toInt) {
longValue.toInt
} else {
- throw QueryExecutionErrors.castingCauseOverflowError(t, from,
IntegerType)
+ if (ansiEnabled) {
+ throw QueryExecutionErrors.castingCauseOverflowError(t, from,
IntegerType)
+ } else {
+ null
+ }
Review Comment:
Oracle.
`SELECT CAST('2' AS int) FROM DUAL;` output 2.
SELECT CAST(TO_TIMESTAMP('1900-05-05 18:34:56.10', 'YYYY-MM-DD
HH24:MI:SS.FF') AS int) FROM DUAL; output `SQL 错误 [932] [42000]: ORA-00932:
数据类型不一致: 应为 NUMBER, 但却获得 TIMESTAMP`
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -785,17 +786,19 @@ case class Cast(
buildCast[Boolean](_, b => if (b) 1 else 0)
case DateType =>
buildCast[Int](_, d => null)
- case TimestampType if ansiEnabled =>
+ case TimestampType =>
buildCast[Long](_, t => {
val longValue = timestampToLong(t)
if (longValue == longValue.toInt) {
longValue.toInt
} else {
- throw QueryExecutionErrors.castingCauseOverflowError(t, from,
IntegerType)
+ if (ansiEnabled) {
+ throw QueryExecutionErrors.castingCauseOverflowError(t, from,
IntegerType)
+ } else {
+ null
+ }
Review Comment:
Oracle.
`SELECT CAST('2' AS int) FROM DUAL;` output 2.
SELECT CAST(TO_TIMESTAMP('1900-05-05 18:34:56.10', 'YYYY-MM-DD
HH24:MI:SS.FF') AS int) FROM DUAL; output `SQL 错误 [932] [42000]: ORA-00932:
数据类型不一致: 应为 NUMBER, 但却获得 TIMESTAMP`
--
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]