---
phase: 34.1-close-ddl-gaps-vs-snowflake
plan: 01
subsystem: ddl
tags: [alter, rename, parser, vtab, catalog]

# Dependency graph
requires:
  - phase: 34
    provides: DuckDB 1.5.0 parser hook infrastructure
provides:
  - ALTER SEMANTIC VIEW ... RENAME TO DDL verb
  - ALTER SEMANTIC VIEW IF EXISTS ... RENAME TO DDL verb
  - catalog_rename() function for atomic in-memory rename
  - persist_rename() for catalog table persistence
  - AlterRenameVTab table function
affects: [34.1-02, 34.1-03, documentation, registry-publishing]

# Tech tracking
tech-stack:
  added: []
  patterns: [two-argument VTab pattern for ALTER RENAME]

key-files:
  created:
    - src/ddl/alter.rs
    - test/sql/phase34_1_alter_rename.test
  modified:
    - src/parse.rs
    - src/catalog.rs
    - src/ddl/mod.rs
    - src/lib.rs
    - tests/parse_proptest.rs
    - test/sql/TEST_LIST

key-decisions:
  - "AlterRename reuses DropState pattern (persist_conn + if_exists bool) for consistency"
  - "persist_rename uses DELETE + INSERT (not UPDATE) to match persist_drop pattern"
  - "catalog_rename atomically removes old name and inserts new name with rollback on conflict"

patterns-established:
  - "Two-argument VTab pattern: AlterRenameVTab takes (old_name, new_name) positional parameters"
  - "ALTER prefix detection uses longest-first ordering (IF EXISTS before bare ALTER)"

requirements-completed: [DDL-01, DDL-02]

# Metrics
duration: 10min
completed: 2026-03-22
---

# Phase 34.1 Plan 01: ALTER SEMANTIC VIEW RENAME TO Summary

**ALTER SEMANTIC VIEW ... RENAME TO DDL with parser detection, catalog mutation, persistence, and 8 sqllogictest scenarios**

## Performance

- **Duration:** 10 min
- **Started:** 2026-03-22T12:38:57Z
- **Completed:** 2026-03-22T12:48:37Z
- **Tasks:** 2
- **Files modified:** 8

## Accomplishments
- Implemented ALTER SEMANTIC VIEW ... RENAME TO and IF EXISTS variants as new DDL verbs
- Added catalog_rename() with atomic in-memory rename and rollback on conflict
- Created AlterRenameVTab with persist_rename() following established VTab pattern
- Comprehensive sqllogictest coverage: basic rename, round-trip, errors, IF EXISTS no-op, case insensitivity

## Task Commits

Each task was committed atomically:

1. **Task 1: Add ALTER RENAME parser detection, catalog function, and VTab** - `a6240a5` (feat)
2. **Task 2: Add sqllogictest coverage for ALTER RENAME** - `3df769d` (test)

## Files Created/Modified
- `src/ddl/alter.rs` - AlterRenameVTab, AlterRenameState, persist_rename (new)
- `src/parse.rs` - AlterRename/AlterRenameIfExists DdlKind variants, prefix detection, rewrite, validation
- `src/catalog.rs` - catalog_rename() function with rollback, 3 unit tests
- `src/ddl/mod.rs` - pub mod alter declaration
- `src/lib.rs` - Registration of alter_semantic_view_rename and _if_exists table functions
- `tests/parse_proptest.rs` - Updated build_suffix for new DdlKind variants
- `test/sql/phase34_1_alter_rename.test` - 8 test scenarios for ALTER RENAME
- `test/sql/TEST_LIST` - Added phase34_1_alter_rename.test

## Decisions Made
- AlterRename reuses DropState pattern (persist_conn + if_exists bool) for consistency with existing VTabs
- persist_rename uses DELETE + INSERT (not UPDATE on name column) to match persist_drop pattern
- catalog_rename atomically removes old name and inserts new name, rolling back on new_name conflict
- DDL_PREFIXES updated from 7 to 9 entries for near-miss detection support

## Deviations from Plan

### Auto-fixed Issues

**1. [Rule 1 - Bug] Fixed sqllogictest DDL syntax**
- **Found during:** Task 2
- **Issue:** Plan used `:=` assignment syntax which is not valid in CREATE SEMANTIC VIEW DDL body. The correct syntax is `alias.name AS expr`.
- **Fix:** Changed `order_id := orders.id` to `orders.order_id AS id` and similar
- **Files modified:** test/sql/phase34_1_alter_rename.test
- **Verification:** `just test-sql` passes
- **Committed in:** 3df769d (Task 2 commit)

**2. [Rule 1 - Bug] Fixed statement error test format**
- **Found during:** Task 2
- **Issue:** sqllogictest parser requires `statement error` to have an expected error message after `----`
- **Fix:** Added expected error message patterns for Tests 6 and 7
- **Files modified:** test/sql/phase34_1_alter_rename.test
- **Verification:** `just test-sql` passes
- **Committed in:** 3df769d (Task 2 commit)

**3. [Rule 3 - Blocking] Updated parse_proptest.rs for new DdlKind variants**
- **Found during:** Task 1
- **Issue:** `build_suffix` match in `tests/parse_proptest.rs` was non-exhaustive with new AlterRename variants (and parallel agent's ShowDimensions/ShowMetrics/ShowFacts)
- **Fix:** Added match arms for AlterRename, AlterRenameIfExists, ShowDimensions, ShowMetrics, ShowFacts
- **Files modified:** tests/parse_proptest.rs
- **Verification:** `cargo test` passes
- **Committed in:** a6240a5 (Task 1 commit)

---

**Total deviations:** 3 auto-fixed (2 bug, 1 blocking)
**Impact on plan:** All auto-fixes necessary for correctness. No scope creep.

## Issues Encountered
None beyond the auto-fixed deviations above.

## Known Stubs
None - all functionality is fully wired.

## User Setup Required
None - no external service configuration required.

## Next Phase Readiness
- ALTER SEMANTIC VIEW RENAME TO is fully functional and tested
- Ready for Plan 02 (SHOW SEMANTIC DIMENSIONS/METRICS/FACTS) and Plan 03 (verification)
- DdlKind enum now has 12 variants (9 original + 3 from parallel agent)

---
*Phase: 34.1-close-ddl-gaps-vs-snowflake*
*Completed: 2026-03-22*
