sthandassery opened a new pull request, #60583:
URL: https://github.com/apache/spark/pull/60583
### What changes were proposed in this pull request?
Parse `COLUMNS` with `toIntOption` in `ConsoleProgressBar`, and fall back to
the default width of 80 unless it is a positive integer.
### Why are the changes needed?
`sys.env.getOrElse("COLUMNS", "80").toInt` only handles an unset `COLUMNS`.
Both failures below are regressions:
- An empty value (common on headless hosts) fails SparkContext
initialization with `NumberFormatException: For input string: ""`. This has
happened since 3.0.0: #23901 simplified the width expression and dropped the
original check for an empty `COLUMNS`.
- A negative value parses, but every job that shows the bar then fails in
`clear()`, because `String.repeat` rejects a negative count. This has happened
since 4.1.0: SPARK-53035 replaced Scala's `" " * n`, which returns an empty
string for a negative `n`, with `String.repeat`.
A non-numeric value has failed since the progress bar was added. This fix
covers all three.
A cosmetic progress bar shouldn't be able to break SparkContext startup or
user jobs.
### Does this PR introduce _any_ user-facing change?
Yes. A shell started with an empty, non-numeric, zero or negative `COLUMNS`
now starts and runs jobs with an 80-column progress bar instead of failing.
Valid values behave as before.
### How was this patch tested?
Manually, running a short job in `bin/spark-shell` before and after the
change:
| `COLUMNS` | Before | After |
|---|---|---|
| empty | SparkContext fails to start (`NumberFormatException`) | works |
| `-1` | job fails (`IllegalArgumentException: count is negative: -1`) |
works |
| `120` | works, 120-column bar | works, 120-column bar |
`0` and `abc` also start and run normally after the change. `build/sbt
core/scalastyle` and the existing `SparkSubmitSuite` progress-bar test pass.
No unit test was added: the width is read once from the process environment
when the bar is created, so a test would need a new seam just for this one
line. Happy to add one if reviewers prefer.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5.5)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]