Skip to content

Commit 5a04ddc

Browse files
committed
fix test case queries
1 parent a264e3a commit 5a04ddc

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/QueryPartitionSuite.scala

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.spark.sql.hive
1919

2020
import java.io.File
21+
import java.sql.Timestamp
2122

2223
import com.google.common.io.Files
2324
import org.apache.hadoop.fs.FileSystem
@@ -71,22 +72,27 @@ class QueryPartitionSuite extends QueryTest with SQLTestUtils with TestHiveSingl
7172

7273
test("SPARK-21739: Cast expression should initialize timezoneId " +
7374
"when it is called statically to convert something into TimestampType") {
74-
// create table for test
75-
sql("CREATE TABLE table_with_timestamp_partition(value int) PARTITIONED by (ts timestamp)")
76-
sql("INSERT OVERWRITE TABLE table_with_timestamp_partition " +
77-
"partition (ts = '2010-01-01 00:00:00.000') VALUES (1)")
78-
sql("INSERT OVERWRITE TABLE table_with_timestamp_partition " +
79-
"partition (ts = '2010-01-02 00:00:00.000') VALUES (2)")
80-
81-
// test for Cast expression in TableReader
82-
checkAnswer(sql("select value from table_with_timestamp_partition"),
83-
Seq(Row(1), Row(2)))
84-
85-
// test for Cast expression in HiveTableScanExec
86-
checkAnswer(sql("select value from table_with_timestamp_partition " +
87-
"where ts = '2010-01-02 00:00:00.000'"), Row(2))
88-
89-
sql("DROP TABLE IF EXISTS table_with_timestamp_partition")
75+
withTable("table_with_timestamp_partition") {
76+
// create table for test
77+
sql("CREATE TABLE table_with_timestamp_partition(value int) PARTITIONED by (ts timestamp)")
78+
sql("INSERT OVERWRITE TABLE table_with_timestamp_partition " +
79+
"partition (ts = '2010-01-01 00:00:00.000') VALUES (1)")
80+
sql("INSERT OVERWRITE TABLE table_with_timestamp_partition " +
81+
"partition (ts = '2010-01-02 00:00:00.000') VALUES (2)")
82+
sql("INSERT OVERWRITE TABLE table_with_timestamp_partition " +
83+
"partition (ts = '2010-01-03 00:00:00.000') VALUES (3)")
84+
85+
// test for Cast expression in TableReader
86+
checkAnswer(sql("select * from table_with_timestamp_partition"),
87+
Seq(
88+
Row(1, Timestamp.valueOf("2010-01-01 00:00:00.000")),
89+
Row(2, Timestamp.valueOf("2010-01-02 00:00:00.000")),
90+
Row(3, Timestamp.valueOf("2010-01-03 00:00:00.000"))))
91+
92+
// test for Cast expression in HiveTableScanExec
93+
checkAnswer(sql("select value from table_with_timestamp_partition " +
94+
"where ts = '2010-01-02 00:00:00.000'"), Row(2))
95+
}
9096
}
9197

9298
}

0 commit comments

Comments
 (0)