Skip to content

Support current Hex Semantic Authoring YAML in hex adapter#202

Merged
nicosuave merged 6 commits into
mainfrom
update-hex-adapter
Jun 15, 2026
Merged

Support current Hex Semantic Authoring YAML in hex adapter#202
nicosuave merged 6 commits into
mainfrom
update-hex-adapter

Conversation

@nicosuave

Copy link
Copy Markdown
Member

Updates the Hex import/export adapter (sidemantic/adapters/hex.py) to handle the current Hex Semantic Authoring YAML schema (post-Aug-2025), which the adapter previously broke on, while keeping legacy single-document files working.

What changed

  • type: discriminator — every current Hex resource carries a top-level type: (model / view). The adapter now dispatches on it. Untyped legacy documents default to model, so existing single-doc fixtures keep parsing.
  • Multi-document files — a single file can contain multiple resources separated by ---. Parsing switched from yaml.safe_load (which silently dropped everything after the first divider) to yaml.safe_load_all.
  • view resource typetype: view with base (target model id) and contents (selection groups) is now parsed. Sidemantic has no native view concept, so the view structure is preserved on model metadata and round-trips back to a type: view resource on export.
  • semi_additive measures — the current object form (over: [{dimension, pick}] with optional groupings) maps to Sidemantic's non_additive_dimension.
  • Display namename on models/dimensions/measures maps to the Sidemantic display label.
  • visibilitypublic / internal / private on models, dimensions, and measures is recorded in metadata and reflected in the public flag (only public stays visible).

Export emits the type discriminator, display names, visibility, and the object-form semi_additive back to current Hex YAML.

Tests and fixtures

  • Added a typed, multi-document fixture (tests/fixtures/hex/subscriptions_project.yml) containing a model and a view, plus tests/adapters/hex/test_typed_resources.py covering parsing, the view resource, labels, visibility, semi-additive, and import/export round-trips.
  • Updated saas_analytics.yml and product_events.yml to the current typed + object-form semi_additive shape and un-xfailed the semi_additive and visibility tests.
  • Legacy single-doc fixtures and all existing tests remain green.

Verified against the Hex learn.hex.tech semantic-models modeling specification.

Known limitations

  • A view is imported as a metadata-bearing, field-less model (faithful round-trip), not expanded into a fully resolved model against its base.
  • visibility on relations is not mapped (the Relationship core type has no visibility field); it is scoped to models, dimensions, and measures.
  • Hex semi_additive.pick and groupings are preserved only insofar as the first over dimension maps to the single non_additive_dimension.

Update the Hex import adapter for the post-Aug-2025 schema while keeping
legacy single-document files working:

- Parse the top-level type: discriminator (model / view); untyped
  documents default to model for backward compatibility.
- Read multi-document files separated by --- via yaml.safe_load_all
  instead of dropping everything after the first divider.
- Add the view resource type (type: view with base + contents),
  preserved on model metadata and round-tripped back to type: view.
- Map measure semi_additive (object form with over/pick) to
  non_additive_dimension.
- Map dimension/measure name to display labels and visibility
  (public/internal/private) to public + meta on models, dimensions,
  and measures.
- Export the type discriminator, names, visibility, and semi_additive
  back to current Hex YAML.

Add a typed multi-document fixture plus tests, and un-xfail the
semi_additive and visibility tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 815c0ee08e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sidemantic/adapters/hex.py Outdated
Hex measures using semi_additive.over[].pick (e.g. pick: min for
opening-balance snapshots) or groupings previously only carried the
over dimension into Metric.non_additive_dimension. On export the adapter
re-emitted a minimal semi_additive: {over: [{dimension: ...}]} with no
pick, which the Hex spec defaults to max, silently changing the measure
semantics on import/export round-trips.

Stash the full object-form semi_additive config in measure meta on parse
and prefer it on export, so pick/groupings survive faithfully.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb643961cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sidemantic/adapters/hex.py
Comment thread sidemantic/adapters/hex.py
The CLI/MCP directory loader detected Hex only by single-document
yaml.safe_load plus a base_sql_table+measures heuristic. Current Hex
Semantic Authoring projects are multi-document (---separated) typed
resources, so safe_load raised before any Hex detection ran and
'sidemantic info' on a Hex project failed outright. Standalone exported
type: view files were also silently skipped because they have neither
base_sql_table nor measures.

Detect Hex explicitly: a multi-document fallback using safe_load_all and
a typed-resource check (type: model / type: view with an id) covering
both legacy and current forms. Exempt Hex view resources, which are
intentionally table-less presentation layers, from the physical-source
validation requirement so they register cleanly.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a1f084ef7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sidemantic/loaders.py Outdated
Recognize base_sql_query as well as base_sql_table when selecting the Hex
adapter so untyped query-backed Hex models load through load_from_directory
instead of being silently skipped on the CLI/MCP path.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afb3fb5661

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sidemantic/validation.py
Comment thread sidemantic/adapters/hex.py Outdated
Reduce an inline semi_additive.over[].dimension object to its id so the Hex
adapter no longer fails Pydantic validation on valid snapshot measures. Report
Hex view resources whose base reference is missing or names an unknown model
during directory validation instead of silently passing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 552eff3337

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sidemantic/validation_runner.py
Hex view resources require contents in addition to a base reference. Report a
view that omits contents during directory validation instead of silently
passing, since views are exempt from the physical-source check.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f63e9e591

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sidemantic/validation_runner.py
@nicosuave nicosuave merged commit 0bee417 into main Jun 15, 2026
20 checks passed
@nicosuave nicosuave deleted the update-hex-adapter branch June 15, 2026 13:52
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.

1 participant