Skip to content

Spark format_string ignores parentheses flag for negative decimals #23717

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions