Skip to content

Commit 5ec7dd6

Browse files
committed
[SPARK-19329][SQL]insert data to a not exist location datasource table should success
1 parent 0c589e3 commit 5ec7dd6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class FindDataSourceTable(sparkSession: SparkSession) extends Rule[LogicalPlan]
240240
// TODO: improve `InMemoryCatalog` and remove this limitation.
241241
catalogTable = if (withHiveSupport) Some(table) else None)
242242

243-
LogicalRelation(dataSource.resolveRelation(), catalogTable = Some(table))
243+
LogicalRelation(dataSource.resolveRelation(false), catalogTable = Some(table))
244244
}
245245
})
246246
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,4 +1431,27 @@ class HiveDDLSuite
14311431
}
14321432
}
14331433
}
1434+
1435+
test("insert data to a table which has altered the table location " +
1436+
"to a not exist location should success") {
1437+
withTable("t", "t1") {
1438+
withTempDir { dir =>
1439+
spark.sql(
1440+
s"""create table t(a string, b int)
1441+
|using parquet
1442+
|options(path "${dir.getAbsolutePath}")
1443+
""".stripMargin)
1444+
var table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
1445+
assert(table.location == dir.getAbsolutePath)
1446+
1447+
var newDir = dir.getAbsolutePath.stripSuffix("/") + "/x"
1448+
spark.sql(s"alter table t set location '$newDir'")
1449+
table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
1450+
assert(table.location == newDir)
1451+
1452+
spark.sql("insert into table t select 'c', 1")
1453+
checkAnswer(spark.table("t"), Row("c", 1) :: Nil)
1454+
}
1455+
}
1456+
}
14341457
}

0 commit comments

Comments
 (0)