File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
catalyst/src/main/scala/org/apache/spark/sql/catalyst
core/src/test/scala/org/apache/spark/sql Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -277,8 +277,16 @@ trait HiveTypeCoercion {
277
277
case a @ BinaryArithmetic (left, right @ StringType ()) =>
278
278
a.makeCopy(Array (left, Cast (right, DoubleType )))
279
279
280
- // We should cast all timestamp/date/string compare into string comparisions
280
+ // For equality between string and timestamp we cast the string to a timestamp
281
+ // so that things like rounding of subsecond precision does not affect the comparison.
282
+ case p @ Equality (left @ StringType (), right @ TimestampType ()) =>
283
+ p.makeCopy(Array (Cast (left, TimestampType ), right))
284
+ case p @ Equality (left @ TimestampType (), right @ StringType ()) =>
285
+ p.makeCopy(Array (left, Cast (right, TimestampType )))
286
+
287
+ // We should cast all relative timestamp/date/string comparison into string comparisions
281
288
// This behaves as a user would expect because timestamp strings sort lexicographically.
289
+ // i.e. TimeStamp(2013-01-01 00:00 ...) < "2014" = true
282
290
case p @ BinaryComparison (left @ StringType (), right @ DateType ()) =>
283
291
p.makeCopy(Array (left, Cast (right, StringType )))
284
292
case p @ BinaryComparison (left @ DateType (), right @ StringType ()) =>
Original file line number Diff line number Diff line change @@ -266,6 +266,15 @@ private[sql] object BinaryComparison {
266
266
def unapply (e : BinaryComparison ): Option [(Expression , Expression )] = Some ((e.left, e.right))
267
267
}
268
268
269
+ /** An extractor that matches both standard 3VL equality and null-safe equality. */
270
+ private [sql] object Equality {
271
+ def unapply (e : BinaryComparison ): Option [(Expression , Expression )] = e match {
272
+ case EqualTo (l, r) => Some ((l, r))
273
+ case EqualNullSafe (l, r) => Some ((l, r))
274
+ case _ => None
275
+ }
276
+ }
277
+
269
278
case class EqualTo (left : Expression , right : Expression ) extends BinaryComparison {
270
279
override def symbol : String = " ="
271
280
Original file line number Diff line number Diff line change @@ -350,7 +350,7 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll with SQLTestUtils {
350
350
(0 to 3 ).map(i => Tuple1 (new Timestamp (i))).toDF(" time" ).registerTempTable(" timestamps" )
351
351
352
352
checkAnswer(sql(
353
- " SELECT time FROM timestamps WHERE time='1969-12-31 16:00:00'" ),
353
+ " SELECT time FROM timestamps WHERE time='1969-12-31 16:00:00.0 '" ),
354
354
Row (java.sql.Timestamp .valueOf(" 1969-12-31 16:00:00" )))
355
355
356
356
checkAnswer(sql(
You can’t perform that action at this time.
0 commit comments