Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Aug 21, 2025

Overview

  • Fixed an issue where unnecessary spaces were inserted between operators (such as ->>, @>, etc.) when accessing properties from JSON columns.
  • Improved the formatting logic for array parameters. Specifically, when writing arrays like ARRAY['p1', 'p2'], ensured that the array closing bracket ] is not treated as an escape character, so that arrays are formatted correctly.

Example

Before:

SELECT id
       , json_data - > > 'name' AS name
       , json_data - > 'address' - > > 'city' AS city -- Incorrect spaces
       , jsonb_data @ > '{"active": true}' AS is_active
       , jsonb_data < @ '{"role": "admin"}' AS has_admin_role
       , jsonb_data ? 'email' AS has_email
       , jsonb_data ? & array [ /* property1 */'name'
       , /* property2 */'age' ]AS has_required_fields -- Incorrect line break

After:

SELECT id
      , json_data ->> 'name' AS name
      , json_data -> 'address' ->> 'city' AS city
      , jsonb_data @> '{"active": true}' AS is_active
      , jsonb_data <@ '{"role": "admin"}' AS has_admin_role
      , jsonb_data ? 'email' AS has_email
      , jsonb_data ?& array[/* property1 */'name', /* property2 */'age'] AS has_required_fields
  • These changes improve the accuracy and readability of SQL formatting when working with JSON columns and array parameters.

@xterao xterao self-assigned this Aug 21, 2025
@github-actions github-actions bot added the fix Bug fixes label Aug 21, 2025
@xterao xterao requested a review from Copilot August 21, 2025 11:14
@xterao xterao added this to the 2.1.2 Release milestone Aug 21, 2025
@xterao xterao linked an issue Aug 21, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes SQL formatting issues specifically for JSON columns and array parameters by improving how operators and array brackets are handled.

  • Fixed unnecessary spaces being inserted between JSON operators (->>, @>, etc.) when accessing properties from JSON columns
  • Improved array parameter formatting by ensuring array closing brackets ] are handled correctly and not treated as escape characters
  • Added specific handling for ARRAY expressions with proper indentation and spacing

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/test/testData/sql/formatter/*.sql Test data files showing before/after formatting with JSON operators and array parameters
src/test/kotlin/.../SqlFormatterTest.kt Added test case for comparison operators formatting
src/main/kotlin/.../SqlBlockGenerator.kt Added logic to detect ARRAY keywords and create proper block types
src/main/kotlin/.../CommaRawClauseHandler.kt Added handling for commas within array list groups
src/main/kotlin/.../SqlArrayWordBlock.kt New block type for ARRAY keywords with proper indentation logic
src/main/kotlin/.../SqlArrayListGroupBlock.kt New group block for array parameter lists
src/main/kotlin/.../SqlEscapeBlock.kt Modified to handle array closing brackets correctly
src/main/kotlin/.../SqlFileBlock.kt Updated spacing rules for JSON/SQL operators and array constructs
src/main/kotlin/.../comment/*.kt Refactored comment block handling with improved utility methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@xterao xterao force-pushed the fix/sql-format-spacing-comparison-operators branch from c7267ab to b58e9bd Compare August 21, 2025 11:33
@xterao xterao merged commit 7b39e02 into fix/sql-formatter Aug 22, 2025
5 checks passed
@xterao xterao deleted the fix/sql-format-spacing-comparison-operators branch August 22, 2025 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extra Spaces in Comparison Operators

2 participants