Skip to content

fix: support parentheses for negative decimal formatting#23718

Open
wangzhigang1999 wants to merge 1 commit into
apache:mainfrom
wangzhigang1999:zhigang/fix-spark-decimal-parentheses
Open

fix: support parentheses for negative decimal formatting#23718
wangzhigang1999 wants to merge 1 commit into
apache:mainfrom
wangzhigang1999:zhigang/fix-spark-decimal-parentheses

Conversation

@wangzhigang1999

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

Spark and Java format negative numeric values with parentheses when the ( flag is present. The decimal formatting path always emitted a minus sign because it ignored negative_in_parentheses, while the floating-point path already handled the flag. This made format_string inconsistent across numeric input types.

What changes are included in this PR?

  • Add a closing suffix when a negative decimal uses parentheses formatting.
  • Include the suffix when calculating width, left alignment, and zero padding.
  • Add regression coverage for grouped negative decimals with and without an explicit width.

Are these changes tested?

Yes. The following checks pass locally:

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test -p datafusion-spark --lib
  • The full workspace test command from the contributor guide with avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption enabled

Are there any user-facing changes?

Yes. Spark-compatible formatting of negative decimal values now honors the parentheses flag. There are no public API or breaking changes.

@github-actions github-actions Bot added the spark label Jul 20, 2026
@wangzhigang1999
wangzhigang1999 marked this pull request as ready for review July 20, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spark format_string ignores parentheses flag for negative decimals

1 participant