cloud-fan commented on a change in pull request #26463: [SPARK-29837][SQL]
PostgreSQL dialect: cast to boolean
URL: https://github.com/apache/spark/pull/26463#discussion_r345274654
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/postgreSQL/CastSuite.scala
##########
@@ -16,44 +16,57 @@
*/
package org.apache.spark.sql.catalyst.expressions.postgreSQL
+import java.sql.{Date, Timestamp}
+
import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.expressions.{ExpressionEvalHelper,
Literal}
class CastSuite extends SparkFunSuite with ExpressionEvalHelper {
- private def checkPostgreCastStringToBoolean(v: Any, expected: Any): Unit = {
- checkEvaluation(PostgreCastStringToBoolean(Literal(v)), expected)
+ private def checkPostgreCastToBoolean(v: Any, expected: Any): Unit = {
+ checkEvaluation(PostgreCastToBoolean(Literal(v), None), expected)
}
test("cast string to boolean") {
- checkPostgreCastStringToBoolean("true", true)
- checkPostgreCastStringToBoolean("tru", true)
- checkPostgreCastStringToBoolean("tr", true)
- checkPostgreCastStringToBoolean("t", true)
- checkPostgreCastStringToBoolean("tRUe", true)
- checkPostgreCastStringToBoolean(" tRue ", true)
- checkPostgreCastStringToBoolean(" tRu ", true)
- checkPostgreCastStringToBoolean("yes", true)
- checkPostgreCastStringToBoolean("ye", true)
- checkPostgreCastStringToBoolean("y", true)
- checkPostgreCastStringToBoolean("1", true)
- checkPostgreCastStringToBoolean("on", true)
+ checkPostgreCastToBoolean("true", true)
+ checkPostgreCastToBoolean("tru", true)
+ checkPostgreCastToBoolean("tr", true)
+ checkPostgreCastToBoolean("t", true)
+ checkPostgreCastToBoolean("tRUe", true)
+ checkPostgreCastToBoolean(" tRue ", true)
+ checkPostgreCastToBoolean(" tRu ", true)
+ checkPostgreCastToBoolean("yes", true)
+ checkPostgreCastToBoolean("ye", true)
+ checkPostgreCastToBoolean("y", true)
+ checkPostgreCastToBoolean("1", true)
+ checkPostgreCastToBoolean("on", true)
+
+ checkPostgreCastToBoolean("false", false)
+ checkPostgreCastToBoolean("fals", false)
+ checkPostgreCastToBoolean("fal", false)
+ checkPostgreCastToBoolean("fa", false)
+ checkPostgreCastToBoolean("f", false)
+ checkPostgreCastToBoolean(" fAlse ", false)
+ checkPostgreCastToBoolean(" fAls ", false)
+ checkPostgreCastToBoolean(" FAlsE ", false)
+ checkPostgreCastToBoolean("no", false)
+ checkPostgreCastToBoolean("n", false)
+ checkPostgreCastToBoolean("0", false)
+ checkPostgreCastToBoolean("off", false)
+ checkPostgreCastToBoolean("of", false)
- checkPostgreCastStringToBoolean("false", false)
- checkPostgreCastStringToBoolean("fals", false)
- checkPostgreCastStringToBoolean("fal", false)
- checkPostgreCastStringToBoolean("fa", false)
- checkPostgreCastStringToBoolean("f", false)
- checkPostgreCastStringToBoolean(" fAlse ", false)
- checkPostgreCastStringToBoolean(" fAls ", false)
- checkPostgreCastStringToBoolean(" FAlsE ", false)
- checkPostgreCastStringToBoolean("no", false)
- checkPostgreCastStringToBoolean("n", false)
- checkPostgreCastStringToBoolean("0", false)
- checkPostgreCastStringToBoolean("off", false)
- checkPostgreCastStringToBoolean("of", false)
+ intercept[Exception](checkPostgreCastToBoolean("o", null))
+ intercept[Exception](checkPostgreCastToBoolean("abc", null))
+ intercept[Exception](checkPostgreCastToBoolean("", null))
+ }
- checkPostgreCastStringToBoolean("o", null)
- checkPostgreCastStringToBoolean("abc", null)
- checkPostgreCastStringToBoolean("", null)
+ test("unsupported data types to cast to boolean") {
+ intercept[Exception](checkPostgreCastToBoolean(new Timestamp(1), null))
+ intercept[Exception](checkPostgreCastToBoolean(new Date(1), null))
+ intercept[Exception](checkPostgreCastToBoolean(1.toLong, null))
Review comment:
It should be `intercept[AnalysisException]...`
----------------------------------------------------------------
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]