When I compare a Int with a String, Spark casts the right hand side
sql("SELECT 1621335543 >= '2021-05-18'").explain(true)
== Analyzed Logical Plan ==
(1621335543 >= CAST(2021-05-18 AS INT)): boolean
Project [(1621335543 >= cast(2021-05-18 as int)) AS (1621335543 >= CAST(2021-05-18 AS INT))#1309]
+- OneRowRelation
In this case, Spark casts the value '2021-05-18' to Int and the result is NULL.
But when I compare a Timestamp with a String, Spark casts the left hand side
sql("SELECT current_timestamp() >= '2021-05-18'").explain(true)
== Analyzed Logical Plan ==
(CAST(current_timestamp() AS STRING) >= 2021-05-18): boolean
Project [(cast(current_timestamp() as string) >= 2021-05-18) AS (CAST(current_timestamp() AS STRING) >= 2021-05-18)#1313]
+- OneRowRelation
How Spark chooses which DataType to cast ?