feat: OSI (Open Semantic Interchange) v0.1.1 compatibility#229
Draft
feat: OSI (Open Semantic Interchange) v0.1.1 compatibility#229
Conversation
Add bidirectional converter between BSL and OSI YAML format: - to_osi() / to_osi_yaml(): Export BSL models to OSI-compliant YAML - from_osi() / from_osi_yaml(): Import OSI YAML into BSL models - ai_context field on Dimension and Measure for LLM metadata - Expression translation between Ibis Deferred and SQL strings - BSL-specific metadata preserved via OSI custom_extensions - Round-trip tested: BSL->OSI->BSL and OSI->BSL->OSI Closes #226 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of a separate from_osi() conversion layer, from_config() now
auto-detects OSI format (version + semantic_model keys) and parses it
directly. This means from_yaml("model.osi.yaml") just works — BSL
natively speaks OSI.
- OSI parsing logic moved from osi.py into yaml.py
- osi.py slimmed to export-only (to_osi/to_osi_yaml) + expression helpers
- from_osi/from_osi_yaml kept as thin aliases to from_config/from_yaml
- Removed from_osi/from_osi_yaml from top-level __init__.py exports
- Tests updated to use from_config for OSI import (the native path)
- Added format detection tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…olumn joins Four fixes to make OSI import near-lossless: 1. primary_key -> is_entity: fields matching dataset.primary_key are automatically marked is_entity=True on import (no custom_extensions needed for standard OSI files) 2. Dataset-level ai_context: added to SemanticTableOp, threaded through to_semantic_table/SemanticModel/with_dimensions/with_measures. Stored as JSON string internally for ibis hashability, deserialized via get_ai_context(). Round-trips through to_osi export. 3. label on Dimension: new optional field, parsed on OSI import, emitted on export. Supports the OSI field.label categorization concept. 4. Multi-column relationship joins: all from_columns/to_columns pairs are now used to build compound join predicates, not just the first. All 56 OSI tests pass. Export validates against official OSI JSON schema. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
P1 fixes: - Calculated measures: extract formula from closure/original_expr instead of emitting the metric name as a self-reference - Join key export: introspect lambda predicates by evaluating against mock tables and walking the Equals expression tree to extract column names, instead of hardcoding ["unknown"] - Unqualified metrics (COUNT(*)): only assign to the first dataset instead of duplicating across all datasets in multi-dataset imports P2 fixes: - Relationship cardinality: read from custom_extensions and use join_many() when cardinality is "many" instead of always join_one() - Expression fallback: return None for non-trivial Ibis expressions instead of stripping "_." prefix which leaks method syntax as invalid SQL P3 fixes: - BSL YAML measure ai_context: pass extra_kwargs["ai_context"] through to Measure() constructor instead of silently dropping it Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds bidirectional conversion between BSL's YAML format and the OSI (Open Semantic Interchange) v0.1.1 spec, addressing #226.
New module
osi.pywith:to_osi()/to_osi_yaml()— export BSL models to OSI-compliant YAMLfrom_osi()/from_osi_yaml()— import OSI YAML into BSLSemanticModelinstancesKey design decisions:
_.col.sum()) are translated to SQL strings (SUM(col)) for OSIis_entity,is_event_timestamp,smallest_time_grain,derived_dimensions) preserved via OSIcustom_extensionsfor round-trip fidelityai_contextfield added toDimensionandMeasureclasses — supports both string and structured object (instructions/synonyms/examples) as per OSI specis_entity=True) automatically map to OSIprimary_keydimension.is_timeWhat's included
src/boring_semantic_layer/osi.pysrc/boring_semantic_layer/ops.pyai_contexttoDimension/Measure; threaded through_extract_measure_metadata/_make_base_measuresrc/boring_semantic_layer/yaml.pyai_contextfrom BSL YAML configssrc/boring_semantic_layer/__init__.pysrc/boring_semantic_layer/tests/test_osi.pyexamples/flights_osi.yamldocs/osi-compatibility.mdGaps remaining for full OSI parity
ai_contextat all levelsprimary_key/unique_keysis_entitymaps to PK;unique_keysnot yet modeledcustom_extensionslabelon fieldsTest plan
ai_contextor_extract_measure_metadatachanges)🤖 Generated with Claude Code