Skip to content

feat(dsql): parse ALTER TABLE ASYNC - #2

Merged
amaksimo merged 1 commit into
amaksimo:dsql-async-indexfrom
agarwal-govind:dsql-async-alter-table
Aug 3, 2026
Merged

feat(dsql): parse ALTER TABLE ASYNC#2
amaksimo merged 1 commit into
amaksimo:dsql-async-indexfrom
agarwal-govind:dsql-async-alter-table

Conversation

@agarwal-govind

Copy link
Copy Markdown

Summary

Aurora DSQL runs certain ALTER TABLE operations as asynchronous DDL jobs via the ALTER TABLE ASYNC form — most notably:

ALTER TABLE ASYNC t VALIDATE CONSTRAINT c

which returns a job_id and validates existing rows in the background (the same async DDL model as CREATE INDEX ASYNC, already supported on this branch). The parser currently rejects ALTER TABLE ASYNC ... because ASYNC is not recognized after TABLE.

This adds an async flag to the AlterTable AST node and parses the optional ASYNC keyword, following the existing CREATE INDEX ASYNC precedent.

Changes

  • ast/ddl.rs: add AlterTable.async: bool + render ASYNC in Display (after ALTER TABLE , before IF EXISTS/ONLY).
  • parser/mod.rs: parse_alter_table parses an optional ASYNC keyword. Non-async ALTER TABLE is unchanged.
  • dialect/snowflake.rs: set async: false at the two AlterTable construction sites.
  • tests/sqlparser_postgres.rs: round-trip tests for ALTER TABLE ASYNC ... VALIDATE CONSTRAINT, including ASYNC + IF EXISTS + ONLY.
  • Cargo.toml: bump sqlparser-dsql 0.62.10.62.2 and note ALTER TABLE ASYNC in the description.

Testing

  • Exact round-trip verified for ALTER TABLE ASYNC t VALIDATE CONSTRAINT c and ALTER TABLE ASYNC IF EXISTS ONLY public.t VALIDATE CONSTRAINT c.
  • Full suites pass with no regressions: sqlparser_postgres (180) and sqlparser_common (471).

Why

Unblocks dsql-lint (awslabs/aurora-dsql-tools) from upgrading its VALIDATE CONSTRAINT rule from "guide to ASYNC" to full auto-fix + clean-pass of the valid ALTER TABLE ASYNC form, matching how CREATE INDEX ASYNC is handled. Part of the DSQL VALIDATE CONSTRAINT ASYNC ecosystem rollout (agent-plugins, mcp, aurora-dsql-orms, aurora-dsql-tools).


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

Aurora DSQL runs certain ALTER TABLE operations as asynchronous DDL jobs
via the ALTER TABLE ASYNC form, e.g.
  ALTER TABLE ASYNC t VALIDATE CONSTRAINT c
which returns a job_id and validates existing rows in the background
(same async DDL model as CREATE INDEX ASYNC).

Add an `async` flag to the AlterTable AST node, parse an optional ASYNC
keyword immediately after TABLE (before IF EXISTS / ONLY), and render it
in Display. Non-async ALTER TABLE is unchanged.

- ast/ddl.rs: AlterTable.async field + Display
- parser/mod.rs: parse_alter_table parses optional ASYNC
- dialect/snowflake.rs: set async: false at the two AlterTable sites
- tests/sqlparser_postgres.rs: async VALIDATE CONSTRAINT round-trip,
  incl. ASYNC + IF EXISTS + ONLY

Exact round-trip verified; full postgres (180) and common (471) suites pass.
@amaksimo
amaksimo merged commit 990b80a into amaksimo:dsql-async-index Aug 3, 2026
3 of 10 checks passed
amaksimo added a commit that referenced this pull request Aug 3, 2026
The merged ALTER TABLE ASYNC PR (#2) added AlterTable.r#async but missed
this fully-destructured pattern (no ..), leaving `cargo test` broken.
Published crate excludes tests so 0.62.2 uploads fine; this keeps the
branch green.
amaksimo added a commit to awslabs/aurora-dsql-tools that referenced this pull request Aug 3, 2026
> [!NOTE]
> **Dependency published — unblocked.** `sqlparser-dsql 0.62.2` (adds
`ALTER TABLE ASYNC` parsing) is live on crates.io. Parser PR:
amaksimo/datafusion-sqlparser-rs#2. Full suite
builds and passes against it (115 unit tests + fix/integration/snapshot
suites, 0 failures).

## Summary

Follow-up to #112. That PR made `VALIDATE CONSTRAINT` emit a
guidance-only `Unfixable` diagnostic because the parser couldn't
represent the `ALTER TABLE ASYNC` form. With parser support in place,
this upgrades the `ValidateConstraintAsync` rule to a real **auto-fix**,
matching how `CREATE INDEX ASYNC` is handled.

## Behavior

- `ALTER TABLE t VALIDATE CONSTRAINT c` (no ASYNC) → `FixedWithWarning`;
the fix rewrites to `ALTER TABLE ASYNC t VALIDATE CONSTRAINT c`.
- `ALTER TABLE ASYNC t VALIDATE CONSTRAINT c` now lints **clean**.

The `async` flag lives on the `AlterTable` statement (not the
operation), so the fix is captured during the per-op scan and applied to
the statement after the loop. The warning tells users validation runs as
a background DDL job (wait via `sys.jobs`; can still fail on dirty
data).

## Changes

- `src/rules/errors.rs`: auto-fix logic for `ValidateConstraintAsync`.
- `tests/`: `FIX_TIER` + `SNAPSHOT` cases (`validate-constraint-async`)
and a clean-pass test for the ASYNC form.
- `Cargo.toml`: bump `dsql-lint` `0.2.12` → `0.2.13`; require
`sqlparser-dsql` `0.62.2` (kept the `visitor` feature added on main).
Merged `main` and resolved the `Cargo.toml` conflict (0.2.12 shipped on
main in the meantime, hence 0.2.13).

## Testing

Verified locally against the parser branch via a temporary
`[patch.crates-io]` (**not committed**): full suite green — 115 unit
tests + fix/integration/snapshot suites, 0 failures. CI here will fail
to build until `sqlparser-dsql 0.62.2` is on crates.io.

## Rollout dependency chain

1. Parser: amaksimo/datafusion-sqlparser-rs#2 →
publish `sqlparser-dsql 0.62.2`
2. **This PR** (bump pin + auto-fix)

Part of the DSQL `VALIDATE CONSTRAINT ASYNC` ecosystem rollout
(agent-plugins #238, mcp #4300, aurora-dsql-orms #528, aurora-dsql-tools
#112).

---

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of the
[project
license](https://github.com/awslabs/aurora-dsql-tools/blob/main/LICENSE).

Co-authored-by: Aleksandar Maksimovic <amaksimovic3@hotmail.com>
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.

2 participants