From 1234f666283172b28d5f17904fc3f2f5065a21ca Mon Sep 17 00:00:00 2001 From: Daoyuan Wang Date: Fri, 19 Sep 2014 18:11:49 +0800 Subject: [PATCH 1/2] fix timestamp smaller than 0 and cast int as timestamp --- .../spark/sql/catalyst/expressions/Cast.scala | 17 +++++++------ .../ExpressionEvaluationSuite.scala | 16 ++++++++----- ...cast #1-0-3299f83638ee811f7c067b0e6dd485a1 | 1 + ...cast #2-0-744369f4f8a402efd04ef015b9e0b280 | 1 + ...cast #3-0-29ba823920a2d2fcf828fb13640658ae | 1 + ...cast #4-0-c5682ff8cb55ee086be8e71086a719ea | 1 + ... cast #5-0-99ad33e07a97eeeb783e35aa68e2563 | 1 + ...cast #6-0-971232467af2235406c942fbf1328e1d | 1 + ...cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd | 1 + ...cast #8-0-bf456c66fb02f4176c0614ce70ef3262 | 1 + .../sql/hive/execution/HiveQuerySuite.scala | 24 +++++++++++++++++++ 11 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #3-0-29ba823920a2d2fcf828fb13640658ae create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #4-0-c5682ff8cb55ee086be8e71086a719ea create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #8-0-bf456c66fb02f4176c0614ce70ef3262 diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala index 0ad2b30cf9c1f..8045c81b6f1a6 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala @@ -86,15 +86,15 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression { try Timestamp.valueOf(n) catch { case _: java.lang.IllegalArgumentException => null } }) case BooleanType => - buildCast[Boolean](_, b => new Timestamp((if (b) 1 else 0) * 1000)) + buildCast[Boolean](_, b => new Timestamp((if (b) 1 else 0))) case LongType => - buildCast[Long](_, l => new Timestamp(l * 1000)) + buildCast[Long](_, l => new Timestamp(l)) case IntegerType => - buildCast[Int](_, i => new Timestamp(i * 1000)) + buildCast[Int](_, i => new Timestamp(i)) case ShortType => - buildCast[Short](_, s => new Timestamp(s * 1000)) + buildCast[Short](_, s => new Timestamp(s)) case ByteType => - buildCast[Byte](_, b => new Timestamp(b * 1000)) + buildCast[Byte](_, b => new Timestamp(b)) // TimestampWritable.decimalToTimestamp case DecimalType => buildCast[BigDecimal](_, d => decimalToTimestamp(d)) @@ -107,11 +107,10 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression { } private[this] def decimalToTimestamp(d: BigDecimal) = { - val seconds = d.longValue() + val seconds = Math.floor(d.toDouble).toLong val bd = (d - seconds) * 1000000000 val nanos = bd.intValue() - // Convert to millis val millis = seconds * 1000 val t = new Timestamp(millis) @@ -121,11 +120,11 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression { } // Timestamp to long, converting milliseconds to seconds - private[this] def timestampToLong(ts: Timestamp) = ts.getTime / 1000 + private[this] def timestampToLong(ts: Timestamp) = Math.floor(ts.getTime / 1000.0).toLong private[this] def timestampToDouble(ts: Timestamp) = { // First part is the seconds since the beginning of time, followed by nanosecs. - ts.getTime / 1000 + ts.getNanos.toDouble / 1000000000 + Math.floor(ts.getTime / 1000.0).toLong + ts.getNanos.toDouble / 1000000000 } // Converts Timestamp to string according to Hive TimestampWritable convention diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala index b961346dfc995..8b6721d5d8125 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala @@ -231,7 +231,9 @@ class ExpressionEvaluationSuite extends FunSuite { checkEvaluation("12.65" cast DecimalType, BigDecimal(12.65)) checkEvaluation(Literal(1) cast LongType, 1) - checkEvaluation(Cast(Literal(1) cast TimestampType, LongType), 1) + checkEvaluation(Cast(Literal(1000) cast TimestampType, LongType), 1.toLong) + checkEvaluation(Cast(Literal(-1200) cast TimestampType, LongType), -2.toLong) + checkEvaluation(Cast(Literal(1.toDouble) cast TimestampType, DoubleType), 1.toDouble) checkEvaluation(Cast(Literal(1.toDouble) cast TimestampType, DoubleType), 1.toDouble) checkEvaluation(Cast(Literal(sts) cast TimestampType, StringType), sts) @@ -242,11 +244,11 @@ class ExpressionEvaluationSuite extends FunSuite { checkEvaluation(Cast(Cast(Cast(Cast( Cast("5" cast ByteType, ShortType), IntegerType), FloatType), DoubleType), LongType), 5) checkEvaluation(Cast(Cast(Cast(Cast( - Cast("5" cast ByteType, TimestampType), DecimalType), LongType), StringType), ShortType), 5) + Cast("5" cast ByteType, TimestampType), DecimalType), LongType), StringType), ShortType), 0) checkEvaluation(Cast(Cast(Cast(Cast( Cast("5" cast TimestampType, ByteType), DecimalType), LongType), StringType), ShortType), null) checkEvaluation(Cast(Cast(Cast(Cast( - Cast("5" cast DecimalType, ByteType), TimestampType), LongType), StringType), ShortType), 5) + Cast("5" cast DecimalType, ByteType), TimestampType), LongType), StringType), ShortType), 0) checkEvaluation(Literal(true) cast IntegerType, 1) checkEvaluation(Literal(false) cast IntegerType, 0) checkEvaluation(Cast(Literal(1) cast BooleanType, IntegerType), 1) @@ -293,16 +295,18 @@ class ExpressionEvaluationSuite extends FunSuite { test("timestamp casting") { val millis = 15 * 1000 + 2 + val seconds = millis * 1000 + 2 val ts = new Timestamp(millis) val ts1 = new Timestamp(15 * 1000) // a timestamp without the milliseconds part + val tss = new Timestamp(seconds) checkEvaluation(Cast(ts, ShortType), 15) checkEvaluation(Cast(ts, IntegerType), 15) checkEvaluation(Cast(ts, LongType), 15) checkEvaluation(Cast(ts, FloatType), 15.002f) checkEvaluation(Cast(ts, DoubleType), 15.002) - checkEvaluation(Cast(Cast(ts, ShortType), TimestampType), ts1) - checkEvaluation(Cast(Cast(ts, IntegerType), TimestampType), ts1) - checkEvaluation(Cast(Cast(ts, LongType), TimestampType), ts1) + checkEvaluation(Cast(Cast(tss, ShortType), TimestampType), ts) + checkEvaluation(Cast(Cast(tss, IntegerType), TimestampType), ts) + checkEvaluation(Cast(Cast(tss, LongType), TimestampType), ts) checkEvaluation(Cast(Cast(millis.toFloat / 1000, TimestampType), FloatType), millis.toFloat / 1000) checkEvaluation(Cast(Cast(millis.toDouble / 1000, TimestampType), DoubleType), diff --git a/sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 b/sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 new file mode 100644 index 0000000000000..fb63d26b0f299 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 @@ -0,0 +1 @@ +1970-01-01 08:00:00.001 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 b/sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 new file mode 100644 index 0000000000000..70027c6c7da52 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 @@ -0,0 +1 @@ +1970-01-01 08:00:01.2 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #3-0-29ba823920a2d2fcf828fb13640658ae b/sql/hive/src/test/resources/golden/timestamp cast #3-0-29ba823920a2d2fcf828fb13640658ae new file mode 100644 index 0000000000000..d00491fd7e5bb --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #3-0-29ba823920a2d2fcf828fb13640658ae @@ -0,0 +1 @@ +1 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #4-0-c5682ff8cb55ee086be8e71086a719ea b/sql/hive/src/test/resources/golden/timestamp cast #4-0-c5682ff8cb55ee086be8e71086a719ea new file mode 100644 index 0000000000000..5625e59da8873 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #4-0-c5682ff8cb55ee086be8e71086a719ea @@ -0,0 +1 @@ +1.2 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 b/sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 new file mode 100644 index 0000000000000..a7545df2f1eea --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 @@ -0,0 +1 @@ +1970-01-01 07:59:59.999 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d b/sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d new file mode 100644 index 0000000000000..2d481cd778ca5 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d @@ -0,0 +1 @@ +1970-01-01 07:59:58.8 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd b/sql/hive/src/test/resources/golden/timestamp cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd new file mode 100644 index 0000000000000..3fbedf693b51d --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd @@ -0,0 +1 @@ +-2 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #8-0-bf456c66fb02f4176c0614ce70ef3262 b/sql/hive/src/test/resources/golden/timestamp cast #8-0-bf456c66fb02f4176c0614ce70ef3262 new file mode 100644 index 0000000000000..1d94c8a014fb4 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #8-0-bf456c66fb02f4176c0614ce70ef3262 @@ -0,0 +1 @@ +-1.2 diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala index 8c8a8b124ac69..a86f531ffa0fa 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala @@ -294,6 +294,30 @@ class HiveQuerySuite extends HiveComparisonTest { createQueryTest("case statements WITHOUT key #4", "SELECT (CASE WHEN key > 2 THEN 3 WHEN 2 > key THEN 2 ELSE 0 END) FROM src WHERE key < 15") + createQueryTest("timestamp cast #1", + "SELECT CAST(CAST(1 as TIMESTAMP) as STRING) FROM src LIMIT 1") + + createQueryTest("timestamp cast #2", + "SELECT CAST(CAST(1.2 as TIMESTAMP) as STRING) FROM src LIMIT 1") + + createQueryTest("timestamp cast #3", + "SELECT CAST(CAST(1200 as TIMESTAMP) as INT) FROM src LIMIT 1") + + createQueryTest("timestamp cast #4", + "SELECT CAST(CAST(1.2 as TIMESTAMP) as DOUBLE) FROM src LIMIT 1") + + createQueryTest("timestamp cast #5", + "SELECT CAST(CAST(-1 as TIMESTAMP) as STRING) FROM src LIMIT 1") + + createQueryTest("timestamp cast #6", + "SELECT CAST(CAST(-1.2 as TIMESTAMP) as STRING) FROM src LIMIT 1") + + createQueryTest("timestamp cast #7", + "SELECT CAST(CAST(-1200 as TIMESTAMP) as INT) FROM src LIMIT 1") + + createQueryTest("timestamp cast #8", + "SELECT CAST(CAST(-1.2 as TIMESTAMP) as DOUBLE) FROM src LIMIT 1") + test("implement identity function using case statement") { val actual = sql("SELECT (CASE key WHEN key THEN key END) FROM src") .map { case Row(i: Int) => i } From 4274b1d10fc48746c850207fc27e5acc8630ddc9 Mon Sep 17 00:00:00 2001 From: Daoyuan Wang Date: Fri, 19 Sep 2014 18:21:41 +0800 Subject: [PATCH 2/2] set test not related to timezone --- ...mp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 | 1 - ...mp cast #1-0-69fc614ccea92bbe39f4decc299edcc6 | 1 + ...p cast #2-0-732ed232ac592c5e7f7c913a88874fd2} | 0 ...mp cast #2-0-744369f4f8a402efd04ef015b9e0b280 | 1 - ...mp cast #3-0-76ee270337f664b36cacfc6528ac109} | 0 ...mp cast #4-0-732ed232ac592c5e7f7c913a88874fd2 | 1 + ...amp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 | 1 - ...mp cast #5-0-dbd7bcd167d322d6617b884c02c7f247 | 1 + ...p cast #6-0-6d2da5cfada03605834e38bc4075bc79} | 0 ...mp cast #6-0-971232467af2235406c942fbf1328e1d | 1 - ...p cast #7-0-1d70654217035f8ce5f64344f4c5a80f} | 0 ...mp cast #8-0-6d2da5cfada03605834e38bc4075bc79 | 1 + .../sql/hive/execution/HiveQuerySuite.scala | 16 ++++++++-------- 13 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #1-0-69fc614ccea92bbe39f4decc299edcc6 rename sql/hive/src/test/resources/golden/{timestamp cast #4-0-c5682ff8cb55ee086be8e71086a719ea => timestamp cast #2-0-732ed232ac592c5e7f7c913a88874fd2} (100%) delete mode 100644 sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 rename sql/hive/src/test/resources/golden/{timestamp cast #3-0-29ba823920a2d2fcf828fb13640658ae => timestamp cast #3-0-76ee270337f664b36cacfc6528ac109} (100%) create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #4-0-732ed232ac592c5e7f7c913a88874fd2 delete mode 100644 sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #5-0-dbd7bcd167d322d6617b884c02c7f247 rename sql/hive/src/test/resources/golden/{timestamp cast #8-0-bf456c66fb02f4176c0614ce70ef3262 => timestamp cast #6-0-6d2da5cfada03605834e38bc4075bc79} (100%) delete mode 100644 sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d rename sql/hive/src/test/resources/golden/{timestamp cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd => timestamp cast #7-0-1d70654217035f8ce5f64344f4c5a80f} (100%) create mode 100644 sql/hive/src/test/resources/golden/timestamp cast #8-0-6d2da5cfada03605834e38bc4075bc79 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 b/sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 deleted file mode 100644 index fb63d26b0f299..0000000000000 --- a/sql/hive/src/test/resources/golden/timestamp cast #1-0-3299f83638ee811f7c067b0e6dd485a1 +++ /dev/null @@ -1 +0,0 @@ -1970-01-01 08:00:00.001 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #1-0-69fc614ccea92bbe39f4decc299edcc6 b/sql/hive/src/test/resources/golden/timestamp cast #1-0-69fc614ccea92bbe39f4decc299edcc6 new file mode 100644 index 0000000000000..8ebf695ba7d20 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #1-0-69fc614ccea92bbe39f4decc299edcc6 @@ -0,0 +1 @@ +0.001 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #4-0-c5682ff8cb55ee086be8e71086a719ea b/sql/hive/src/test/resources/golden/timestamp cast #2-0-732ed232ac592c5e7f7c913a88874fd2 similarity index 100% rename from sql/hive/src/test/resources/golden/timestamp cast #4-0-c5682ff8cb55ee086be8e71086a719ea rename to sql/hive/src/test/resources/golden/timestamp cast #2-0-732ed232ac592c5e7f7c913a88874fd2 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 b/sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 deleted file mode 100644 index 70027c6c7da52..0000000000000 --- a/sql/hive/src/test/resources/golden/timestamp cast #2-0-744369f4f8a402efd04ef015b9e0b280 +++ /dev/null @@ -1 +0,0 @@ -1970-01-01 08:00:01.2 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #3-0-29ba823920a2d2fcf828fb13640658ae b/sql/hive/src/test/resources/golden/timestamp cast #3-0-76ee270337f664b36cacfc6528ac109 similarity index 100% rename from sql/hive/src/test/resources/golden/timestamp cast #3-0-29ba823920a2d2fcf828fb13640658ae rename to sql/hive/src/test/resources/golden/timestamp cast #3-0-76ee270337f664b36cacfc6528ac109 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #4-0-732ed232ac592c5e7f7c913a88874fd2 b/sql/hive/src/test/resources/golden/timestamp cast #4-0-732ed232ac592c5e7f7c913a88874fd2 new file mode 100644 index 0000000000000..5625e59da8873 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #4-0-732ed232ac592c5e7f7c913a88874fd2 @@ -0,0 +1 @@ +1.2 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 b/sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 deleted file mode 100644 index a7545df2f1eea..0000000000000 --- a/sql/hive/src/test/resources/golden/timestamp cast #5-0-99ad33e07a97eeeb783e35aa68e2563 +++ /dev/null @@ -1 +0,0 @@ -1970-01-01 07:59:59.999 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #5-0-dbd7bcd167d322d6617b884c02c7f247 b/sql/hive/src/test/resources/golden/timestamp cast #5-0-dbd7bcd167d322d6617b884c02c7f247 new file mode 100644 index 0000000000000..27de46fdf22ac --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #5-0-dbd7bcd167d322d6617b884c02c7f247 @@ -0,0 +1 @@ +-0.0010000000000000009 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #8-0-bf456c66fb02f4176c0614ce70ef3262 b/sql/hive/src/test/resources/golden/timestamp cast #6-0-6d2da5cfada03605834e38bc4075bc79 similarity index 100% rename from sql/hive/src/test/resources/golden/timestamp cast #8-0-bf456c66fb02f4176c0614ce70ef3262 rename to sql/hive/src/test/resources/golden/timestamp cast #6-0-6d2da5cfada03605834e38bc4075bc79 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d b/sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d deleted file mode 100644 index 2d481cd778ca5..0000000000000 --- a/sql/hive/src/test/resources/golden/timestamp cast #6-0-971232467af2235406c942fbf1328e1d +++ /dev/null @@ -1 +0,0 @@ -1970-01-01 07:59:58.8 diff --git a/sql/hive/src/test/resources/golden/timestamp cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd b/sql/hive/src/test/resources/golden/timestamp cast #7-0-1d70654217035f8ce5f64344f4c5a80f similarity index 100% rename from sql/hive/src/test/resources/golden/timestamp cast #7-0-4f42664b3e2a7e75c6fcdd3667fd86cd rename to sql/hive/src/test/resources/golden/timestamp cast #7-0-1d70654217035f8ce5f64344f4c5a80f diff --git a/sql/hive/src/test/resources/golden/timestamp cast #8-0-6d2da5cfada03605834e38bc4075bc79 b/sql/hive/src/test/resources/golden/timestamp cast #8-0-6d2da5cfada03605834e38bc4075bc79 new file mode 100644 index 0000000000000..1d94c8a014fb4 --- /dev/null +++ b/sql/hive/src/test/resources/golden/timestamp cast #8-0-6d2da5cfada03605834e38bc4075bc79 @@ -0,0 +1 @@ +-1.2 diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala index a86f531ffa0fa..1efdf29033d8e 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala @@ -295,28 +295,28 @@ class HiveQuerySuite extends HiveComparisonTest { "SELECT (CASE WHEN key > 2 THEN 3 WHEN 2 > key THEN 2 ELSE 0 END) FROM src WHERE key < 15") createQueryTest("timestamp cast #1", - "SELECT CAST(CAST(1 as TIMESTAMP) as STRING) FROM src LIMIT 1") + "SELECT CAST(CAST(1 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1") createQueryTest("timestamp cast #2", - "SELECT CAST(CAST(1.2 as TIMESTAMP) as STRING) FROM src LIMIT 1") + "SELECT CAST(CAST(1.2 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1") createQueryTest("timestamp cast #3", - "SELECT CAST(CAST(1200 as TIMESTAMP) as INT) FROM src LIMIT 1") + "SELECT CAST(CAST(1200 AS TIMESTAMP) AS INT) FROM src LIMIT 1") createQueryTest("timestamp cast #4", - "SELECT CAST(CAST(1.2 as TIMESTAMP) as DOUBLE) FROM src LIMIT 1") + "SELECT CAST(CAST(1.2 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1") createQueryTest("timestamp cast #5", - "SELECT CAST(CAST(-1 as TIMESTAMP) as STRING) FROM src LIMIT 1") + "SELECT CAST(CAST(-1 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1") createQueryTest("timestamp cast #6", - "SELECT CAST(CAST(-1.2 as TIMESTAMP) as STRING) FROM src LIMIT 1") + "SELECT CAST(CAST(-1.2 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1") createQueryTest("timestamp cast #7", - "SELECT CAST(CAST(-1200 as TIMESTAMP) as INT) FROM src LIMIT 1") + "SELECT CAST(CAST(-1200 AS TIMESTAMP) AS INT) FROM src LIMIT 1") createQueryTest("timestamp cast #8", - "SELECT CAST(CAST(-1.2 as TIMESTAMP) as DOUBLE) FROM src LIMIT 1") + "SELECT CAST(CAST(-1.2 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1") test("implement identity function using case statement") { val actual = sql("SELECT (CASE key WHEN key THEN key END) FROM src")