Skip to content

Render single spaces in DROP PRIMARY KEY, RENAME TABLE and indexes - #2792

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/deparse-whitespace-20261013
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/deparse-whitespace-20261013

Conversation

@minleejae

@minleejae minleejae commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Render DDL with single spaces between words. Today:

  • ALTER TABLE t DROP PRIMARY KEY ends with a space, and with a parameter renders DROP PRIMARY KEY CASCADE.
  • RENAME TABLE t TO t2 renders RENAME TABLE t TO t2.
  • ALTER TABLE t ADD INDEX i (a) renders ADD INDEX i (a).

The SQL still reparses, but the extra spaces differ from the input and from each other.

Current design (As-is)

  • The DROP PRIMARY KEY renderer appends a trailing space. The shared tail adds its own space before parameters.
  • RenameTableStatement appends " TABLE " and then " " or " IF EXISTS ".
  • Index prefixes its keyword and name with a space even when no index type precedes them. An index with only a keyword or a name therefore renders a leading space.

Target design (To-be)

  • Separate these words with exactly one space and add no leading or trailing space.
  • Rendered SQL is otherwise unchanged. The SQL renderer and StatementDeParser produce the same text.

Validation

  • New DeparseWhitespaceTest:
    • Compares toString() and StatementDeParser output exactly for DROP PRIMARY KEY (alone, with CASCADE, and followed by another action), RENAME (with and without TABLE, IF EXISTS, and several tables), ADD INDEX/ADD KEY, and an index inside CREATE TABLE.
    • Checks constructed Index declarations directly.
  • Three existing assertions that encoded ADD INDEX now expect a single space.
  • Java 17 offline Gradle spotlessApply check: 10,105 tests, 10,080 passed, 25 skipped, zero failures/errors.
  • Ran the rendered statements on MySQL 8.4, MySQL 8.0 and MariaDB 11.4 (19 cases), including MariaDB RENAME TABLE IF EXISTS. All succeed in original and rendered form.

Integration validation

Applied #2788, #2789, #2790, #2791 and #2792 together on master (166f0a27):

DROP PRIMARY KEY ended with a space, which doubled before CASCADE or
RESTRICT. RENAME TABLE rendered two spaces before the first table, and
an index without a type rendered a leading space, so ALTER TABLE ... ADD
INDEX and named-only indexes came out with doubled spaces. Separate
these words with exactly one space; the SQL is otherwise unchanged.

Signed-off-by: minleejae <mmj9808@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant