This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 925330449971 [SPARK-61462][SQL] Fix silent under-delete in DELETE-only
MERGE and metadata-only DELETE when CHAR values are stored without padding
925330449971 is described below
commit 925330449971ca5a9e58af8dfcae6a1ccb3c80e7
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Wed Nov 11 20:15:41 2026 -0800
[SPARK-61462][SQL] Fix silent under-delete in DELETE-only MERGE and
metadata-only DELETE when CHAR values are stored without padding
### What changes were proposed in this pull request?
This PR makes `ApplyCharTypePadding` pad the target CHAR columns inside the
conditions of row-level writes:
- The `condition` and `groupFilterCondition` of `ReplaceData` and
`WriteDelta` now replace each target CHAR attribute (the stored one or its
padded alias, including `OuterReference`s) with `readSidePadding(<stored
attribute>)`.
- The sources of the group filter subqueries, which `RewriteMergeIntoTable`
builds from an already resolved source, also get their read-side padding.
- Only aliases that carry the raw CHAR type are treated as padding. A
group-based `UPDATE` also projects `If(cond, ...)` aliases directly on the read
relation, and mapping those broke `UPDATE ... WHERE c IN (...)`.
The padded comparison has no V1 filter form, so `PredicateUtils.toV1` now
returns `None` for an `OR` unless both sides convert. Previously it returned
the one convertible side, which selects fewer rows than the `OR`, and
`SupportsDelete.canDeleteWhere` only checks that no predicate went missing.
`toV1` is also used by `SupportsOverwrite` and `SupportsRuntimeFiltering`,
which now fall back as for any other non-convertible predicate.
Scope: this PR covers `DELETE` and `MERGE` with only `DELETE` actions.
`UPDATE` and `MERGE` with `UPDATE` / `INSERT` actions on data stored without
padding are not changed. `ResolveRowLevelCommandAssignments` strips the CHAR
metadata from their target relation, so the target read is not padded there.
They are fixed by #60359 (SPARK-61479).
Tradeoffs:
- A metadata-only `DELETE ... WHERE dep = 'hr'` on `dep CHAR(8)` now falls
back to a row-level plan instead of being pushed down, because comparing the
stored value with the padded literal silently under-deletes. Connectors that
accept `PartitionPredicate` or `CHAR_READ_SIDE_PADDING` keep the metadata-only
path.
- A row-level `DELETE` or delete-only `MERGE` with a CHAR condition no
longer pushes that predicate to the scan at planning time, unless the connector
accepts `CHAR_READ_SIDE_PADDING`. This applies to padded data too. The runtime
group filter selects the same groups as before, but only when it is enabled
(the default) and the scan supports runtime filtering. Otherwise a group-based
operation rewrites every group the scan returns, and a delta-based one reads
more rows but still writes [...]
### Why are the changes needed?
With `spark.sql.readSideCharPadding` enabled, a DSv2 source that stores
CHAR values without padding is read with padding applied on top of the scan,
but the conditions of `ReplaceData` / `WriteDelta` are not evaluated on top of
that read. They are pushed down to the scan and to metadata-only deletes, and
they select the groups to read at runtime, so they compared the stored
(unpadded) value with the padded literal. As a result, `MERGE` with only
`DELETE` actions and metadata-only `DEL [...]
This is a correctness issue.
The same change also fixes a group-based `DELETE` with a CHAR condition,
which failed with `INTERNAL_ERROR_ATTRIBUTE_NOT_FOUND` when it ran as a
row-level plan with the runtime group filter on (the default), for example
`DELETE ... WHERE c IN ('a', 'z')` on a non-partition `CHAR(3)` column, or a
correlated subquery on a CHAR column.
### Does this PR introduce _any_ user-facing change?
Yes.
- `MERGE INTO ... WHEN MATCHED THEN DELETE` and `DELETE FROM` on a DSv2
table with CHAR columns stored without padding now delete all matching rows
instead of silently deleting only a subset.
- A group-based `DELETE` with a CHAR condition no longer fails with
`INTERNAL_ERROR_ATTRIBUTE_NOT_FOUND`.
- `DELETE` with a CHAR comparison inside an `OR` no longer deletes only the
rows matched by the other side.
- A metadata-only `DELETE` with a CHAR condition may now use a row-level
plan, as described above.
### How was this patch tested?
Added test cases to `DeleteFromTableSuiteBase`, `MergeIntoTableSuiteBase`,
`UpdateTableSuiteBase` and `DataSourceV2EnhancedDeleteFilterSuite`, and updated
`V2PredicateSuite` for the `OR` conversion. Ran the DELETE, UPDATE and MERGE
suites (group-based and delta-based), the runtime filtering suites,
`DataSourceV2EnhancedDeleteFilterSuite`, the `*CharVarcharTestSuite` suites,
`V2PredicateSuite`, `DataSourceV2SQLSuiteV1Filter`,
`DataSourceV2SQLSuiteV2Filter` and `DataSourceV2DataFrameSui [...]
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Sonnet 5.5
Closes #60345 from dongjoon-hyun/SPARK-61462-merge-delete-char.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit aa77cd990b7a42753d01e12ef24d1b94381fa4f2)
Signed-off-by: Dongjoon Hyun <[email protected]>
skip-checks: true
---
.../sql/internal/connector/PredicateUtils.scala | 5 +-
.../datasources/ApplyCharTypePadding.scala | 84 ++++++++++++++++++++--
.../DataSourceV2EnhancedDeleteFilterSuite.scala | 22 ++++++
.../sql/connector/DeleteFromTableSuiteBase.scala | 56 +++++++++++++++
.../sql/connector/MergeIntoTableSuiteBase.scala | 61 ++++++++++++++++
.../spark/sql/connector/UpdateTableSuiteBase.scala | 17 +++++
.../datasources/v2/V2PredicateSuite.scala | 2 +-
7 files changed, 237 insertions(+), 10 deletions(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/connector/PredicateUtils.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/connector/PredicateUtils.scala
index 339febb374ec..fc13204ce1dc 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/connector/PredicateUtils.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/connector/PredicateUtils.scala
@@ -115,12 +115,11 @@ private[sql] object PredicateUtils {
val or = predicate.asInstanceOf[V2Or]
val left = toV1(or.left())
val right = toV1(or.right())
+ // Converting only one side would select fewer rows than the OR.
if (left.nonEmpty && right.nonEmpty) {
Some(Or(left.get, right.get))
- } else if (left.nonEmpty) {
- left
} else {
- right
+ None
}
case "NOT" =>
diff --git
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/ApplyCharTypePadding.scala
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/ApplyCharTypePadding.scala
index 65d1f98d6f49..f5c48d8f1b5a 100644
---
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/ApplyCharTypePadding.scala
+++
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/ApplyCharTypePadding.scala
@@ -22,12 +22,13 @@ import java.util.concurrent.atomic.AtomicBoolean
import org.apache.spark.internal.LogKeys
import org.apache.spark.sql.catalyst.analysis.ApplyCharTypePaddingHelper
import org.apache.spark.sql.catalyst.catalog.HiveTableRelation
-import org.apache.spark.sql.catalyst.expressions.AttributeReference
-import org.apache.spark.sql.catalyst.plans.logical.{DeleteFromTable,
LogicalPlan}
+import org.apache.spark.sql.catalyst.expressions.{Alias, AttributeMap,
AttributeReference, Expression, NamedExpression, OuterReference, SubExprUtils,
SubqueryExpression}
+import org.apache.spark.sql.catalyst.plans.logical.{DeleteFromTable,
LogicalPlan, Project, ReplaceData, WriteDelta}
import org.apache.spark.sql.catalyst.rules.Rule
-import org.apache.spark.sql.catalyst.trees.TreePattern.DELETE_FROM_TABLE
+import org.apache.spark.sql.catalyst.trees.TreePattern.{DELETE_FROM_TABLE,
REPLACE_DATA, WRITE_DELTA}
import org.apache.spark.sql.catalyst.util.CharVarcharUtils
-import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation
+import org.apache.spark.sql.connector.write.RowLevelOperationTable
+import org.apache.spark.sql.execution.datasources.v2.{DataSourceV2Relation,
ExtractV2Table}
import org.apache.spark.sql.internal.SQLConf
/**
@@ -79,8 +80,8 @@ object ApplyCharTypePadding extends Rule[LogicalPlan] {
r.copy(dataCols = cleanedDataCols, partitionCols = cleanedPartCols)
})
}, skipCond = p => p.analyzed || p.isInstanceOf[DeleteFromTable],
canGetOutput = _.resolved)
- padDeleteConditions(
- ApplyCharTypePaddingHelper.paddingForStringComparison(newPlan,
padCharCol = false))
+ padRowLevelConditions(padDeleteConditions(
+ ApplyCharTypePaddingHelper.paddingForStringComparison(newPlan,
padCharCol = false)))
} else {
ApplyCharTypePaddingHelper.paddingForStringComparison(
plan, padCharCol =
!conf.getConf(SQLConf.LEGACY_NO_CHAR_PADDING_IN_PREDICATE))
@@ -106,4 +107,75 @@ object ApplyCharTypePadding extends Rule[LogicalPlan] {
})
}
}
+
+ /**
+ * The conditions of a row-level write are not evaluated on top of the
padded read in its query:
+ * they are pushed down to the scan and to metadata-only deletes, and they
select the groups to
+ * read at runtime. To compare padded values with the padded literals and
columns, as the read
+ * does, they must apply the padding of the target columns themselves.
+ */
+ private def padRowLevelConditions(plan: LogicalPlan): LogicalPlan = {
+ plan.resolveOperatorsWithPruning(_.containsAnyPattern(REPLACE_DATA,
WRITE_DELTA)) {
+ case rd: ReplaceData =>
+ val paddings = targetColumnPaddings(rd.query)
+ rd.copy(
+ condition = padColumns(rd.condition, paddings),
+ groupFilterCondition = rd.groupFilterCondition.map(padColumns(_,
paddings)))
+ case wd: WriteDelta =>
+ val paddings = targetColumnPaddings(wd.query)
+ wd.copy(
+ condition = padColumns(wd.condition, paddings),
+ groupFilterCondition = wd.groupFilterCondition.map(padColumns(_,
paddings)))
+ }
+ }
+
+ // Maps the stored and the padded attribute of each padded target column to
the padded value.
+ // A condition can refer to either one. The read-side padding rewrites the
attributes a node
+ // references, and `ReplaceData.references` is `query.outputSet`, so a
group-based DELETE refers
+ // to the padded alias. A delta-based DELETE does not output the column and
keeps the stored one.
+ // The aliases of the padding keep the raw type, unlike the new values that
an UPDATE also
+ // projects directly on top of the read relation.
+ private def targetColumnPaddings(query: LogicalPlan):
AttributeMap[Expression] = {
+ AttributeMap(query.collect {
+ case Project(projectList, ExtractV2Table(_: RowLevelOperationTable)) =>
+ projectList.collect {
+ case alias: Alias if hasRawType(alias) =>
+ val padded = alias.child.transform {
+ case attr: AttributeReference =>
CharVarcharUtils.cleanAttrMetadata(attr)
+ }
+ (alias.toAttribute +: alias.child.references.toSeq).map(_ ->
padded)
+ }.flatten
+ }.flatten)
+ }
+
+ private def hasRawType(expr: NamedExpression): Boolean = {
+ CharVarcharUtils.getRawType(expr.metadata).isDefined
+ }
+
+ private def padColumns(cond: Expression, paddings:
AttributeMap[Expression]): Expression = {
+ // The padded value refers to the attribute without the raw type, which is
not padded again.
+ def isPadded(attr: AttributeReference): Boolean = paddings.contains(attr)
&& hasRawType(attr)
+
+ def pad(expr: Expression): Expression = expr match {
+ case attr: AttributeReference if isPadded(attr) =>
+ paddings(attr)
+
+ // The analyzer pads the subqueries it resolves, but the group filter
subquery of a MERGE is
+ // built from a resolved source, which only gets its read-side padding
here. `apply` leaves
+ // a subquery that is already padded unchanged: its relations no longer
have the raw type,
+ // and its padded comparisons are not padded again. The outer attributes
are collected from
+ // the new plan, as the analyzer does, because they may refer to the
padded alias.
+ case subquery: SubqueryExpression =>
+ val newPlan =
apply(subquery.plan).transformAllExpressionsWithSubqueries {
+ case OuterReference(attr: AttributeReference) if isPadded(attr) =>
+ paddings(attr).transform { case a: AttributeReference =>
OuterReference(a) }
+ }
+
subquery.withNewPlan(newPlan).withNewOuterAttrs(SubExprUtils.getOuterReferences(newPlan))
+
+ case other =>
+ other.mapChildren(pad)
+ }
+
+ pad(cond)
+ }
}
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2EnhancedDeleteFilterSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2EnhancedDeleteFilterSuite.scala
index b2c753e0ab61..878c5d94e998 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2EnhancedDeleteFilterSuite.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2EnhancedDeleteFilterSuite.scala
@@ -28,6 +28,7 @@ import
org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import org.apache.spark.sql.execution.datasources.v2.{BatchScanExec,
DeleteFromTableExec, ReplaceDataExec, WriteDeltaExec}
import org.apache.spark.sql.execution.joins.BaseJoinExec
import org.apache.spark.sql.functions.udf
+import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.util.QueryExecutionListener
@@ -109,6 +110,27 @@ class DataSourceV2EnhancedDeleteFilterSuite extends
SharedSparkSession
}
}
+ // The source cannot evaluate the read-side padding of a CHAR column in the
first pass, but the
+ // second pass converts it to a PartitionPredicate that matches values
stored without padding.
+ test("SPARK-61462: partition predicate with a CHAR column stored without
padding") {
+ withTable(deleteTableName) {
+ sql(s"CREATE TABLE $deleteTableName (pk INT, dep CHAR(8)) " +
+ s"USING $v2Source PARTITIONED BY (dep)")
+ withSQLConf(SQLConf.LEGACY_CHAR_VARCHAR_AS_STRING.key -> "true") {
+ sql(s"INSERT INTO $deleteTableName VALUES (1, 'hr'), (2, 'software')")
+ }
+
+ assertDeleteWithFilters(
+ s"DELETE FROM $deleteTableName WHERE dep = 'hr'",
+ expectedNumConditions = 1,
+ expectedNumPartitionPredicates = 1,
+ expectedOrdinalsPerPredicate = Seq(Array(0)),
+ expectedPartitionFieldNames = Array("dep"))
+
+ checkAnswer(sql(s"SELECT * FROM $deleteTableName"), Row(2, "software")
:: Nil)
+ }
+ }
+
// STARTS_WITH on partition column rejected in first pass; second pass
// creates a PartitionPredicate for it. '=' on data column translates
// to V2. Table accepts both (accept-data-predicates=true).
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/connector/DeleteFromTableSuiteBase.scala
b/sql/core/src/test/scala/org/apache/spark/sql/connector/DeleteFromTableSuiteBase.scala
index b4698771d54c..44f72f37a9cb 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/connector/DeleteFromTableSuiteBase.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/connector/DeleteFromTableSuiteBase.scala
@@ -377,6 +377,62 @@ abstract class DeleteFromTableSuiteBase extends
RowLevelOperationSuiteBase {
checkDeleteMetrics(numDeletedRows = 1, numCopiedRows = 0)
}
+ test("SPARK-61462: delete with a condition on a CHAR column stored with and
without padding") {
+ createTable("pk INT NOT NULL, id INT, dep CHAR(8)")
+ withSQLConf(SQLConf.LEGACY_CHAR_VARCHAR_AS_STRING.key -> "true") {
+ append("pk INT NOT NULL, id INT, dep STRING",
+ """{ "pk": 1, "id": 1, "dep": "hr" }
+ |{ "pk": 2, "id": 2, "dep": "software" }
+ |""".stripMargin)
+ }
+ append("pk INT NOT NULL, id INT, dep STRING", """{ "pk": 3, "id": 3,
"dep": "hr" }""")
+
+ // the data source cannot delete these rows with filters that compare the
padded literal with
+ // the stored values, so this delete must be executed as a row-level
operation
+ sql(s"DELETE FROM $tableNameAsString WHERE dep = 'hr'")
+
+ checkAnswer(sql(s"SELECT * FROM $tableNameAsString"), Row(2, 2,
"software") :: Nil)
+ checkDeleteMetrics(numDeletedRows = 2, numCopiedRows = 0)
+ }
+
+ test("SPARK-61462: delete with a CHAR condition in an OR with a partition
condition") {
+ createTable("pk INT NOT NULL, c CHAR(3), dep STRING")
+ append("pk INT NOT NULL, c STRING, dep STRING",
+ """{ "pk": 1, "c": "a", "dep": "hr" }
+ |{ "pk": 2, "c": "b", "dep": "software" }
+ |{ "pk": 3, "c": "x", "dep": "hr" }
+ |{ "pk": 4, "c": "a", "dep": "finance" }
+ |{ "pk": 5, "c": "y", "dep": "finance" }
+ |""".stripMargin)
+
+ // the padded comparison has no V1 filter, so it must not be dropped from
the OR
+ sql(s"DELETE FROM $tableNameAsString WHERE c = 'a' OR dep = 'software'")
+
+ checkAnswer(
+ sql(s"SELECT pk FROM $tableNameAsString"),
+ Row(3) :: Row(5) :: Nil)
+ }
+
+ test("SPARK-61462: delete with a correlated subquery on a CHAR column") {
+ withTempView("deleted") {
+ createTable("pk INT NOT NULL, c CHAR(3), dep STRING")
+ append("pk INT NOT NULL, c STRING, dep STRING",
+ """{ "pk": 1, "c": "a", "dep": "hr" }
+ |{ "pk": 2, "c": "b", "dep": "software" }
+ |{ "pk": 3, "c": "x", "dep": "hr" }
+ |""".stripMargin)
+
+ Seq("a ", "z ").toDF("v").createOrReplaceTempView("deleted")
+
+ sql(s"DELETE FROM $tableNameAsString t WHERE EXISTS (SELECT 1 FROM
deleted WHERE v = t.c)")
+
+ checkAnswer(
+ sql(s"SELECT * FROM $tableNameAsString"),
+ Row(2, "b ", "software") :: Row(3, "x ", "hr") :: Nil)
+ checkDeleteMetrics(numDeletedRows = 1, numCopiedRows = 1)
+ }
+ }
+
test("SPARK-60673: delete with metadata columns in the condition") {
// the metadata columns must be read even if the operation does not
require them
createAndInitTable("pk INT NOT NULL, id INT, dep STRING",
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/connector/MergeIntoTableSuiteBase.scala
b/sql/core/src/test/scala/org/apache/spark/sql/connector/MergeIntoTableSuiteBase.scala
index 480b17271b24..bbbb22b8aa75 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/connector/MergeIntoTableSuiteBase.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/connector/MergeIntoTableSuiteBase.scala
@@ -2173,6 +2173,67 @@ abstract class MergeIntoTableSuiteBase extends
RowLevelOperationSuiteBase
}
}
+ test("SPARK-61462: delete-only merge comparing CHAR columns stored with and
without padding") {
+ createTable("pk INT NOT NULL, c CHAR(3), dep STRING")
+ sql(s"CREATE TABLE $sourceNameAsString (c CHAR(3), dep STRING)")
+
+ withSQLConf(SQLConf.LEGACY_CHAR_VARCHAR_AS_STRING.key -> "true") {
+ append("pk INT NOT NULL, c STRING, dep STRING",
+ """{ "pk": 1, "c": "a", "dep": "hr" }
+ |{ "pk": 3, "c": "x", "dep": "hr" }
+ |""".stripMargin)
+ sql(s"INSERT INTO $sourceNameAsString VALUES ('b', 'software')")
+ }
+ append("pk INT NOT NULL, c STRING, dep STRING",
+ """{ "pk": 2, "c": "b", "dep": "software" }
+ |{ "pk": 4, "c": "y", "dep": "finance" }
+ |""".stripMargin)
+ sql(s"INSERT INTO $sourceNameAsString VALUES ('a', 'hr')")
+
+ sql(
+ s"""MERGE INTO $tableNameAsString t
+ |USING $sourceNameAsString s
+ |ON t.c = s.c AND t.dep = s.dep
+ |WHEN MATCHED THEN
+ | DELETE
+ |""".stripMargin)
+
+ checkAnswer(
+ sql(s"SELECT * FROM $tableNameAsString"),
+ Row(3, "x ", "hr") :: Row(4, "y ", "finance") :: Nil)
+ }
+
+ Seq("true", "false").foreach { groupFilterEnabled =>
+ test("SPARK-61462: delete-only merge with a condition on a CHAR column
stored without " +
+ s"padding (group filter enabled: $groupFilterEnabled)") {
+ withSQLConf(
+ SQLConf.RUNTIME_ROW_LEVEL_OPERATION_GROUP_FILTER_ENABLED.key ->
groupFilterEnabled) {
+ withTempView("source") {
+ createTable("pk INT NOT NULL, id INT, dep CHAR(8)")
+ withSQLConf(SQLConf.LEGACY_CHAR_VARCHAR_AS_STRING.key -> "true") {
+ append("pk INT NOT NULL, id INT, dep STRING",
+ """{ "pk": 1, "id": 1, "dep": "hr" }
+ |{ "pk": 2, "id": 2, "dep": "it" }
+ |{ "pk": 3, "id": 3, "dep": "software" }
+ |""".stripMargin)
+ }
+
+ Seq(1, 2, 3).toDF("pk").createOrReplaceTempView("source")
+
+ sql(
+ s"""MERGE INTO $tableNameAsString t
+ |USING source s
+ |ON t.pk = s.pk AND t.dep IN ('hr', 'it')
+ |WHEN MATCHED THEN
+ | DELETE
+ |""".stripMargin)
+
+ checkAnswer(sql(s"SELECT * FROM $tableNameAsString"), Row(3, 3,
"software") :: Nil)
+ }
+ }
+ }
+ }
+
test("SPARK-60708: merge into char/varchar table with metadata columns") {
withTempView("source") {
createTable("pk INT NOT NULL, id INT, dep STRING, name VARCHAR(10)")
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/connector/UpdateTableSuiteBase.scala
b/sql/core/src/test/scala/org/apache/spark/sql/connector/UpdateTableSuiteBase.scala
index 9e9b2a7dfbe9..4bbaa83aa6cc 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/connector/UpdateTableSuiteBase.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/connector/UpdateTableSuiteBase.scala
@@ -991,6 +991,23 @@ abstract class UpdateTableSuiteBase extends
RowLevelOperationSuiteBase {
checkUpdateMetrics(numUpdatedRows = 2, numCopiedRows = 0)
}
+ test("SPARK-61462: update with a condition on a CHAR column") {
+ createTable("pk INT NOT NULL, c CHAR(3), id INT, dep STRING")
+
+ append("pk INT NOT NULL, c STRING, id INT, dep STRING",
+ """{ "pk": 1, "c": "a", "id": 1, "dep": "hr" }
+ |{ "pk": 2, "c": "x", "id": 2, "dep": "software" }
+ |{ "pk": 3, "c": "b", "id": 3, "dep": "hr" }
+ |""".stripMargin)
+
+ // the new values that an UPDATE projects on top of the read relation are
not paddings
+ sql(s"UPDATE $tableNameAsString SET id = -1 WHERE c IN ('a', 'b', 'c')")
+
+ checkAnswer(
+ sql(s"SELECT * FROM $tableNameAsString"),
+ Row(1, "a ", -1, "hr") :: Row(2, "x ", 2, "software") :: Row(3, "b ",
-1, "hr") :: Nil)
+ }
+
test("SPARK-60708: update char/varchar table with metadata columns") {
createTable("pk INT NOT NULL, id INT, dep STRING, name VARCHAR(10)")
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2PredicateSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2PredicateSuite.scala
index 7396687d9020..dc6c886d73bf 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2PredicateSuite.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2PredicateSuite.scala
@@ -395,7 +395,7 @@ class V2PredicateSuite extends SparkFunSuite {
val left = new Predicate("=", Array[Expression](ref("a"), LiteralValue(1,
IntegerType)))
val predicate3 = new Or(left,
new Predicate("=", Array[Expression](LiteralValue(1, IntegerType))))
- assert(PredicateUtils.toV1(predicate3) == PredicateUtils.toV1(left))
+ assert(PredicateUtils.toV1(predicate3) == None)
val predicate4 = new Or(
new Predicate("=", Array[Expression](LiteralValue(1, IntegerType))),
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]