Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Aug 21, 2025

Problem

When using the EXISTS clause in SQL conditions, unintended line breaks were inserted. This affected formatting in various scenarios, such as when EXISTS is used as the first condition in a WHERE clause, within conditional directives, or in combination with CREATE or IN clauses.

Solution

A new block class was introduced to represent the EXISTS clause. By properly recognizing the parent-child relationships of these blocks, the formatter now controls line breaks and indentation more accurately.

Testing

  • Verified formatting when EXISTS is used as the first condition in a WHERE clause.
  • Tested cases where specific keywords are wrapped with conditional directives.
  • Checked formatting when EXISTS is combined with CREATE or IN clauses.

@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 04:14
@xterao xterao linked an issue Aug 21, 2025 that may be closed by this pull request
@xterao xterao added this to the 2.1.2 Release milestone Aug 21, 2025

This comment was marked as outdated.

@xterao xterao force-pushed the fix/sql-format-exists-group branch from 1253ea6 to 60b4203 Compare August 21, 2025 04:35
@xterao xterao requested a review from Copilot August 21, 2025 05:49
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 formatting issues with SQL EXISTS clauses by introducing a new block class to properly handle line breaks and indentation. The fix addresses problems where unintended line breaks were inserted when EXISTS appeared as the first condition in WHERE clauses, within conditional directives, or combined with CREATE/IN clauses.

  • Introduces SqlExistsGroupBlock to represent EXISTS clauses with proper formatting logic
  • Updates block generation logic to recognize EXISTS keywords and create appropriate block structures
  • Refactors conditional comment block indentation calculations for better maintainability

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
SqlExistsGroupBlock.kt New block class implementing EXISTS clause formatting with specialized indentation logic
SqlKeywordUtil.kt Adds EXISTS keyword recognition and line setting rules
SqlBlockGenerator.kt Updates block generation to handle EXISTS keywords and create SqlExistsGroupBlock instances
SqlElConditionLoopCommentBlock.kt Refactors indentation calculation methods for better maintainability and adds directive support
SqlSubQueryGroupBlock.kt Improves child block filtering logic for conditional comments and keyword groups
Test files Adds comprehensive test cases for conditional EXISTS and subquery formatting scenarios

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-exists-group branch from b8e2c24 to b25b329 Compare August 21, 2025 06:08
@xterao xterao merged commit 49b7af8 into fix/sql-formatter Aug 21, 2025
5 checks passed
@xterao xterao deleted the fix/sql-format-exists-group branch August 21, 2025 06:29
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.

Incorrect Formatting of EXISTS Clause Inside Conditional Directives

2 participants