17
17
18
18
package org .apache .carbondata .spark .testsuite .createTable
19
19
20
- import java .util .concurrent .{Callable , Executors , ExecutorService , Future , TimeUnit }
20
+ import org .apache .spark .sql .catalyst .TableIdentifier
21
+ import org .apache .spark .sql .hive .CarbonRelation
21
22
22
- import org .apache .spark .sql .AnalysisException
23
+ import java .util .concurrent .{Callable , ExecutorService , Executors , Future , TimeUnit }
24
+ import org .apache .spark .sql .{AnalysisException , CarbonEnv }
23
25
import org .apache .spark .sql .test .util .QueryTest
24
26
import org .scalatest .BeforeAndAfterAll
25
27
28
+ import java .io .File
29
+
26
30
class TestCreateTableIfNotExists extends QueryTest with BeforeAndAfterAll {
27
31
28
32
override def beforeAll {
@@ -44,6 +48,25 @@ class TestCreateTableIfNotExists extends QueryTest with BeforeAndAfterAll {
44
48
}
45
49
}
46
50
51
+ test(" test create table with consistent table location" ) {
52
+ val dbName = " testdb"
53
+ val tblName = " testtbl"
54
+ sql(s " drop database if exists $dbName cascade " )
55
+ val dblocation = warehouse + File .separator + dbName
56
+ sql(s " create database $dbName location ' $dblocation' " )
57
+ sql(s " use $dbName" )
58
+ new File (warehouse + File .separator + tblName).mkdir()
59
+ sql(s " create table $tblName(a int, b string) STORED AS carbondata " )
60
+ val tblIdentifier = new TableIdentifier (tblName)
61
+ val carbonTablePath = CarbonEnv .getInstance(sqlContext.sparkSession).carbonMetaStore
62
+ .lookupRelation(tblIdentifier)(sqlContext.sparkSession).carbonTable.getTablePath
63
+
64
+ val sparkTablePath =
65
+ sqlContext.sparkSession.sessionState.catalog
66
+ .getTableMetadata(tblIdentifier).storage.locationUri.get.getPath
67
+ assert(carbonTablePath.equals(sparkTablePath))
68
+ }
69
+
47
70
test(" test create table if not exist concurrently" ) {
48
71
49
72
val executorService : ExecutorService = Executors .newFixedThreadPool(10 )
0 commit comments