---
phase: 28-integration-testing-documentation
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - src/lib.rs
  - src/ddl/define.rs
  - src/ddl/mod.rs
  - src/ddl/parse_args.rs
  - src/parse.rs
autonomous: true
requirements: []

must_haves:
  truths:
    - "The extension compiles without DefineSemanticViewVTab or parse_args.rs"
    - "The 3 CREATE function DDL variants are no longer registered"
    - "The _from_json VTab variants still work (native DDL path is unbroken)"
    - "All non-CREATE functions (drop, describe, list, explain, semantic_view) still registered"
  artifacts:
    - path: "src/ddl/define.rs"
      provides: "DefineFromJsonVTab only (DefineSemanticViewVTab removed)"
      contains: "DefineFromJsonVTab"
    - path: "src/ddl/mod.rs"
      provides: "DDL module declarations without parse_args"
    - path: "src/lib.rs"
      provides: "Extension init without function DDL registrations"
  key_links:
    - from: "src/lib.rs"
      to: "src/ddl/define.rs"
      via: "DefineFromJsonVTab import (not DefineSemanticViewVTab)"
      pattern: "DefineFromJsonVTab"
    - from: "src/ddl/define.rs"
      to: "src/catalog.rs"
      via: "persist_define, catalog_insert, catalog_upsert still used by DefineFromJsonVTab"
      pattern: "persist_define"
---

<objective>
Remove the function-based CREATE DDL interface: `create_semantic_view()`, `create_or_replace_semantic_view()`, `create_semantic_view_if_not_exists()`.

Purpose: These function DDL variants are superseded by the native `CREATE SEMANTIC VIEW ... AS ...` DDL. Removing them simplifies the codebase and eliminates the dual-path maintenance burden. The `_from_json` VTab variants (backend for native DDL rewriting) are kept.

Output: Compiling extension with only the native DDL path for CREATE operations. All other functions unchanged.
</objective>

<execution_context>
@/Users/paul/.claude/get-shit-done/workflows/execute-plan.md
@/Users/paul/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/28-integration-testing-documentation/28-CONTEXT.md
@.planning/phases/28-integration-testing-documentation/28-RESEARCH.md

<interfaces>
<!-- Key types and contracts the executor needs. -->

From src/ddl/define.rs (KEEP these):
```rust
pub struct DefineState {
    pub catalog: CatalogState,
    pub persist_conn: Option<ffi::duckdb_connection>,
    pub or_replace: bool,
    pub if_not_exists: bool,
}
pub struct DefineBindData { name: String }
pub struct DefineInitData { done: AtomicBool }
fn persist_define(conn: ffi::duckdb_connection, name: &str, json: &str) -> Result<(), String>
pub struct DefineFromJsonVTab;  // KEEP
```

From src/ddl/define.rs (REMOVE these):
```rust
pub struct DefineSemanticViewVTab;  // REMOVE struct + impl VTab block
use crate::ddl::parse_args::parse_define_args_from_bind;  // REMOVE import
```

From src/lib.rs (REMOVE these 3 registration blocks):
```rust
con.register_table_function_with_extra_info::<DefineSemanticViewVTab, _>("create_semantic_view", &define_state)?;
con.register_table_function_with_extra_info::<DefineSemanticViewVTab, _>("create_or_replace_semantic_view", &define_or_replace_state)?;
con.register_table_function_with_extra_info::<DefineSemanticViewVTab, _>("create_semantic_view_if_not_exists", &define_if_not_exists_state)?;
```

From src/lib.rs (KEEP these 3 _from_json registration blocks -- they use the SAME DefineState instances):
```rust
con.register_table_function_with_extra_info::<DefineFromJsonVTab, _>("create_semantic_view_from_json", &define_state)?;
con.register_table_function_with_extra_info::<DefineFromJsonVTab, _>("create_or_replace_semantic_view_from_json", &define_or_replace_state)?;
con.register_table_function_with_extra_info::<DefineFromJsonVTab, _>("create_semantic_view_if_not_exists_from_json", &define_if_not_exists_state)?;
```

From src/parse.rs function_name():
```rust
fn function_name(kind: DdlKind) -> &'static str {
    match kind {
        DdlKind::Create => "create_semantic_view",              // dead code (rewrite_ddl rejects CREATE)
        DdlKind::CreateOrReplace => "create_or_replace_semantic_view",  // dead code
        DdlKind::CreateIfNotExists => "create_semantic_view_if_not_exists",  // dead code
        DdlKind::Drop => "drop_semantic_view",
        DdlKind::DropIfExists => "drop_semantic_view_if_exists",
        DdlKind::Describe => "describe_semantic_view",
        DdlKind::Show => "list_semantic_views",
    }
}
```
Note: function_name() is ONLY called by rewrite_ddl() which already rejects CREATE forms.
The CREATE arms are dead code but harmless. Remove them to keep the code honest -- change to
`DdlKind::Create | DdlKind::CreateOrReplace | DdlKind::CreateIfNotExists => unreachable!()`.
Wait -- rewrite_ddl() already returns an error for these. So function_name() is never called
with CREATE variants. The match arms can be removed (use unreachable!() or remove the arms
entirely with a wildcard). Actually, the safest approach: since rewrite_ddl() rejects these
before calling function_name(), just leave the match arms as-is OR change to unreachable!().
The compiler may warn about unreachable patterns after removing the function registrations
(it won't -- these are string returns, not type references). Keep it simple: leave as-is
or replace with unreachable!() at executor's discretion.
</interfaces>
</context>

<tasks>

<task type="auto">
  <name>Task 1: Remove function DDL registrations and imports from lib.rs</name>
  <files>src/lib.rs</files>
  <action>
In `src/lib.rs`, in the `init_extension` function:

1. Remove the `DefineSemanticViewVTab` from the import block (line ~291). Keep `DefineFromJsonVTab` and `DefineState` in the import.

2. Remove the 3 function DDL registration blocks (lines ~349-383):
   - The `create_semantic_view` registration block (define_state + register call)
   - The `create_or_replace_semantic_view` registration block (define_or_replace_state + register call)
   - The `create_semantic_view_if_not_exists` registration block (define_if_not_exists_state + register call)

3. KEEP the 3 `_from_json` registration blocks (lines ~385-402). These use the same `DefineState` instances (`define_state`, `define_or_replace_state`, `define_if_not_exists_state`).

CRITICAL: The `DefineState` variables (`define_state`, `define_or_replace_state`, `define_if_not_exists_state`) are STILL NEEDED by the `_from_json` registrations. Do NOT remove the variable declarations -- only remove the 3 lines that register `DefineSemanticViewVTab`.

4. Update the comment above the registration block (line ~349 "Register create_semantic_view...") to reflect the removal. The `_from_json` variants can inherit the comments about what DefineState does.

After this change, `DefineSemanticViewVTab` should have zero references in `lib.rs`.
  </action>
  <verify>
    <automated>cd /Users/paul/Documents/Dev/Personal/duckdb-semantic-views && cargo check --features extension 2>&1 | tail -5</automated>
  </verify>
  <done>lib.rs compiles without DefineSemanticViewVTab import, 3 function DDL registrations removed, 3 _from_json registrations intact</done>
</task>

<task type="auto">
  <name>Task 2: Remove DefineSemanticViewVTab from define.rs, delete parse_args.rs, clean up mod.rs</name>
  <files>src/ddl/define.rs, src/ddl/parse_args.rs, src/ddl/mod.rs, src/parse.rs</files>
  <action>
Follow this exact removal order to avoid intermediate compile errors:

1. **src/ddl/define.rs:**
   - Remove the `use crate::ddl::parse_args::parse_define_args_from_bind;` import (line 11).
   - Remove the `use crate::expand::{expand, QueryRequest};` import (line 12) ONLY IF it has no other callers in this file. Check: `DefineFromJsonVTab::bind` also uses `crate::expand::expand` and `crate::expand::QueryRequest` but imports them with full paths (`crate::expand::QueryRequest`, `crate::expand::expand`). So the top-level import IS only used by `DefineSemanticViewVTab`. Remove it.
   - Remove the entire `DefineSemanticViewVTab` struct definition (line ~102: `pub struct DefineSemanticViewVTab;`).
   - Remove the entire `impl VTab for DefineSemanticViewVTab { ... }` block (lines ~104-244). This includes `bind`, `init`, `func`, `parameters`, `named_parameters`.
   - KEEP everything else: `DefineState`, `DefineBindData`, `DefineInitData`, `persist_define()`, `DefineFromJsonVTab` and its impl block.

2. **src/ddl/parse_args.rs:**
   - DELETE the entire file. It has no callers after `DefineSemanticViewVTab` is removed.

3. **src/ddl/mod.rs:**
   - Remove the line `pub mod parse_args;`.

4. **src/parse.rs** (optional cleanup):
   - In `function_name()`, the 3 CREATE arms (`DdlKind::Create`, `DdlKind::CreateOrReplace`, `DdlKind::CreateIfNotExists`) are dead code since `rewrite_ddl()` rejects CREATE forms before calling `function_name()`. Two options at executor's discretion:
     a. Replace with `unreachable!("CREATE forms handled by validate_and_rewrite")` (cleaner)
     b. Leave as-is (harmless dead code)
   - Either way is acceptable. If choosing (a), verify `cargo test` still passes (proptest references to `DdlKind::Create` etc. are in the parser detection tests, not function_name tests).

5. Verify no remaining references to `DefineSemanticViewVTab` or `parse_args`:
   - `cargo check --features extension` should pass
   - `cargo test` should compile and pass (unit tests)
  </action>
  <verify>
    <automated>cd /Users/paul/Documents/Dev/Personal/duckdb-semantic-views && cargo test 2>&1 | tail -10</automated>
  </verify>
  <done>DefineSemanticViewVTab removed from define.rs, parse_args.rs deleted, mod.rs updated, cargo test passes with zero references to removed code</done>
</task>

</tasks>

<verification>
After both tasks complete:
- `cargo check --features extension` compiles cleanly
- `cargo test` passes all unit + proptest tests
- `grep -r "DefineSemanticViewVTab" src/` returns no matches
- `grep -r "parse_args" src/` returns no matches (except possibly comments)
- The extension binary can be built with `just build`

Note: `just test-sql` and `just test-all` will FAIL at this point because SQL test files and Python integration tests still reference `create_semantic_view()`. This is expected -- Plan 02 fixes those tests.
</verification>

<success_criteria>
- Extension compiles with `cargo check --features extension`
- `cargo test` passes (all Rust unit tests and proptests)
- No source code references to `DefineSemanticViewVTab` or `parse_args` module
- `DefineFromJsonVTab` and all non-CREATE functions still operational
</success_criteria>

<output>
After completion, create `.planning/phases/28-integration-testing-documentation/28-01-SUMMARY.md`
</output>
