Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Aug 27, 2025

Summary
This PR fixes unintended formatting when column names are identical to SQL functions or reserved keywords. Previously, such identifiers were not treated as normal word blocks, leading to incorrect formatting results.

Relation
#423

Details

  • Columns or identifiers that share names with functions or keywords are now treated as word blocks.
  • Escaped identifiers (e.g., "age") are also handled consistently to prevent unwanted formatting changes.

Adjustments for Escaped Identifiers:

  • Disable keyword capitalization for escaped words.
  • Do not create keyword groups for them.
  • Apply the same spacing rules as for word blocks, including consistent spacing around escape characters.
  • When a column definition uses escape characters, align the indentation to the right the same way as with normal column names.
  • When enclosed in escape characters, calculate spacing based on the total character length, including the escape characters.

Impact

  • Prevents unexpected line breaks or keyword formatting when column names overlap with reserved words or functions.
  • Ensures escaped identifiers maintain proper indentation and spacing.

@github-actions github-actions bot added the fix Bug fixes label Aug 27, 2025
@xterao xterao self-assigned this Aug 27, 2025
@xterao xterao requested a review from Copilot August 27, 2025 01:07
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 unintended formatting when column names are identical to SQL functions or reserved keywords by treating such identifiers as word blocks instead of applying function/keyword formatting.

  • Handle escaped identifiers (e.g., "age", [abs]) consistently as word blocks without keyword capitalization
  • Improve spacing and indentation logic for escaped identifiers and conditional expressions
  • Add test coverage for function names used as column identifiers

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
FunctionNameColumn.sql Test input with function/keyword names used as columns
FunctionNameColumn_format.sql Expected formatted output showing proper word block treatment
SqlFormatterTest.kt Added test case for function name column formatting
SqlFormatVisitor.kt Added logic to handle elements after block comment end
SqlBlockGenerator.kt Added helper methods for escape detection and function name handling
SqlFormatPreProcessor.kt Enhanced escape detection and keyword processing logic
InjectionSqlFormatter.kt Improved base indent calculation for text blocks
NotQueryGroupHandler.kt Extended condition keyword group detection
SqlBlockRelationBuilder.kt Refactored top-level type checking
SqlFunctionGroupBlock.kt Enhanced indentation calculation for function blocks
SqlEscapeBlock.kt Improved escape block indentation and spacing logic
SqlTopQueryGroupBlock.kt Added spacing logic for top-level blocks
SqlConditionalExpressionGroupBlock.kt Enhanced indentation for conditional expressions
SqlElConditionLoopCommentBlock.kt Fixed indentation calculations and parent detection
SqlElBlockCommentBlock.kt Added keyword group block indentation support
SqlRightPatternBlock.kt Improved spacing logic for conditional expressions
SqlFileBlock.kt Enhanced keyword/function name detection and spacing
SqlBlock.kt Improved condition loop directive detection
TypeUtil.kt Centralized top-level type checking logic

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

@xterao xterao merged commit 267cc7a into main Aug 27, 2025
5 checks passed
@xterao xterao deleted the fix/sql-format-column-name-as-word branch August 27, 2025 06:27
@xterao xterao added this to the 2.2.0 Release milestone Aug 28, 2025
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 Line Break When Column Name Matches Function Name After Conditional Loop Directive

2 participants