Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
update some codes
  • Loading branch information
彭灿00244106 committed Dec 4, 2018
commit ac2b0048f13acbce8f9b82f2b1c5f5cd268c63d4
Original file line number Diff line number Diff line change
Expand Up @@ -377,41 +377,41 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
}
}

test("CTAS a managed table with the existing empty directory") {
val tableLoc = new File(spark.sessionState.catalog.defaultTablePath(TableIdentifier("tab1")))
private def withEmptyDirInTablePath(dirName: String)(f : File => Unit): Unit = {
val tableLoc =
new File(spark.sessionState.catalog.defaultTablePath(TableIdentifier(dirName)))
try {
tableLoc.mkdir()
f(tableLoc)
} finally {
waitForTasksToFinish()
Utils.deleteRecursively(tableLoc)
}
}


test("CTAS a managed table with the existing empty directory") {
withEmptyDirInTablePath("tab1") { tableLoc =>
withTable("tab1") {
sql(s"CREATE TABLE tab1 USING ${dataSource} AS SELECT 1, 'a'")
checkAnswer(spark.table("tab1"), Row(1, "a"))
}
} finally {
waitForTasksToFinish()
Utils.deleteRecursively(tableLoc)
}
}

test("create a managed table with the existing empty directory") {
val tableLoc = new File(spark.sessionState.catalog.defaultTablePath(TableIdentifier("tab1")))
try {
tableLoc.mkdir()
withEmptyDirInTablePath("tab1") { tableLoc =>
withTable("tab1") {
sql(s"CREATE TABLE tab1 (col1 int, col2 string) USING ${dataSource}")
sql("INSERT INTO tab1 VALUES (1, 'a')")
checkAnswer(spark.table("tab1"), Row(1, "a"))
}
} finally {
waitForTasksToFinish()
Utils.deleteRecursively(tableLoc)
}
}

test("create a managed table with the existing non-empty directory") {
withTable("tab1") {
val tableLoc = new File(spark.sessionState.catalog.defaultTablePath(TableIdentifier("tab1")))
try {
// create an empty hidden file
tableLoc.mkdir()
withEmptyDirInTablePath("tab1") { tableLoc =>
val hiddenGarbageFile = new File(tableLoc.getCanonicalPath, ".garbage")
hiddenGarbageFile.createNewFile()
val exMsg = "Can not create the managed table('`tab1`'). The associated location"
Expand Down Expand Up @@ -439,28 +439,20 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
}.getMessage
assert(ex.contains(exMsgWithDefaultDB))
}
} finally {
waitForTasksToFinish()
Utils.deleteRecursively(tableLoc)
}
}
}

test("rename a managed table with existing empty directory") {
val tableLoc = new File(spark.sessionState.catalog.defaultTablePath(TableIdentifier("tab2")))
try {
withEmptyDirInTablePath("tab2") { tableLoc =>
withTable("tab1") {
sql(s"CREATE TABLE tab1 USING $dataSource AS SELECT 1, 'a'")
tableLoc.mkdir()
val ex = intercept[AnalysisException] {
sql("ALTER TABLE tab1 RENAME TO tab2")
}.getMessage
val expectedMsg = "Can not rename the managed table('`tab1`'). The associated location"
assert(ex.contains(expectedMsg))
}
} finally {
waitForTasksToFinish()
Utils.deleteRecursively(tableLoc)
}
}

Expand Down