Skip to content

Spark format_string ignores parentheses flag for negative decimals #23717

Closed

Description

@wangzhigang1999

Describe the bug

The Spark-compatible format_string function does not honor the ( flag when formatting negative Decimal values. Instead of enclosing the magnitude in parentheses, the decimal formatting path always emits a minus sign.

The floating-point formatting path already handles this flag correctly, so decimal and floating-point values currently produce inconsistent results.

To Reproduce

Format a negative decimal using the grouping separator and parentheses flags:

SELECT format_string('%(,.2f', CAST(-1234.50 AS DECIMAL(10, 2)));

Current result:

-1,234.50

A fixed-width format such as %(,15.2f similarly produces a minus sign instead of parentheses.

Expected behavior

The result should match Spark/Java formatting semantics:

(1,234.50)

For %(,15.2f, the result should be padded to the requested width:

     (1,234.50)

Additional context

ConversionSpecifier::format_decimal reads the sign but does not apply negative_in_parentheses. Supporting the flag also requires accounting for the closing parenthesis when applying width, left alignment, and zero padding.

Activity

  1. Udaytaneja commented on Jul 20, 2026

    @Udaytaneja

    Hi mantainers , I am interested in doing this work . Please assign this to me .

  2. added a commit that references this issue on Jul 28, 2026
    bb75d92
  3. added a commit that references this issue on Aug 12, 2026
    643cb23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions