Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions core-spec/ossie-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,18 @@
"required": ["name", "source"],
"additionalProperties": false
},
"Cardinality": {
"type": "string",
"enum": [
"ManyToOne",
"OneToOne",
"OneToMany"
],
"description": "Relationship cardinality, from `from` to `to`. `ManyToOne`: each `from` row matches at most one `to` row. `OneToMany`: each `to` row matches at most one `from` row. `OneToOne`: both. Absent means `ManyToOne`."
},
"Relationship": {
"type": "object",
"description": "Foreign key relationship between datasets",
"description": "Equality conditions between the fields of two datasets",
"properties": {
"name": {
"type": "string",
Expand All @@ -278,28 +287,31 @@
"from": {
"type": "string",
"minLength": 1,
"description": "Dataset on the many side of the relationship"
"description": "Dataset containing from_columns"
},
"to": {
"type": "string",
"minLength": 1,
"description": "Dataset on the one side of the relationship"
"description": "Dataset containing to_columns"
},
"from_columns": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"description": "Array of field names in the 'from' dataset (foreign key fields)"
"description": "Array of field names in the 'from' dataset"
},
"to_columns": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"description": "Array of field names in the 'to' dataset (primary or unique key fields)"
"description": "Array of field names in the 'to' dataset"
},
"cardinality": {
"$ref": "#/$defs/Cardinality"
},
"ai_context": {
"$ref": "#/$defs/AIContext"
Expand Down
12 changes: 6 additions & 6 deletions core-spec/relational_semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ SQL-native names. The correspondence:
| field | `field` | A scalar (non-measure) column; we adopt Ossie's term. Ossie's optional `dimension` role (e.g. `is_time`) is metadata this interface does not require. |
| measure | dataset-scoped `metric` (`datasets[].metrics`) | A measure on the dataset's relation, of any scalar result type. A dataset-scoped metric that composes measures of the dataset's `source` with `AGG(source.measure)` is a derived measure (Section 5.2), and the dataset remains a relation. The `source` must be a measure relation (see [Measure Relation as a `source`](spec.md#measure-relation-as-a-source)). Each measure of the `source` that it references keeps its own source rows and row identity, which can originate upstream of the dataset (Sections 3.2 and 3.3); its other aggregates read the dataset's rows. Model-scoped metrics are not exposed as measure columns (Section 10.3). |
| row identity (Section 3.2) | `primary_key` | A dataset's declared primary key is a natural source of the row identity of a base measure. A measure of the dataset's `source` that a derived measure evaluates keeps the row identity that it has there. |
| join relationship (Section 11.3) | `relationship` (`from`/`to`, `from_columns`/`to_columns`) | `from`/`to` map to source/target and the columns to the join predicate (`from` many, `to` one); Section 11.3 adds cardinality, roles, and arbitrary `ON`. |
| join relationship (Section 11.3) | `relationship` (`from`/`to`, `from_columns`/`to_columns`) | `from`/`to` map to source/target, the columns to the join predicate, and `cardinality` to the cardinality (`MANY_TO_ONE` if absent); Section 11.3 adds roles and arbitrary `ON`. |
| Layer 1 expression | `OSSIE_SQL_2026` expression (`expression.sql`, or an `OSSIE_SQL_2026` entry in `dialects`) | The portable form of an Ossie expression, in the Layer 1 language (Section 1.1). For the resolution rules, see [Expression Object](spec.md#expression-object). |

Ossie model metadata this interface does not natively surface (`ai_context`, `nonportable_extensions`,
Expand Down Expand Up @@ -956,11 +956,11 @@ ALTER VIEW model.flights
```

An Ossie `relationship` maps onto the equi-join baseline: its `from`/`to` datasets are the
source and target and its `from_columns`/`to_columns` the joined column pairs (`from` the many
side, `to` the one), which round-trips between this interface and the Ossie model. The richer
elements above (explicit cardinality, semantic roles, and arbitrary boolean `ON` predicates)
have no home in current Ossie relationship metadata and do not round-trip without a future Ossie
schema extension (Section 13.2).
source and target, its `from_columns`/`to_columns` the joined column pairs, and its
`cardinality` the cardinality (`MANY_TO_ONE` if absent), which round-trips between this
interface and the Ossie model. The richer elements above (`MANY_TO_MANY`, semantic roles, and
arbitrary boolean `ON` predicates) have no home in current Ossie relationship metadata and do
not round-trip without a future Ossie schema extension (Section 13.2).

**Using a relationship.** A tool reads the relationships on a relation, selects the one that
fits the analysis, and generates the join from its predicate. The relationship fixes the
Expand Down
24 changes: 19 additions & 5 deletions core-spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,18 @@ datasets:

## Relationships

Relationships define how logical datasets are connected through foreign key constraints. They support both simple and composite keys.
Relationships connect logical datasets through equality conditions between their fields. They support simple and composite keys.

### Schema

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Unique identifier for the relationship |
| `from` | string | Yes | The logical dataset on the many side of the relationship |
| `to` | string | Yes | The logical dataset on the one side of the relationship |
| `from_columns` | array | Yes | Array of field names in the "from" dataset (foreign key fields) |
| `to_columns` | array | Yes | Array of field names in the "to" dataset (primary or unique key fields) |
| `from` | string | Yes | The logical dataset containing `from_columns` |
| `to` | string | Yes | The logical dataset containing `to_columns` |
| `from_columns` | array | Yes | Array of field names in the "from" dataset |
| `to_columns` | array | Yes | Array of field names in the "to" dataset |
| `cardinality` | string (enum) | No | `ManyToOne`, `OneToMany`, or `OneToOne`. See [Cardinality](#cardinality). |
| `ai_context` | string/object | No | Additional context for AI tools |
| `nonportable_extensions` | array | No | Vendor-specific attributes |

Expand All @@ -257,6 +258,18 @@ Relationships define how logical datasets are connected through foreign key cons
- For simple relationships, use a single field: `[field1]`
- For composite relationships, use multiple fields: `[field1, field2]`

### Cardinality

`cardinality` describes the maximum number of matching rows on each side of a relationship:

| Value | Meaning |
|-------|---------|
| `ManyToOne` | Each `from` row matches at most one `to` row. |
| `OneToMany` | Each `to` row matches at most one `from` row. |
| `OneToOne` | Both conditions hold. |

The default is `ManyToOne`. Cardinality is informational and does not imply referential integrity, join type, or filter propagation. Many-to-many cardinality is unsupported.

### Examples

**Simple Relationship:**
Expand Down Expand Up @@ -939,6 +952,7 @@ including rationale and migration impact for consumers, see the
- Model-scoped metric expressions may evaluate a dataset-scoped metric with `AGG(dataset.metric)`. See [Metric Scoping](#metric-scoping).
- Breaking: a key names each field once. `primary_key` and each `unique_keys` definition may no longer repeat a field, and because field names resolve case-insensitively, `[email, EMAIL]` repeats one. Documents that named a field twice declared fewer columns than they appeared to and now fail validation. A `unique_keys` definition that restates another remains valid and is reported as a warning. See [Datasets](#datasets).
- Dataset-scoped metric expressions may evaluate a measure of the dataset's `source` with `AGG(source.measure)` when the `source` is a measure relation. A field expression must not refer to a measure column. See [Metric Scoping](#metric-scoping).
- Relationships may declare `cardinality`: `ManyToOne` (the default), `OneToMany`, or `OneToOne`. Consumers that assume that `from` is the many side must read it. See [Cardinality](#cardinality).
- **0.1.1** (2025-12-11): Initial release
- Core semantic model structure
- Support for datasets, relationships, fields, and metrics
Expand Down
27 changes: 18 additions & 9 deletions core-spec/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ datatypes:
- "DateTimeTz" # Instant identified using offset or timezone context
- "Opaque" # Known type outside the portable vocabulary

# Supported relationship cardinalities, stated from `from` to `to`
# Auto-generated from ossie-schema.json ($defs.Cardinality.enum).
cardinalities:
- "ManyToOne" # Each from row matches at most one to row (default)
- "OneToOne" # Each row matches at most one row on the other side
- "OneToMany" # Each to row matches at most one from row

# Vendor name for non-portable extensions (free-form string).
# See the known-vendor catalog in extensions/vendors.md.
vendor_name: string
Expand Down Expand Up @@ -107,7 +114,7 @@ datasets:
# Optional: Dataset fields that uniquely identify rows
# These are fields declared in the dataset, not columns of its source
# Can be a single field or a composite of multiple fields
# This is the preferred unique identifier for this dataset and is used in relationships to determine many-to-one or one-to-one.
# This is the preferred unique identifier for this dataset.
# Examples:
# primary_key: [customer_id] # Simple primary key
#
Expand All @@ -117,7 +124,6 @@ datasets:
# Optional: Array of unique key definitions, each a list of dataset fields
# These are fields declared in the dataset, not columns of its source
# Each unique key can be a single field or a composite of multiple fields
# Used for determining relationship type of either many-to-one or one-to-one
# Examples:
# unique_keys:
# - [field1]
Expand Down Expand Up @@ -177,37 +183,40 @@ datasets:
---
# Relationship Schema
# Defines how logical datasets within this model are connected
# Represents foreign key relationships (many-to-one or one-to-one)
# Represents equality relationships (many-to-one, one-to-many, or one-to-one)
relationships:
# Required: Unique identifier for the relationship
- name: string

# Required: The logical dataset on the many side of the relationship
# Required: The logical dataset containing from_columns
# References a logical dataset name
from: string

# Required: The logical dataset on the one side of the relationship
# Required: The logical dataset containing to_columns
# References a logical dataset name
to: string

# Required: Array of field names in the "from" dataset (foreign key fields)
# Required: Array of field names in the "from" dataset
# These are fields declared in the dataset, not columns of its source
# For simple relationships, use a single field: [field1]
# For composite relationships, use multiple fields: [field1, field2]
# The order of fields must correspond to the order in to_columns
# Examples:
# - [customer_id] # Simple foreign key
# - [order_id, line_number] # Composite foreign key
# - [customer_id] # Simple key
# - [order_id, line_number] # Composite key
from_columns: [] # Array of field names

# Required: Array of field names in the "to" dataset (primary or unique key fields)
# Required: Array of field names in the "to" dataset
# These are fields declared in the dataset, not columns of its source
# Must have the same number of fields as from_columns in corresponding order
# Examples:
# - [id] # Simple key
# - [order_id, line_number] # Composite key
to_columns: [] # Array of field names

# Optional: One of the 'cardinalities' enum above; omitted means ManyToOne
cardinality: string

# Optional: Additional context for AI tools (e.g., synonyms, business context)
# Helps LLMs understand when and why the datasets should be joined
ai_context: {} # see AIContext in ossie-schema.json
Expand Down
4 changes: 2 additions & 2 deletions core-spec/wide_table_semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ The binding identifies the model and reports the errors of Section 8.

## 4. Paths

The **relationship graph** contains one node per dataset and one edge per relationship. Each relationship equates its `from_columns` with its `to_columns`; `from` is the many side and `to` the one side (core specification, Relationships). This many-to-one direction is the relationship's **declared cardinality**; the data need not satisfy it (Layer 2 Section 11.3).
The **relationship graph** contains one node per dataset and one edge per relationship. Each relationship equates its `from_columns` with its `to_columns`. Its `cardinality` is its **declared cardinality** (core specification, Relationships); the data need not satisfy it (Layer 2 Section 11.3).

- A **step** crosses a relationship from `from` to `to`. If the data satisfies the declared cardinality, a step matches at most one `to` row for each `from` row.
- A **step** crosses a relationship from `from` to `to` if its declared cardinality is `ManyToOne` or `OneToOne`, and from `to` to `from` if it is `OneToMany` or `OneToOne`. If the data satisfies the declared cardinality, a step matches at most one row where it ends for each row where it starts.
- A **path** from dataset X to dataset Y is a sequence of steps from X to Y with no repeated dataset. The path from a dataset to itself is empty. Y is **reachable** from X if such a path exists.
- The lowering joins Y to X along the path from X to Y. If two or more paths lead from X to Y, the engine MUST raise [`E_AMBIGUOUS_PATH`](#8-errors), even if one path is shorter. For example, if `store` relates to `date_dim` through its closing date, the sale date and the closing date give two paths from `store_sales` to `date_dim` (Appendix B.3).

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The Ossie core specification (current version: **0.3.0.dev0**, latest released:
| **Semantic Model** | The top-level container representing a complete semantic model, including datasets, relationships, and metrics. |
| **Datasets** | Logical datasets representing business entities (fact and dimension tables), with fields, primary keys, and unique keys. |
| **Fields** | Row-level attributes for grouping, filtering, and metric expressions. Fields support multiple SQL dialects for cross-platform compatibility. |
| **Relationships** | Foreign key connections between datasets, supporting both simple and composite keys. |
| **Relationships** | Equality conditions between the fields of two datasets, supporting both simple and composite keys, with an optional cardinality. |
| **Metrics** | Quantitative measures (sums, averages, ratios, etc.). A model-scoped metric's expression may combine fields from several datasets; a dataset-scoped metric is defined on one dataset's relation: it aggregates the dataset's rows, or derives from measures of the dataset's `source`. |
| **Non-portable Extensions** | Vendor-specific metadata in `nonportable_extensions`. Core semantics do not depend on it. Behavior defined only there is not portable Ossie behavior. |
| **AI Context** | Optional annotations at every level (model, dataset, field, relationship, metric) to help AI tools understand business meaning — including instructions, synonyms, and example queries. |
Expand Down Expand Up @@ -308,7 +308,7 @@ A practical guide for organizations looking to adopt Ossie.
| **Field** | A row-level attribute within a dataset, used for grouping, filtering, or as part of metric expressions. Fields can be simple column references or computed expressions. A field's logical data type is declared by the optional top-level `datatype` field (one of `String`, `Integer`, `Decimal`, `Float`, `Boolean`, `Date`, `Time`, `DateTime`, `DateTimeTz`, or `Opaque`). |
| **Dimension** | A categorical attribute used to slice and filter data (e.g., region, product category, date). In Ossie, dimensions are represented as fields with optional metadata such as `is_time`. |
| **Metric** | A quantitative measure computed by aggregating fields (e.g., total revenue, average order value). A dataset-scoped metric is defined on an individual dataset's relation, for a measure that semantically belongs to the dataset: it aggregates the dataset's rows, or derives from measures of the dataset's `source`; a model-scoped metric is defined at the model root and may span datasets. |
| **Relationship** | A foreign key connection between two datasets, defining how they can be joined. Relationships are always many-to-one (from the referencing dataset to the referenced dataset). |
| **Relationship** | Equality conditions between the fields of two datasets, defining how they can be joined. Its optional `cardinality` is `ManyToOne` (the default), `OneToMany`, or `OneToOne`. |
| **Dialect** | A SQL or expression language variant an expression is written in (e.g., `ANSI_SQL`). A free-form string; `OSSIE_SQL_2026` is the only dialect Ossie defines, and all others are opaque. |
| **Non-portable Extension** | Vendor-specific metadata on a model, dataset, field, relationship, or metric, stored as `nonportable_extensions`. The core specification does not interpret it, and portable behavior does not depend on it. |
| **AI Context** | Optional annotations on any Ossie construct (model, dataset, field, relationship, metric) that provide additional context for AI tools — including natural language instructions, synonyms, and example queries. |
Expand Down
Loading
Loading