Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/20774#discussion_r175332620 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala --- @@ -1251,18 +1251,40 @@ class TypeCoercionSuite extends AnalysisTest { } test("binary comparison with string promotion") { - ruleTest(PromoteStrings, - GreaterThan(Literal("123"), Literal(1)), - GreaterThan(Cast(Literal("123"), IntegerType), Literal(1))) - ruleTest(PromoteStrings, - LessThan(Literal(true), Literal("123")), - LessThan(Literal(true), Cast(Literal("123"), BooleanType))) - ruleTest(PromoteStrings, - EqualTo(Literal(Array(1, 2)), Literal("123")), - EqualTo(Literal(Array(1, 2)), Literal("123"))) - ruleTest(PromoteStrings, - GreaterThan(Literal("1.5"), Literal(BigDecimal("0.5"))), - GreaterThan(Cast(Literal("1.5"), DoubleType), Cast(Literal(BigDecimal("0.5")), DoubleType))) + val rule = TypeCoercion.PromoteStrings(conf) + + Seq("true", "false").foreach { flag => + withSQLConf("spark.sql.hive.compareDateTimestampInTimestamp" -> flag) { + ruleTest(rule, + GreaterThan(Literal("123"), Literal(1)), + GreaterThan(Cast(Literal("123"), IntegerType), Literal(1))) + ruleTest(rule, + LessThan(Literal(true), Literal("123")), + LessThan(Literal(true), Cast(Literal("123"), BooleanType))) + ruleTest(rule, + EqualTo(Literal(Array(1, 2)), Literal("123")), + EqualTo(Literal(Array(1, 2)), Literal("123"))) + ruleTest(rule, + GreaterThan(Literal("1.5"), Literal(BigDecimal("0.5"))), + GreaterThan(Cast(Literal("1.5"), DoubleType), Cast(Literal(BigDecimal("0.5")), + DoubleType))) + val date0301 = Literal(java.sql.Date.valueOf("2017-03-01")) + val timestamp0301000000 = Literal(Timestamp.valueOf("2017-03-01 00:00:00")) + val timestamp0301000001 = Literal(Timestamp.valueOf("2017-03-01 00:00:01")) + if ("true".equals(flag)) { + // `Date` should be treated as timestamp at 00:00:00 See SPARK-23549 + ruleTest(rule, EqualTo(date0301, timestamp0301000000), + EqualTo(Cast(date0301, TimestampType), timestamp0301000000)) + ruleTest(rule, LessThan(date0301, timestamp0301000001), + LessThan(Cast(date0301, TimestampType), timestamp0301000001)) + } else { + ruleTest(rule, LessThan(date0301, timestamp0301000000), + LessThan(Cast(date0301, StringType), Cast(timestamp0301000000, StringType))) + ruleTest(rule, LessThan(date0301, timestamp0301000001), + LessThan(Cast(date0301, StringType), Cast(timestamp0301000001, StringType))) + } + } + } --- End diff -- ```Scala test("binary comparison with string promotion") { val rule = TypeCoercion.PromoteStrings(conf) ruleTest(rule, GreaterThan(Literal("123"), Literal(1)), GreaterThan(Cast(Literal("123"), IntegerType), Literal(1))) ruleTest(rule, LessThan(Literal(true), Literal("123")), LessThan(Literal(true), Cast(Literal("123"), BooleanType))) ruleTest(rule, EqualTo(Literal(Array(1, 2)), Literal("123")), EqualTo(Literal(Array(1, 2)), Literal("123"))) ruleTest(rule, GreaterThan(Literal("1.5"), Literal(BigDecimal("0.5"))), GreaterThan(Cast(Literal("1.5"), DoubleType), Cast(Literal(BigDecimal("0.5")), DoubleType))) Seq(true, false).foreach { convertToTS => withSQLConf("spark.sql.hive.compareDateTimestampInTimestamp" -> convertToTS.toString) { val date0301 = Literal(java.sql.Date.valueOf("2017-03-01")) val timestamp0301000000 = Literal(Timestamp.valueOf("2017-03-01 00:00:00")) val timestamp0301000001 = Literal(Timestamp.valueOf("2017-03-01 00:00:01")) if (convertToTS) { // `Date` should be treated as timestamp at 00:00:00 See SPARK-23549 ruleTest(rule, EqualTo(date0301, timestamp0301000000), EqualTo(Cast(date0301, TimestampType), timestamp0301000000)) ruleTest(rule, LessThan(date0301, timestamp0301000001), LessThan(Cast(date0301, TimestampType), timestamp0301000001)) } else { ruleTest(rule, LessThan(date0301, timestamp0301000000), LessThan(Cast(date0301, StringType), Cast(timestamp0301000000, StringType))) ruleTest(rule, LessThan(date0301, timestamp0301000001), LessThan(Cast(date0301, StringType), Cast(timestamp0301000001, StringType))) } } } } ```
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org