---
phase: 11.1-review-possible-ddl-and-query-syntax-options-and-bring-it-as-close-as-we-can-to-snowflake-semantic-views
plan: "04"
subsystem: database
tags: [rust, ddl, vscalar, semantic-views, rename]

requires:
  - phase: 11.1-02
    provides: "parse_define_args(), ParsedDefineArgs"
  - phase: 11.1-03
    provides: "expand.rs JOIN codegen and table-qualified name resolution"

provides:
  - "DefineSemanticView::signatures() returns 6-arg LIST(STRUCT) positional signature"
  - "DefineSemanticView::invoke() calls parse_define_args + serde_json::to_string"
  - "DuckDB function registered as 'semantic_view' (renamed from 'semantic_query')"

affects:
  - "11.1-05 (test files must use new DDL syntax and semantic_view function name)"

tech-stack:
  added: []
  patterns:
    - "LogicalTypeHandle::list(&LogicalTypeHandle::struct_type(&[...])) for LIST(STRUCT) type construction"
    - "let varchar = || LogicalTypeHandle::from(LogicalTypeId::Varchar); closure for readable type declarations"
    - "parse_define_args(input, i).map_err(|e| Box::<dyn std::error::Error>::from(e))? pattern"

key-files:
  created: []
  modified:
    - "src/ddl/define.rs"
    - "src/lib.rs"

key-decisions:
  - "signatures() builds all type handles inline using closure for readability — no named constants"
  - "invoke() delegates all parsing to parse_define_args; only serialization + persistence remain in define.rs"
  - "Only the DuckDB registered name changes in lib.rs — Rust type SemanticViewVTab and QueryState are unchanged"

patterns-established:
  - "parse_define_args call pattern: parse_define_args(input, i).map_err(|e| Box::<dyn std::error::Error>::from(e))?"

requirements-completed:
  - DDL-03
  - DDL-04
  - DDL-05

duration: 8min
completed: 2026-03-02
---

# Phase 11.1 Plan 04: Wire parse_args into define.rs + Rename semantic_query → semantic_view Summary

**DefineSemanticView updated to 6-arg LIST(STRUCT) signature; semantic_view registered (renamed from semantic_query)**

## Performance

- **Duration:** 8 min
- **Started:** 2026-03-02T00:50:00Z
- **Completed:** 2026-03-02T00:58:00Z
- **Tasks:** 2
- **Files modified:** 2

## Accomplishments
- Rewrote `DefineSemanticView::signatures()` to return a 6-arg `ScalarFunctionSignature::exact()` with:
  - arg 0: VARCHAR (view name)
  - arg 1: `LIST(STRUCT(alias VARCHAR, table VARCHAR))`
  - arg 2: `LIST(STRUCT(from_table VARCHAR, to_table VARCHAR, join_columns LIST(STRUCT(from, to))))`
  - arg 3: `LIST(STRUCT(name VARCHAR, expr VARCHAR, source_table VARCHAR))` — dimensions
  - arg 4: `LIST(STRUCT(name VARCHAR, expr VARCHAR, granularity VARCHAR))` — time_dimensions
  - arg 5: `LIST(STRUCT(name VARCHAR, expr VARCHAR, source_table VARCHAR))` — metrics
- Rewrote `DefineSemanticView::invoke()` to call `parse_define_args(input, i)` then `serde_json::to_string(&parsed.def)` for catalog persistence
- Renamed the registered DuckDB table function from `"semantic_query"` to `"semantic_view"` in lib.rs (2 references: comment + registration string)
- `cargo check --features extension` passes with no errors or warnings

## Task Commits

1. **Task 1 + 2: Update define.rs signatures/invoke + lib.rs rename** - `6af183f` (feat)

## Files Created/Modified
- `src/ddl/define.rs` - New 6-arg signatures(), parse_define_args-based invoke()
- `src/lib.rs` - "semantic_view" registration (renamed from "semantic_query")

## Decisions Made
- All type handle construction stays in `signatures()` inline — no named constants needed given the closure pattern
- `invoke()` is now very clean: parse → serialize → persist → catalog → output
- Only the registration string changes in lib.rs — SemanticViewVTab and QueryState names are intentionally kept as-is

## Deviations from Plan

### Auto-fixed Issues

**1. [Rule 1 - Formatting] cargo fmt reformatted two expressions**
- **Found during:** Commit (pre-commit hook ran cargo fmt)
- **Issue:** `col_pair_struct` struct_type call and `parse_define_args` chain reformatted to shorter forms
- **Fix:** Applied `cargo fmt` explicitly before second commit attempt
- **Files modified:** src/ddl/define.rs
- **Verification:** Pre-commit hook passed on second attempt
- **Committed in:** 6af183f

---

**Total deviations:** 1 auto-fixed (formatting)
**Impact on plan:** None — only style changes.

## Issues Encountered
None

## Next Phase Readiness
- Rust code fully implements the new interface
- Only remaining work: update .test files to use new DDL syntax and `semantic_view` function name (Plan 11.1-05)

---
*Phase: 11.1-review-possible-ddl-and-query-syntax-options-and-bring-it-as-close-as-we-can-to-snowflake-semantic-views*
*Completed: 2026-03-02*
