From bcede61c434ad970c5eacb423afcdb17761f077c Mon Sep 17 00:00:00 2001 From: Chungmin Lee Date: Fri, 27 Dec 2024 01:16:00 +0000 Subject: [PATCH 1/2] test --- .../spark/sql/delta/DeleteSuiteBase.scala | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spark/src/test/scala/org/apache/spark/sql/delta/DeleteSuiteBase.scala b/spark/src/test/scala/org/apache/spark/sql/delta/DeleteSuiteBase.scala index f64e5799f8b..d0af737cdca 100644 --- a/spark/src/test/scala/org/apache/spark/sql/delta/DeleteSuiteBase.scala +++ b/spark/src/test/scala/org/apache/spark/sql/delta/DeleteSuiteBase.scala @@ -560,4 +560,24 @@ abstract class DeleteSuiteBase extends QueryTest condition = Some(s"value = '$partValue'"), expectedResults = Nil) } + + test("CHAR(N) type should not cause AnalysisException") { + withTable("delta_table") { + sql( + s""" + |CREATE TABLE delta_table(key CHAR(5), value CHAR(5)) + |USING delta + |OPTIONS('path'='$tempPath') + """.stripMargin) + Seq(("foo", "bar"), ("foo", "baa")) + .toDF("key", "value") + .coalesce(1) + .write + .mode("append") + .format("delta") + .saveAsTable("delta_table") + checkDelete(Some("value = 'baa'"), + Row("foo ", "bar ") :: Nil) + } + } } From 5570e970d0236ebc72462b2d27ca58afb8d750cd Mon Sep 17 00:00:00 2001 From: Chungmin Lee Date: Fri, 27 Dec 2024 01:28:23 +0000 Subject: [PATCH 2/2] fix --- .../apache/spark/sql/delta/DeltaAnalysis.scala | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/spark/src/main/scala/org/apache/spark/sql/delta/DeltaAnalysis.scala b/spark/src/main/scala/org/apache/spark/sql/delta/DeltaAnalysis.scala index 012d88a036a..e3182c5c58a 100644 --- a/spark/src/main/scala/org/apache/spark/sql/delta/DeltaAnalysis.scala +++ b/spark/src/main/scala/org/apache/spark/sql/delta/DeltaAnalysis.scala @@ -457,18 +457,12 @@ class DeltaAnalysis(session: SparkSession) case d @ DeleteFromTable(table, condition) if d.childrenResolved => // rewrites Delta from V2 to V1 val newTarget = stripTempViewWrapper(table).transformUp { case DeltaRelation(lr) => lr } - val indices = newTarget.collect { - case DeltaFullTable(_, index) => index - } - if (indices.isEmpty) { - // Not a Delta table at all, do not transform - d - } else if (indices.size == 1 && indices(0).deltaLog.tableExists) { - // It is a well-defined Delta table with a schema - DeltaDelete(newTarget, Some(condition)) - } else { - // Not a well-defined Delta table - throw DeltaErrors.notADeltaSourceException("DELETE", Some(d)) + newTarget.collectLeaves().headOption match { + case Some(DeltaFullTable(_, index)) => + DeltaDelete(newTarget, Some(condition)) + case o => + // Not a Delta table at all, do not transform + d } case u @ UpdateTable(table, assignments, condition) if u.childrenResolved =>