This is an automated email from the ASF dual-hosted git repository.
biyan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 1a72f504eef [HUDI-5563] Check table exist before drop table (#7679)
1a72f504eef is described below
commit 1a72f504eef1faacc70a1ecd2045a832db296387
Author: Zouxxyy <[email protected]>
AuthorDate: Tue Jan 31 09:43:43 2023 +0800
[HUDI-5563] Check table exist before drop table (#7679)
---
.../org/apache/spark/sql/hudi/analysis/HoodieAnalysis.scala | 3 ++-
.../test/scala/org/apache/spark/sql/hudi/TestDropTable.scala | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git
a/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieAnalysis.scala
b/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieAnalysis.scala
index 21194eaaeeb..4875892b0ef 100644
---
a/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieAnalysis.scala
+++
b/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieAnalysis.scala
@@ -617,7 +617,8 @@ case class HoodiePostAnalysisRule(sparkSession:
SparkSession) extends Rule[Logic
CreateHoodieTableCommand(table, ignoreIfExists)
// Rewrite the DropTableCommand to DropHoodieTableCommand
case DropTableCommand(tableName, ifExists, false, purge)
- if sparkAdapter.isHoodieTable(tableName, sparkSession) =>
+ if sparkSession.sessionState.catalog.tableExists(tableName)
+ && sparkAdapter.isHoodieTable(tableName, sparkSession) =>
DropHoodieTableCommand(tableName, ifExists, false, purge)
// Rewrite the AlterTableDropPartitionCommand to
AlterHoodieTableDropPartitionCommand
case AlterTableDropPartitionCommand(tableName, specs, ifExists, purge,
retainData)
diff --git
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestDropTable.scala
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestDropTable.scala
index 4470712e020..b86241eaca9 100644
---
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestDropTable.scala
+++
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestDropTable.scala
@@ -19,6 +19,7 @@ package org.apache.spark.sql.hudi
import org.apache.hadoop.fs.{LocalFileSystem, Path}
import org.apache.hudi.common.fs.FSUtils
+import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.catalog.SessionCatalog
@@ -51,6 +52,16 @@ class TestDropTable extends HoodieSparkSqlTestBase {
}
}
+ test("Test Drop Table with non existent table") {
+ // drop table if exists
+ spark.sql("drop table if exists non_existent_table")
+
+ // drop table
+ assertThrows[AnalysisException]{
+ spark.sql("drop table non_existent_table")
+ }
+ }
+
test("Test Drop Table with purge") {
withTempDir { tmp =>
Seq("cow", "mor").foreach { tableType =>