Skip to content

Consume Flink TableChange in LanceCatalog#alterTable instead of inferring from SchemaDiff #79

Description

@fightBoxing

Discovered during architecture review of #76 (feat: primary-key upsert/delete + ALTER TABLE schema evolution). Follow-up: correctness hazard in the ALTER path that only surfaces on specific DDL sequences.

Context

LanceCatalog#alterTable(ObjectPath, CatalogBaseTable, boolean) receives
the new CatalogBaseTable only and infers the diff against the existing
Lance dataset schema using SchemaDiff.compute(oldRowType, newRowType).

Renames are reconstructed with a heuristic: if the diff contains exactly
N removed columns and N added columns at matching positions, they are
treated as N RENAME COLUMN operations.

Problems

  1. Cannot distinguish a true rename from a coincidentally
    position-aligned drop+add.
    If a user's DDL is
    DROP COLUMN a; ADD COLUMN b <same type> at the same position, the
    heuristic silently keeps a's data under the name b — a correctness
    hazard.
  2. Breaks under Flink's future ADD COLUMN AFTER col positioning
    semantics.
    Position-based matching is not stable across schema-
    evolution features Flink is already adding.
  3. Loses the user's original DDL wording, degrading error messages.

Proposed change

Override the TableChange-taking variant:

Catalog#alterTable(ObjectPath, CatalogBaseTable, List<TableChange>, boolean)

and dispatch directly on TableChange.AddColumn, DropColumn,
ModifyColumnName, ModifyPhysicalColumnType,
SetOption/ResetOption. Keep SchemaDiff only as a defensive fallback
for the deprecated code path; mark it @Deprecated internally.

Acceptance criteria

  • ALTER TABLE t RENAME COLUMN a TO b no longer routes through
    SchemaDiff.compute on the primary path.
  • Test: DROP COLUMN a; ADD COLUMN a <different type> in the same session
    verifies the drop actually happened (the heuristic today flags this as
    rename-with-type-change and refuses).
  • Existing LanceCatalogTableITCase assertions continue to pass.

Refs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions