Repository navigation
fluree ontology from a semantic layer: Snowflake semantic views and Genie exports - #2213
Conversation
…enie exports `fluree ontology from` reads a warehouse's semantic layer into the same table model as DDL, so the same rules apply: - a Snowflake semantic view or Cortex Analyst semantic model (.yaml/.yml, read with serde-saphyr): tables' descriptions and synonyms, dimensions, time dimensions and facts typed from data_type, is_enum dimensions with sample_values enumerated, relationships as foreign keys from the left column to the right table; metrics, filters and verified queries left out. A dbt semantic model is recognised and refused for now. - a Databricks Genie space export (.json with data_sources or serialized_space): tables, columns and join specs, with Unity Catalog's table and column comments from --comments. Keys follow the CSV rules. Also: a foreign key named for a code or number (HIRE_CODE) takes its target's label; a relation shared by several tables gets one description written for them all; generated descriptions use "an" before a vowel; the Turtle prefix comes from the --base namespace; --input-format names every source. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX
bplatz
left a comment
There was a problem hiding this comment.
Approving. Please go through the inline comments before merging. Three of them give wrong output on ordinary input: the YAML typing, the code/number foreign-key labels (which also change the DDL path from #2210), and the Genie join direction.
None of the shared-emitter changes has a unit test yet: code-FK labelling, shared-relation descriptions, "a"/"an", and the prefix taken from --base.
| let doc: Value = | ||
| serde_saphyr::from_str(yaml).map_err(|e| SemanticError::Yaml(e.to_string()))?; |
There was a problem hiding this comment.
Reading into an untyped Value applies YAML's implicit typing, and text()/strings() then drop or stringify whatever came back typed:
- a dimension named
NO,Y,ONorOFFis dropped without a note; sample_values: [GB, NO, SE, 007]gives records labelled "false" and "7.0";synonyms: [no, yes]become "false" and "true";- an unquoted
.inffails the whole file.
Deserializing into typed structs with String fields keeps these verbatim: serde-saphyr keeps NO, 01 and 1e3 as written when the target is String. parse_document in #2215 also returns a Value, so dbt's accepted_values and Ossie documents go through the same typing.
There was a problem hiding this comment.
Agreed, and thanks for checking what serde-saphyr does with String targets. Fixed in a12ae5f: Snowflake views are read into typed structs (a shared from_yaml, with duplicate keys last-wins as PyYAML does), so NO, 007, .inf and synonyms: [no, yes] come through as written. yaml_values_are_kept_as_written covers each case. dbt and Ossie got the same treatment in #2215 (33e25f8).
| // `hire code` is the product's code, not a role: a key named for a code | ||
| // or number has no label of its own, and takes its target's | ||
| if ["code", "no", "num", "number"] | ||
| .iter() | ||
| .any(|suffix| words.ends_with(&format!(" {suffix}")) || words == *suffix) | ||
| { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
This collapses distinct relations into one. origin_airport_code and destination_airport_code, both REFERENCES airports, used to be "origin airport" and "destination airport". Now both are labelled "airport", share the fk:airport:… key, and come out as a single property ("The airport of a flight."). The same happens to from_/to_currency_code and bill_to_/ship_to_customer_number, and employer_no REFERENCES accounts loses "employer". I'd strip the suffix as before and take the target's label only when nothing is left, and never merge two columns of the same table into one property.
There was a problem hiding this comment.
You're right, I'd traded a cosmetic win (HIRE_CODE → "product") for silently merging real relations, which is the worse failure. Reverted to your rule in a12ae5f: strip the suffix (now including number) and use the target's label only when nothing is left. With the emitter change from #2210, two columns of one table never become one property. code_named_keys_keep_their_words covers origin/destination airport codes.
| let sql = strings(j, "sql").join(" "); | ||
| let columns = alias_columns(&sql, &left_alias) | ||
| .into_iter() | ||
| .zip(alias_columns(&sql, &right_alias)) | ||
| .collect(); |
There was a problem hiding this comment.
The join's relationship type is ignored, and left is always taken as the many side. With --rt=FROM_RELATIONSHIP_TYPE_ONE_TO_MANY--, left=customers and right=orders:
customers.idis made to reference orders, and since it's a key it's left out;orders.customer_idis pushed into orders' primary key, so it's left out too.
No relation comes out at all. For MANY_TO_MANY, the right table's column becomes a key. Parsing the --rt= marker, swapping sides for ONE_TO_MANY and adding no key for MANY_TO_MANY would fix it. There's only a MANY_TO_ONE test today.
There was a problem hiding this comment.
Fixed in a12ae5f: the --rt= marker is parsed. ONE_TO_MANY swaps the sides, MANY_TO_MANY makes the relation but no key, and MANY_TO_ONE/ONE_TO_ONE stay as they were. genie_join_types covers ONE_TO_MANY and MANY_TO_MANY. (Snowflake's relationship_type gets the same handling.)
| continue; | ||
| }; | ||
| table.columns.push(Column { | ||
| description: text(c, "description").or_else(|| comment(&name, &column)), |
There was a problem hiding this comment.
Worth checking against a real export. As far as I know, text fields in serialized_space are string arrays (as sql already is in the fixture), so "description": ["…"] on tables and column_configs would be dropped by text(). Column synonyms aren't read either, and exclude: true columns aren't skipped. I also think column_configs only lists columns that have settings, in which case the rest of a table's columns would be silently missing.
There was a problem hiding this comment.
I don't have a real export to check against, so I made the reader accept both shapes, in a12ae5f: text fields can be a string or a list of strings, column synonyms are read, exclude: true columns are skipped (and counted), and columns that appear in --comments but not in column_configs are added (and counted), which covers the "only columns with settings" case when UC comments are passed. I'd still like to run it against a real export before launch if you have one handy.
| // the other columns of a composite key are part of the same relation | ||
| for (other, _) in join.columns.iter().skip(1) { | ||
| t.columns.retain(|c| !c.name.eq_ignore_ascii_case(other)); | ||
| } |
There was a problem hiding this comment.
A few silent drops here:
- The other columns of a composite join are removed from the table (
retain). - A column holds only one
references, so a later composite join overwrites an earlier relation. In a probe,LINE_NOTESlostLINE_NO, and itsORDER_ID → ORDERSrelation was overwritten. - Joins naming an unknown table, Genie join SQL without backticks, and
--commentsentries that match nothing are skipped with no count.
Reporting these in the notes would make them visible.
There was a problem hiding this comment.
Fixed in a12ae5f: a composite join keeps its other columns, and a second join on a column that already references another table becomes its own relation (named for the table it reaches) instead of overwriting the first. Joins naming unknown tables, Genie join SQL with no backticked pairs, and --comments tables that match nothing are all counted in the notes on stderr. Covered by composite_and_repeated_joins_drop_nothing and the Genie tests.
…its review follow-ups The merge takes the tables PR's emitter (never merge two source names, count every drop) and puts this branch's relation descriptions on it: a relation's generated description is written once every table that uses it is known, with "a"/"an" by the word. Review follow-ups for this branch: - Foreign keys named for a code or number keep their words again (`origin_airport_code` "origin airport", `employer_no` "employer"); the target's label stands in only when nothing is left. With the emitter's rule, two columns of one table are never one property. - Snowflake YAML is read into typed fields (from_yaml), so `NO`, `007`, `.inf` and synonyms like `no`/`yes` are kept as written rather than typed by YAML; duplicate keys keep the last value, as PyYAML does. - Genie: joins follow their `--rt=` relationship type (one-to-many turned round, many-to-many makes no key); text fields may be strings or lists of strings; column synonyms are read and excluded columns skipped; columns named in --comments that the export doesn't list are added. - Nothing is dropped silently: a composite join keeps its other columns, a second join on one column becomes its own relation instead of overwriting the first, and joins to unknown tables, join SQL with no `alias`.`column` pairs and unmatched comments are counted in notes. - A JSON-LD document is never read as a Genie export. - Tests for the shared-emitter changes: code-named key labels, shared relation descriptions, "a"/"an", and the prefix named for --base (which caught a namespace ending in `:` falling back to `ex`). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX
|
Thanks @bplatz! The three wrong-output ones (YAML typing, code/number FK labels, Genie join direction) and the other two inline comments are fixed in a12ae5f, with replies on each. On the emitter tests: those are in now, too. |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gr44LtZux3gFaK3fGq4R6
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmQLwTu67J9hjS5nwrh
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255, #2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210, #2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next. Resolutions: - Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the dictionary's coverage watermark sit on next's graph slots and per-graph OrdMaps. A commit's reification links count toward coverage. Planner stats from segment sums decline under annotations, whose link deltas only the walk counts, and otherwise carry the indexed link counts. - Stats-view identity: the index root's id reaches the snapshot through next's root decoder (`decode` takes the id, as `take_snapshot_metadata` does). `LedgerState::load_record` has a decoding-root form beside `load_decoding_root`. - Transact: #2184's parallel-relationship check runs in next's link cascade, counting the `rdf:reifies` links on the retracted edge that the transaction does not retract itself. Main's bundle `edge_reifiers` is dropped, and `subjects_with_prior_rows` and `enforce_single_target_reifiers` stay deleted. The upsert pre-check takes main's dictionary probe and bounded seek. - Query: geo search resolves the graph's POST tree once at open (pooled graphs keep their filter), an empty manifest when there is none. `branch_or_none` reads the dedicated branch, and the batched joins keep next's pooled lanes. The stats-view key hashes the root id. - Indexer: `apply_dict_novelty` and `compact_forward_streams` take the cycle's compaction budget, so the term dictionary keeps its reserved share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit` rewrites next's 20-byte types records. - Disk cache: main's in-flight write registration, with an empty entry still read as crash debris that a write replaces. The process-wide eviction walk stays removed. - Graph import (#2232): fenced CAS and publishes, the seed carries the record's namespace and fence, 32-bit graph ids and next's loaders. An import into a graph of an existing ledger refuses triple terms and edge annotations: the splice merges no triple-term dictionary yet. - Iceberg: `create_iceberg_graph_source` goes with main (a source needs a mapping); the R2RML path keeps next's `model_instance`. - CLI: main's shared import flags without the leaflet flags; `graph import` routes through next's process-wide server routing, and `upload_source_import` serves next's `Destination`. Doc sources read a ledger through the command's open instance. - Tests: sibling ledger ids become distinct names, `genesis_ledger` is awaited, Cypher state dumps include each relationship's `rdf:reifies` link, and the graph-import arena test checks the refusal instead.
Stacked on #2210 (base
feat/ontology-from-tables, so the diff is just the third commit). This teachesfluree ontology fromto read a warehouse's semantic layer, which is really just a richer data dictionary, into the same table model DDL and CSVs use, so all the same rules apply (labels in words, IRIs from labels, foreign keys as relations, enumerated columns as a class with records, keys/metrics/SQL left out).Snowflake semantic views (and Cortex Analyst semantic models), as
.yaml/.yml:descriptionandsynonymsare copied ("People and clubs who buy from the shops. Also called: riders, clients.");dimensions,time_dimensions,facts(andmeasures) become properties typed fromdata_type(TIMESTAMP_NTZ→xsd:dateTime,NUMBER(10,2)→xsd:decimal, via the same type table the DDL reader uses, nowsql::xsd_for);is_enum: trueandsample_valuesis enumerated. Sample values alone are just samples, so they don't enumerate on their own;relationshipis a foreign key from its left column to the right table, and the right column is a key of its table, so it's left out. I went with labelling the relation for the column (CUSTOMER_IDinorders_to_customers→ "customer") rather than for the relationship's name ("orders to customers"), which reads more like a join than a relation;metrics,filtersandverified_queriesdescribe queries rather than things and are left out.Databricks Genie space exports, as
.json(detected bydata_sources/serialized_space, so any other.jsonis still JSON-LD): tables and metric views fromdata_sources, columns fromcolumn_configs, andjoin_specsparsed from their`alias`.`column`SQL. The export doesn't carry descriptions (those live in Unity Catalog), so--comments uc_comments.jsontakes{"table": {"": "table comment", "column": "column comment"}}, and the command nudges you on stderr when it's missing. Genie declares no keys, soid/<table>_idare treated as keys the same way CSVs are.A dbt semantic model (
semantic_models:) is recognised and refused with a clear message for now; that's the next PR.A few things I changed in the shared emitter while running this against a realistic semantic view (10 tables, 9 relationships, 6 enumerated dimensions), since they affect the DDL/CSV paths too:
HIRE_CODEintoPRODUCTS) now takes the target's label ("product") instead of the leftover word ("hire");_id/_key/_fk/_refare still stripped (employer_id→ "employer");accountfrom contacts, bookings, quotes and deliveries) gets one generated description written for all of them ("The account of a contact, booking, quote or delivery.") instead of whichever table came first;--basenamespace (shop:forhttps://example.com/shop/) rather than the input file's name;--input-formatonfromnow names every source (turtle,jsonld,csv,xlsx,sql,snowflake,genie).serde-saphyr1.3 (deserializefeature only) is the new dependency: pure Rust, panic-free parsing (worth it for user-supplied files), MIT OR Apache-2.0, released 2026-09-16. I looked atserde_yaml_ng(MIT only, last release 2024) andserde_norway(an unsafe-libyaml fork, last release 2024) and preferred this one.Docs:
docs/cli/ontology.md's "From tables" section is now "From tables and semantic layers";docs/cli/catalog.md's example follows the prefix change. Tests use synthetic fixtures (a small bike-shop semantic view and Genie space).cargo test -p fluree-db-ontology -p fluree-db-cliandcargo clippy -p fluree-db-ontology -p fluree-db-cli --all-targets --no-depsare clean locally; full CI will run once the stack is rebased onto main.🤖 Generated with Claude Code
https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX