|
18 | 18 | package org.apache.spark.sql.hive |
19 | 19 |
|
20 | 20 | import com.google.common.io.Files |
| 21 | +import org.apache.spark.sql.test.SQLTestUtils |
21 | 22 |
|
22 | 23 | import org.apache.spark.sql.{QueryTest, _} |
23 | 24 | import org.apache.spark.util.Utils |
24 | 25 |
|
25 | 26 |
|
26 | | -class QueryPartitionSuite extends QueryTest { |
| 27 | +class QueryPartitionSuite extends QueryTest with SQLTestUtils { |
27 | 28 |
|
28 | 29 | private lazy val ctx = org.apache.spark.sql.hive.test.TestHive |
29 | 30 | import ctx.implicits._ |
30 | | - import ctx.sql |
| 31 | + |
| 32 | + protected def _sqlContext = ctx |
31 | 33 |
|
32 | 34 | test("SPARK-5068: query data when path doesn't exist"){ |
33 | | - val testData = ctx.sparkContext.parallelize( |
34 | | - (1 to 10).map(i => TestData(i, i.toString))).toDF() |
35 | | - testData.registerTempTable("testData") |
| 35 | + withSQLConf((SQLConf.HIVE_VERIFY_PARTITION_PATH.key, "true")) { |
| 36 | + val testData = ctx.sparkContext.parallelize( |
| 37 | + (1 to 10).map(i => TestData(i, i.toString))).toDF() |
| 38 | + testData.registerTempTable("testData") |
36 | 39 |
|
37 | | - val tmpDir = Files.createTempDir() |
38 | | - // create the table for test |
39 | | - sql(s"CREATE TABLE table_with_partition(key int,value string) " + |
40 | | - s"PARTITIONED by (ds string) location '${tmpDir.toURI.toString}' ") |
41 | | - sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='1') " + |
42 | | - "SELECT key,value FROM testData") |
43 | | - sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='2') " + |
44 | | - "SELECT key,value FROM testData") |
45 | | - sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='3') " + |
46 | | - "SELECT key,value FROM testData") |
47 | | - sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='4') " + |
48 | | - "SELECT key,value FROM testData") |
| 40 | + val tmpDir = Files.createTempDir() |
| 41 | + // create the table for test |
| 42 | + sql(s"CREATE TABLE table_with_partition(key int,value string) " + |
| 43 | + s"PARTITIONED by (ds string) location '${tmpDir.toURI.toString}' ") |
| 44 | + sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='1') " + |
| 45 | + "SELECT key,value FROM testData") |
| 46 | + sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='2') " + |
| 47 | + "SELECT key,value FROM testData") |
| 48 | + sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='3') " + |
| 49 | + "SELECT key,value FROM testData") |
| 50 | + sql("INSERT OVERWRITE TABLE table_with_partition partition (ds='4') " + |
| 51 | + "SELECT key,value FROM testData") |
49 | 52 |
|
50 | | - // test for the exist path |
51 | | - checkAnswer(sql("select key,value from table_with_partition"), |
52 | | - testData.toDF.collect ++ testData.toDF.collect |
53 | | - ++ testData.toDF.collect ++ testData.toDF.collect) |
| 53 | + // test for the exist path |
| 54 | + checkAnswer(sql("select key,value from table_with_partition"), |
| 55 | + testData.toDF.collect ++ testData.toDF.collect |
| 56 | + ++ testData.toDF.collect ++ testData.toDF.collect) |
54 | 57 |
|
55 | | - // delete the path of one partition |
56 | | - tmpDir.listFiles |
57 | | - .find { f => f.isDirectory && f.getName().startsWith("ds=") } |
58 | | - .foreach { f => Utils.deleteRecursively(f) } |
| 58 | + // delete the path of one partition |
| 59 | + tmpDir.listFiles |
| 60 | + .find { f => f.isDirectory && f.getName().startsWith("ds=") } |
| 61 | + .foreach { f => Utils.deleteRecursively(f) } |
59 | 62 |
|
60 | | - // test for after delete the path |
61 | | - checkAnswer(sql("select key,value from table_with_partition"), |
62 | | - testData.toDF.collect ++ testData.toDF.collect ++ testData.toDF.collect) |
| 63 | + // test for after delete the path |
| 64 | + checkAnswer(sql("select key,value from table_with_partition"), |
| 65 | + testData.toDF.collect ++ testData.toDF.collect ++ testData.toDF.collect) |
63 | 66 |
|
64 | | - sql("DROP TABLE table_with_partition") |
65 | | - sql("DROP TABLE createAndInsertTest") |
| 67 | + sql("DROP TABLE table_with_partition") |
| 68 | + sql("DROP TABLE createAndInsertTest") |
| 69 | + } |
66 | 70 | } |
67 | 71 | } |
0 commit comments