1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ package org .apache .spark .sql .hive
19
+
20
+ import java .io .File
21
+
22
+ import com .google .common .io .Files
23
+ import org .apache .spark .sql .{QueryTest , _ }
24
+ import org .apache .spark .sql .hive .test .TestHive
25
+ import org .apache .spark .util .Utils
26
+ /* Implicits */
27
+ import org .apache .spark .sql .hive .test .TestHive ._
28
+
29
+
30
+
31
+ class QueryPartitionSuite extends QueryTest {
32
+ import org .apache .spark .sql .hive .test .TestHive .implicits ._
33
+
34
+ test(" SPARK-5068: query data when path doesn't exists" ){
35
+ val testData = TestHive .sparkContext.parallelize(
36
+ (1 to 10 ).map(i => TestData (i, i.toString))).toDF()
37
+ testData.registerTempTable(" testData" )
38
+
39
+ val tmpDir = Files .createTempDir()
40
+ // create the table for test
41
+ sql(s " CREATE TABLE table_with_partition(key int,value string) PARTITIONED by (ds string) location ' ${tmpDir.toURI.toString}' " )
42
+ sql(" INSERT OVERWRITE TABLE table_with_partition partition (ds='1') SELECT key,value FROM testData" )
43
+ sql(" INSERT OVERWRITE TABLE table_with_partition partition (ds='2') SELECT key,value FROM testData" )
44
+ sql(" INSERT OVERWRITE TABLE table_with_partition partition (ds='3') SELECT key,value FROM testData" )
45
+ sql(" INSERT OVERWRITE TABLE table_with_partition partition (ds='4') SELECT key,value FROM testData" )
46
+
47
+ // test for the exist path
48
+ checkAnswer(sql(" select key,value from table_with_partition" ),
49
+ testData.toSchemaRDD.collect ++ testData.toSchemaRDD.collect
50
+ ++ testData.toSchemaRDD.collect ++ testData.toSchemaRDD.collect)
51
+
52
+ // delect the path of one partition
53
+ val folders = tmpDir.listFiles.filter(_.isDirectory)
54
+ Utils .deleteRecursively(folders(0 ))
55
+
56
+ // test for affter delete the path
57
+ checkAnswer(sql(" select key,value from table_with_partition" ),
58
+ testData.toSchemaRDD.collect ++ testData.toSchemaRDD.collect
59
+ ++ testData.toSchemaRDD.collect)
60
+
61
+ sql(" DROP TABLE table_with_partition" )
62
+ sql(" DROP TABLE createAndInsertTest" )
63
+ }
64
+ }
0 commit comments