Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-42176][SQL] Fix cast of a boolean value to timestamp
### What changes were proposed in this pull request? The PR fixes an issue when casting a boolean to timestamp. While `select cast(true as timestamp)` works and returns `1970-01-01 00:00:00.000001`, casting `false` to timestamp fails with the following error: > IllegalArgumentException: requirement failed: Literal must have a corresponding value to timestamp, but class Integer found. SBT test also fails with this error: ``` [info] java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long [info] at scala.runtime.BoxesRunTime.unboxToLong(BoxesRunTime.java:107) [info] at org.apache.spark.sql.catalyst.InternalRow$.$anonfun$getWriter$5(InternalRow.scala:178) [info] at org.apache.spark.sql.catalyst.InternalRow$.$anonfun$getWriter$5$adapted(InternalRow.scala:178) ``` The issue was that we need to return `0L` instead of `0` when converting `false` to a long. ### Why are the changes needed? Fixes a small bug in cast. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? I added a unit test to verify the fix. Closes apache#39729 from sadikovi/fix_spark_boolean_to_timestamp. Authored-by: Ivan Sadikov <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
- Loading branch information