Skip to content

[SPARK-58640][SQL] Align getBool with the sibling option accessors in CSVOptions and XmlOptions - #57847

Closed
uros-b wants to merge 1 commit into
apache:masterfrom
uros-b:refactor-csvoptions-getbool
Closed

[SPARK-58640][SQL] Align getBool with the sibling option accessors in CSVOptions and XmlOptions#57847
uros-b wants to merge 1 commit into
apache:masterfrom
uros-b:refactor-csvoptions-getbool

Conversation

@uros-b

@uros-b uros-b commented Aug 7, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

Rewrites the private getBool in CSVOptions and XmlOptions to match the shape of the sibling option accessors:

  private def getBool(paramName: String, default: Boolean = false): Boolean = {
    val paramValue = parameters.get(paramName)
    paramValue match {
      case None => default
      case Some(null) => default
      case Some(value) => value.toLowerCase(Locale.ROOT) match {
        case "true" => true
        case "false" => false
        case _ => throw QueryExecutionErrors.paramIsNotBooleanValueError(paramName)
      }
    }
  }

Why are the changes needed?

getChar and getInt in CSVOptions already match on parameters.get(paramName) and handle the missing and null cases as case None and case Some(null), while getBool was an if/else-if chain over parameters.getOrElse(paramName, default.toString). Besides being inconsistent, that form converts the default to a string only to parse it straight back, and calls toLowerCase twice on the false and error paths.

XmlOptions carried a byte-identical copy of the old method, so both are updated together to keep them in sync rather than leaving them divergent.

Does this PR introduce any user-facing change?

No. Behavior is unchanged for every input: an absent key yields the default, an explicit null value yields the default, true/false are accepted case-insensitively via Locale.ROOT, and any other value throws the same error with the same parameter as before.

How was this patch tested?

Behavior-preserving change covered by the existing CSV and XML option tests. Equivalence with the previous implementation was checked case by case across absent keys, explicit nulls, mixed-case true/false, the empty string, and other invalid values, for both default values.

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

Generated-by: Claude Code (Opus 4.8)

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@cloud-fan Please review.

@cloud-fan cloud-fan 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.

0 blocking, 0 non-blocking, 0 nits.
The refactor is behavior-preserving and internally consistent; no review findings were identified.

Verification

I traced every prior branch against the replacement in both files. An absent key still yields the caller-provided default, an explicit null still yields that default, case-insensitive true and false still map to their Boolean values, and every other non-null string still throws paramIsNotBooleanValueError for the same parameter. No tests were run as part of this review.

@uros-b

uros-b commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Thank you @cloud-fan!

@uros-b uros-b closed this in 551a783 Aug 7, 2026
uros-b added a commit that referenced this pull request Aug 7, 2026
… CSVOptions and XmlOptions

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

Rewrites the private `getBool` in `CSVOptions` and `XmlOptions` to match the shape of the sibling option accessors:

```scala
  private def getBool(paramName: String, default: Boolean = false): Boolean = {
    val paramValue = parameters.get(paramName)
    paramValue match {
      case None => default
      case Some(null) => default
      case Some(value) => value.toLowerCase(Locale.ROOT) match {
        case "true" => true
        case "false" => false
        case _ => throw QueryExecutionErrors.paramIsNotBooleanValueError(paramName)
      }
    }
  }
```

### Why are the changes needed?

`getChar` and `getInt` in `CSVOptions` already match on `parameters.get(paramName)` and handle the missing and null cases as `case None` and `case Some(null)`, while `getBool` was an if/else-if chain over `parameters.getOrElse(paramName, default.toString)`. Besides being inconsistent, that form converts the default to a string only to parse it straight back, and calls `toLowerCase` twice on the `false` and error paths.

`XmlOptions` carried a byte-identical copy of the old method, so both are updated together to keep them in sync rather than leaving them divergent.

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

No. Behavior is unchanged for every input: an absent key yields the default, an explicit `null` value yields the default, `true`/`false` are accepted case-insensitively via `Locale.ROOT`, and any other value throws the same error with the same parameter as before.

### How was this patch tested?

Behavior-preserving change covered by the existing CSV and XML option tests. Equivalence with the previous implementation was checked case by case across absent keys, explicit nulls, mixed-case `true`/`false`, the empty string, and other invalid values, for both `default` values.

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

Generated-by: Claude Code (Opus 4.8)

Closes #57847 from uros-b/refactor-csvoptions-getbool.

Authored-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
(cherry picked from commit 551a783)
Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
uros-b added a commit that referenced this pull request Aug 7, 2026
… CSVOptions and XmlOptions

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

Rewrites the private `getBool` in `CSVOptions` and `XmlOptions` to match the shape of the sibling option accessors:

```scala
  private def getBool(paramName: String, default: Boolean = false): Boolean = {
    val paramValue = parameters.get(paramName)
    paramValue match {
      case None => default
      case Some(null) => default
      case Some(value) => value.toLowerCase(Locale.ROOT) match {
        case "true" => true
        case "false" => false
        case _ => throw QueryExecutionErrors.paramIsNotBooleanValueError(paramName)
      }
    }
  }
```

### Why are the changes needed?

`getChar` and `getInt` in `CSVOptions` already match on `parameters.get(paramName)` and handle the missing and null cases as `case None` and `case Some(null)`, while `getBool` was an if/else-if chain over `parameters.getOrElse(paramName, default.toString)`. Besides being inconsistent, that form converts the default to a string only to parse it straight back, and calls `toLowerCase` twice on the `false` and error paths.

`XmlOptions` carried a byte-identical copy of the old method, so both are updated together to keep them in sync rather than leaving them divergent.

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

No. Behavior is unchanged for every input: an absent key yields the default, an explicit `null` value yields the default, `true`/`false` are accepted case-insensitively via `Locale.ROOT`, and any other value throws the same error with the same parameter as before.

### How was this patch tested?

Behavior-preserving change covered by the existing CSV and XML option tests. Equivalence with the previous implementation was checked case by case across absent keys, explicit nulls, mixed-case `true`/`false`, the empty string, and other invalid values, for both `default` values.

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

Generated-by: Claude Code (Opus 4.8)

Closes #57847 from uros-b/refactor-csvoptions-getbool.

Authored-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
(cherry picked from commit 551a783)
Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
@uros-b

uros-b commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

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.

2 participants