Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ case class PreprocessTableCreation(sparkSession: SparkSession) extends Rule[Logi
s"`${existingProvider.getSimpleName}`. It doesn't match the specified format " +
s"`${specifiedProvider.getSimpleName}`.")
}
tableDesc.storage.locationUri match {
case Some(location) if location.getPath != existingTable.location.getPath =>
throw new AnalysisException(
s"The location of the existing table ${tableIdentWithDB.quotedString} is " +
s"`${existingTable.location}`. It doesn't match the specified location " +
s"`${tableDesc.location}`.")
case _ =>
}

if (query.schema.length != existingTable.schema.length) {
throw new AnalysisException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,35 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
}
}

test("create table - append to a non-partitioned table created with different paths") {
import testImplicits._
withTempDir { dir1 =>
withTempDir { dir2 =>
withTable("path_test") {
Seq(1L -> "a").toDF("v1", "v2")
.write
.mode(SaveMode.Append)
.format("json")
.option("path", dir1.getCanonicalPath)
.saveAsTable("path_test")

val ex = intercept[AnalysisException] {
Seq((3L, "c")).toDF("v1", "v2")
.write
.mode(SaveMode.Append)
.format("json")
.option("path", dir2.getCanonicalPath)
.saveAsTable("path_test")
}.getMessage
assert(ex.contains("The location of the existing table `default`.`path_test`"))

checkAnswer(
spark.table("path_test"), Row(1L, "a") :: Nil)
}
}
}
}

test("Refresh table after changing the data source table partitioning") {
import testImplicits._

Expand Down