Skip to content

fluree ontology from a semantic layer: Snowflake semantic views and Genie exports - #2213

Merged
aaj3f merged 3 commits into
mainfrom
feat/ontology-from-semantic-layer
Nov 3, 2026
Merged

aaj3f merged 3 commits into
mainfrom
feat/ontology-from-semantic-layer

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Stacked on #2210 (base feat/ontology-from-tables, so the diff is just the third commit). This teaches fluree ontology from to 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:

  • tables' description and synonyms are copied ("People and clubs who buy from the shops. Also called: riders, clients.");
  • dimensions, time_dimensions, facts (and measures) become properties typed from data_type (TIMESTAMP_NTZ → xsd:dateTime, NUMBER(10,2) → xsd:decimal, via the same type table the DDL reader uses, now sql::xsd_for);
  • a dimension with is_enum: true and sample_values is enumerated. Sample values alone are just samples, so they don't enumerate on their own;
  • each relationship is 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_ID in orders_to_customers → "customer") rather than for the relationship's name ("orders to customers"), which reads more like a join than a relation;
  • metrics, filters and verified_queries describe queries rather than things and are left out.

Databricks Genie space exports, as .json (detected by data_sources / serialized_space, so any other .json is still JSON-LD): tables and metric views from data_sources, columns from column_configs, and join_specs parsed from their `alias`.`column` SQL. The export doesn't carry descriptions (those live in Unity Catalog), so --comments uc_comments.json takes {"table": {"": "table comment", "column": "column comment"}}, and the command nudges you on stderr when it's missing. Genie declares no keys, so id / <table>_id are 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:

  • a foreign key named for a code or number (HIRE_CODE into PRODUCTS) now takes the target's label ("product") instead of the leftover word ("hire"); _id/_key/_fk/_ref are still stripped (employer_id → "employer");
  • a relation several tables share (account from 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;
  • generated descriptions use "an" before a vowel ("The customer of an order.");
  • the Turtle prefix for minted IRIs is named for the --base namespace (shop: for https://example.com/shop/) rather than the input file's name;
  • --input-format on from now names every source (turtle, jsonld, csv, xlsx, sql, snowflake, genie).

serde-saphyr 1.3 (deserialize feature 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 at serde_yaml_ng (MIT only, last release 2024) and serde_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-cli and cargo clippy -p fluree-db-ontology -p fluree-db-cli --all-targets --no-deps are clean locally; full CI will run once the stack is rebased onto main.

🤖 Generated with Claude Code

https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX

…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
@aaj3f aaj3f added enhancement New feature or request area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows labels Oct 29, 2026
@aaj3f
aaj3f marked this pull request as ready for review October 29, 2026 21:04
@aaj3f
aaj3f requested a review from bplatz October 29, 2026 21:04

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +114 to +115
let doc: Value =
serde_saphyr::from_str(yaml).map_err(|e| SemanticError::Yaml(e.to_string()))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, ON or OFF is 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 .inf fails 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread fluree-db-ontology/src/convert/mod.rs Outdated
Comment on lines +104 to +111
// `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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +300 to +304
let sql = strings(j, "sql").join(" ");
let columns = alias_columns(&sql, &left_alias)
.into_iter()
.zip(alias_columns(&sql, &right_alias))
.collect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.id is made to reference orders, and since it's a key it's left out;
  • orders.customer_id is 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +92 to +95
// 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));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_NOTES lost LINE_NO, and its ORDER_ID → ORDERS relation was overwritten.
  • Joins naming an unknown table, Genie join SQL without backticks, and --comments entries that match nothing are skipped with no count.

Reporting these in the notes would make them visible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@aaj3f

aaj3f commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

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. code_named_keys_keep_their_words covers code-FK labelling, the shared-relation description ("The account of a contact, order or invoice.") and "a"/"an", and the_prefix_is_named_for_the_namespace in the CLI covers the prefix taken from --base (it caught a real bug where a urn:acme:crm: base fell back to ex).

Base automatically changed from feat/ontology-from-tables to main November 2, 2026 22:10
@aaj3f
aaj3f merged commit 2494182 into main Nov 3, 2026
19 checks passed
@aaj3f
aaj3f deleted the feat/ontology-from-semantic-layer branch November 3, 2026 14:29
bplatz added a commit that referenced this pull request Nov 4, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants