|
18 | 18 | package org.apache.spark.sql.hive |
19 | 19 |
|
20 | 20 | import java.io.File |
| 21 | +import java.sql.Timestamp |
21 | 22 |
|
22 | 23 | import com.google.common.io.Files |
23 | 24 | import org.apache.hadoop.fs.FileSystem |
@@ -71,22 +72,27 @@ class QueryPartitionSuite extends QueryTest with SQLTestUtils with TestHiveSingl |
71 | 72 |
|
72 | 73 | test("SPARK-21739: Cast expression should initialize timezoneId " + |
73 | 74 | "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 | + } |
90 | 96 | } |
91 | 97 |
|
92 | 98 | } |
0 commit comments