Skip to content

[SPARK-59273][SQL][FOLLOWUP] Restore skipping non-string columns in DataFrameNaFunctions.fillValue - #58646

Closed
pan3793 wants to merge 1 commit into
apache:masterfrom
pan3793:spark-59273-nafill-followup
Closed

[SPARK-59273][SQL][FOLLOWUP] Restore skipping non-string columns in DataFrameNaFunctions.fillValue#58646
pan3793 wants to merge 1 commit into
apache:masterfrom
pan3793:spark-59273-nafill-followup

Conversation

@pan3793

@pan3793 pan3793 commented Sep 9, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

SPARK-59273 (#58541) widened the fill-value type match in DataFrameNaFunctions.fillValue from the exact StringType to the whole string family:

-        case (StringType, dt) => dt == StringType
+        case (StringType, _: StringType) => true

That pattern is no longer exhaustive for a string fill value: when the schema contains any non-string column, that column falls through to the throwing case _ and df.na.fill(<string>) fails with IllegalArgumentException: StringType is not matched at fillValue. This patch keeps the string-family match but restores the skip for non-string columns:

case (StringType, dt) => dt.isInstanceOf[StringType]

which mirrors the NumericType case above it.

Why are the changes needed?

na.fill with a string value must fill only string-family columns and leave other columns untouched; a schema with any non-string column must not throw. The regression breaks basic usage such as:

Seq[(String, Integer)]((null, null)).toDF("name", "age").na.fill("unknown")

and reddened master CI in DataFrameNaFunctionsSuite, SparkConnectProtoSuite, and the PySpark DataFrameStatTests.test_fillna / DataFrameStatParityTests.test_fillna. SPARK-59273 has not shipped in a release.

Does this PR introduce any user-facing change?

No. It restores on master the pre-SPARK-59273 behavior of DataFrameNaFunctions.fill with a string value.

How was this patch tested?

Existing tests already exercise mixed-type schemas and both behaviors, and failed on master after SPARK-59273:

  • DataFrameNaFunctionsSuite: fill, fill with col(*), fill with nested columns
  • SparkConnectProtoSuite: SPARK-41128: Test fill na
  • PySpark DataFrameStatTests.test_fillna, DataFrameStatParityTests.test_fillna

Ran locally:

build/sbt 'sql/testOnly *DataFrameNaFunctionsSuite'
build/sbt 'connect/testOnly *SparkConnectProtoSuite'

Both suites pass; no new tests added because the failing cases above cover the regression.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: DeepSeek V4 Flash

…ataFrameNaFunctions.fillValue

SPARK-59273 widened the fill-value type match in `fillValue` to the whole string family, but the new pattern is no longer exhaustive: `na.fill` with a string value now throws `IllegalArgumentException: StringType is not matched at fillValue` when the schema contains any non-string column. Match the string family while skipping non-string columns, mirroring the NumericType case.

Existing tests caught the regression (DataFrameNaFunctionsSuite, SparkConnectProtoSuite, PySpark DataFrameStatTests.test_fillna and its Connect parity test) and pass again.

Assisted-by: DeepSeek V4 Flash
@vrjdev

vrjdev commented Sep 9, 2026

Copy link
Copy Markdown

Thanks for the fix, came to the same conclusion and was planning to fix the issue.

@ulysses-you ulysses-you left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm if CI pass

zhengruifeng pushed a commit that referenced this pull request Sep 9, 2026
…ataFrameNaFunctions.fillValue

### What changes were proposed in this pull request?

SPARK-59273 (#58541) widened the fill-value type match in `DataFrameNaFunctions.fillValue` from the exact `StringType` to the whole string family:

```scala
-        case (StringType, dt) => dt == StringType
+        case (StringType, _: StringType) => true
```

That pattern is no longer exhaustive for a string fill value: when the schema contains any non-string column, that column falls through to the throwing `case _` and `df.na.fill(<string>)` fails with `IllegalArgumentException: StringType is not matched at fillValue`. This patch keeps the string-family match but restores the skip for non-string columns:

```scala
case (StringType, dt) => dt.isInstanceOf[StringType]
```

which mirrors the `NumericType` case above it.

### Why are the changes needed?

`na.fill` with a string value must fill only string-family columns and leave other columns untouched; a schema with any non-string column must not throw. The regression breaks basic usage such as:

```scala
Seq[(String, Integer)]((null, null)).toDF("name", "age").na.fill("unknown")
```

and reddened master CI in `DataFrameNaFunctionsSuite`, `SparkConnectProtoSuite`, and the PySpark `DataFrameStatTests.test_fillna` / `DataFrameStatParityTests.test_fillna`. SPARK-59273 has not shipped in a release.

### Does this PR introduce _any_ user-facing change?

No. It restores on master the pre-SPARK-59273 behavior of `DataFrameNaFunctions.fill` with a string value.

### How was this patch tested?

Existing tests already exercise mixed-type schemas and both behaviors, and failed on master after SPARK-59273:

- `DataFrameNaFunctionsSuite`: `fill`, `fill with col(*)`, `fill with nested columns`
- `SparkConnectProtoSuite`: `SPARK-41128: Test fill na`
- PySpark `DataFrameStatTests.test_fillna`, `DataFrameStatParityTests.test_fillna`

Ran locally:

```
build/sbt 'sql/testOnly *DataFrameNaFunctionsSuite'
build/sbt 'connect/testOnly *SparkConnectProtoSuite'
```

Both suites pass; no new tests added because the failing cases above cover the regression.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: DeepSeek V4 Flash

Closes #58646 from pan3793/spark-59273-nafill-followup.

Authored-by: Cheng Pan <pan3793@gmail.com>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit 3d25204)
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
@zhengruifeng

Copy link
Copy Markdown
Contributor

Merge Summary:

Posted by merge_spark_pr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants