Skip to content

ALTER COLLECTION x ADD COLUMN y rejected — router dispatcher missing branch #24

@hollanf

Description

@hollanf

Summary

ALTER COLLECTION x ADD COLUMN y ... is documented but rejected at parse time. The underlying handler exists — the router just doesn't dispatch to it for ALTER COLLECTION.

Zero-downtime schema evolution impossible on strict collections. Only workaround is DROP + CREATE + re-ingest (data loss unless caller has their own backup tooling).

Repro

CREATE COLLECTION memories TYPE DOCUMENT STRICT (
  id STRING PRIMARY KEY,
  name STRING NOT NULL
);

ALTER COLLECTION memories ADD COLUMN is_latest BOOL DEFAULT true;

Error:

parse error: sql parser error: Expected: one of VIEW or TYPE or TABLE or INDEX

Same error for every column type / default combination. ALTER TABLE memories ADD COLUMN is_latest BOOL DEFAULT true works on the same collection.

Expected

Per docs/documents.md:131:

ALTER COLLECTION orders ADD COLUMN region STRING DEFAULT 'us-east';

Root cause — dispatcher asymmetry

In src/control/server/pgwire/ddl/router/schema.rs:

  • Line 84 wires ALTER TABLE ... ADD COLUMNalter_table_add_column()
  • Lines 103–136 wire ALTER COLLECTION ... for OWNER, SET RETENTION, LAST_VALUE_CACHE, LEGAL_HOLD, SET APPEND_ONLY
  • No branch for ALTER COLLECTION ... ADD COLUMN

Statement falls through to DataFusion's sqlparser-rs, which only knows ALTER {TABLE,VIEW,TYPE,INDEX} — hence the misleading error list.

Handler at src/control/server/pgwire/ddl/collection/alter.rs:14-104 is already catalog-generic, so it would work for collections if the router reached it.

Special case ALTER COLLECTION ... ADD COLUMN ... AS MATERIALIZED_SUM is wired separately at router/collaborative.rs:58-63 — plain ADD COLUMN fell through the cracks.

Tests

tests/sql_transactions.rs:71-76 covers ALTER TABLE ... ADD COLUMN only. No test exercises the documented ALTER COLLECTION ... ADD COLUMN path.

Pointers

  • `src/control/server/pgwire/ddl/router/schema.rs:84`
  • `src/control/server/pgwire/ddl/router/schema.rs:103-136`
  • `src/control/server/pgwire/ddl/router/collaborative.rs:58-63`
  • `src/control/server/pgwire/ddl/collection/alter.rs:14-104`
  • `docs/documents.md:131`
  • `tests/sql_transactions.rs:71-76`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions