You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "wangzhigang1999 (via GitHub)" <gi...@apache.org> on 2026/07/20 09:53:02 UTC
[PR] fix: support parentheses for negative decimal formatting [datafusion]
wangzhigang1999 opened a new pull request, #23718:
URL: https://github.com/apache/datafusion/pull/23718
## Which issue does this PR close?
- Closes #23717.
## 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.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: support parentheses for negative decimal formatting [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew merged PR #23718:
URL: https://github.com/apache/datafusion/pull/23718
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: support parentheses for negative decimal formatting [datafusion]
Posted by "wangzhigang1999 (via GitHub)" <gi...@apache.org>.
wangzhigang1999 commented on code in PR #23718:
URL: https://github.com/apache/datafusion/pull/23718#discussion_r3656777076
##########
datafusion/spark/src/function/string/format_string.rs:
##########
@@ -2896,17 +2900,26 @@ mod tests {
#[test]
fn test_grouping_separator_parentheses_decimal() -> Result<()> {
- // %(,15.2f on negative decimal — format_decimal ignores negative_in_parentheses,
- // always uses '-'. Check TODO in fn format_decimal
+ test_scalar_function!(
Review Comment:
Good point, thanks! I added an equivalent Decimal256 regression case in 0d51a2c, so both public decimal scalar variants are now covered.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: support parentheses for negative decimal formatting [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #23718:
URL: https://github.com/apache/datafusion/pull/23718#issuecomment-5091500819
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/23718?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 80.66%. Comparing base ([`3b1ce16`](https://app.codecov.io/gh/apache/datafusion/commit/3b1ce16be6beb3377c59ec36fd9f8ae62998c4c0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`0d51a2c`](https://app.codecov.io/gh/apache/datafusion/commit/0d51a2c4cc216da1171092aaca599ad4325c0aba?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 97 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #23718 +/- ##
==========================================
- Coverage 80.69% 80.66% -0.04%
==========================================
Files 1088 1095 +7
Lines 367766 372318 +4552
Branches 367766 372318 +4552
==========================================
+ Hits 296781 300326 +3545
- Misses 53276 54070 +794
- Partials 17709 17922 +213
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/23718?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: support parentheses for negative decimal formatting [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #23718:
URL: https://github.com/apache/datafusion/pull/23718#discussion_r3655833686
##########
datafusion/spark/src/function/string/format_string.rs:
##########
@@ -2896,17 +2900,26 @@ mod tests {
#[test]
fn test_grouping_separator_parentheses_decimal() -> Result<()> {
- // %(,15.2f on negative decimal — format_decimal ignores negative_in_parentheses,
- // always uses '-'. Check TODO in fn format_decimal
+ test_scalar_function!(
Review Comment:
Nice addition to the regression tests. Would it be worth adding a Decimal256 case for the same `%(...)` decimal formatting regression as well?
I believe the implementation path is shared between Decimal128 and Decimal256, so I do not think this is required for correctness. That said, having both public decimal scalar variants covered would help lock the behavior in and guard against future regressions.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org