Skip to content

Commit 9b81fb7

Browse files
committed
tmp
1 parent 0337c32 commit 9b81fb7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTableIfNotExists.scala

+25-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717

1818
package org.apache.carbondata.spark.testsuite.createTable
1919

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
2122

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}
2325
import org.apache.spark.sql.test.util.QueryTest
2426
import org.scalatest.BeforeAndAfterAll
2527

28+
import java.io.File
29+
2630
class TestCreateTableIfNotExists extends QueryTest with BeforeAndAfterAll {
2731

2832
override def beforeAll {
@@ -44,6 +48,25 @@ class TestCreateTableIfNotExists extends QueryTest with BeforeAndAfterAll {
4448
}
4549
}
4650

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+
4770
test("test create table if not exist concurrently") {
4871

4972
val executorService: ExecutorService = Executors.newFixedThreadPool(10)

0 commit comments

Comments
 (0)