Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spark] Fix DELETE failing with AnalysisException on tables with CHAR(N) columns #4003

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Loading