Skip to content

A definition can be written by hand - #563

Open
WaylandYang wants to merge 1 commit into
devfrom
feat/a-definition-can-be-written-by-hand
Open

A definition can be written by hand#563
WaylandYang wants to merge 1 commit into
devfrom
feat/a-definition-can-be-written-by-hand

Conversation

@WaylandYang

Copy link
Copy Markdown
Contributor

Closes #562. The capability cut; the page follows once #552 has landed (both touch Mappings.tsx).

A row in concept_mappings had exactly one way in: exploration proposes, a person confirms. A data team that already has its definitions — a metrics doc, the SQL behind last quarter's report — had nowhere to put them, and #520 measured what they are worth once they are in the prompt: 1 of 18 right answers without, 17 of 18 with, on the wide corpus. Exploration cannot fill that gap (0 of 18 there; it cannot see a convention that is not in the schema). This is the door.

What changes

  • POST /kbs/{id}/mappings (Editor): concept name, kind (metric / dimension, default metric), a mounted source by name, and the same table_name / expr / sql / unit / summary / derived the revise form takes. The row lands confirmed with the author in a new written_by column (migration 0046), so a written row and an exploration-proposed one stay distinguishable — decided_by cannot tell them apart, since a confirmed proposal has one too. Audit mapping.written.
  • POST /kbs/{id}/mappings/preview (Editor): render the definition (sql verbatim, else SELECT expr FROM table — the same rendering the bench scores with), run it through the read-only gate on its source, return the first row. The person sees the number before saving; the engine's error comes back verbatim when it does not run.
  • Validation shared with revise (definition_shape): at least one of table, expression, SQL. The source must be mounted (source_not_mounted). One definition per (concept, source): a second is a 409, since the existing row may be a confirmed proposal and overwriting it would erase a decision — revise instead. Exploration cannot clobber a written row either: propose only refreshes proposed rows, the same rule that protects a rejection.
  • ConceptMapping gains written_by; the three list queries return it.

The concept still becomes an entity of the builtin Metric / Dimension class, because that is the table's current shape. 0035 retires that shape (#556) and keeps the table, rendering into it, so a written SQL survives.

Verified

  • Unit: definition_shape, render_sql (sql wins and drops a trailing ;; table alone is not runnable).
  • DB test a_definition_can_be_written_by_hand: written row is confirmed with written_by; same key again is Conflict; a later propose on that key leaves it untouched; exploration's own rows have written_by = NULL.
  • End to end on a fresh base with the wide corpus mounted: preview of the GMV definition returns 32931921.08, the bench truth; a broken expression returns 422 with column "no_such_col" does not exist; create → 200 and the list shows the row confirmed / written; same key → 409; unmounted source → 422 source_not_mounted; no definition → 422 empty_mapping.

Does not touch Mappings.tsx (#552) or chat.rs (#548).

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: WaylandYang <wayland0916@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A definition can be written by hand

1 participant