Skip to content
Merged
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
8 changes: 5 additions & 3 deletions core-spec/ossie-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@
"type": "string"
},
"minItems": 1,
"description": "Dataset fields that uniquely identify rows"
"uniqueItems": true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These new constraints should also go into core-spec/spec.md. The dataset table rows for primary_key and unique_keys don't say a field can't be named twice, and Version History has no entry. Documents that passed before this PR now fail, so the spec should say why.

For example, "Dataset fields that uniquely identify rows, each named once" for primary_key, the same rule for each unique_keys definition, and a Version History line for the change.

"description": "Dataset fields that uniquely identify rows, each named once"
},
"unique_keys": {
"type": "array",
Expand All @@ -228,10 +229,11 @@
"items": {
"type": "string"
},
"minItems": 1
"minItems": 1,
"uniqueItems": true
},
"minItems": 1,
"description": "Array of unique key definitions, each a list of dataset fields"
"description": "Array of unique key definitions, each a list of dataset fields naming each field once"
},
"description": {
"type": "string",
Expand Down
13 changes: 11 additions & 2 deletions core-spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ Logical datasets represent business entities or concepts (fact and dimension tab
|-------|------|----------|-------------|
| `name` | string | Yes | Unique identifier for the dataset |
| `source` | string | Yes | Reference to underlying physical table/view (e.g., `database.schema.table`) or query |
| `primary_key` | array | No | Dataset fields that uniquely identify rows |
| `unique_keys` | array of arrays | No | Array of unique key definitions, each a list of dataset fields |
| `primary_key` | array | No | Dataset fields that uniquely identify rows, each named once |
| `unique_keys` | array of arrays | No | Array of unique key definitions, each a list of dataset fields naming each field once |
| `description` | string | No | Human-readable description |
| `ai_context` | string/object | No | Additional context for AI tools (e.g., synonyms, common terms) |
| `fields` | array | No | Row-level attributes for grouping, filtering, and metric expressions |
Expand All @@ -195,6 +195,14 @@ unique_keys:
- [first_name, last_name] # Composite unique key
```

A key is the set of fields it names, so it names each of them once. Unquoted
field names resolve case-insensitively (see
[Namespacing and Identifier Resolution](expression_language.md#namespacing-and-identifier-resolution)),
so `[email, EMAIL]` names one field twice and is invalid. Two `unique_keys`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This makes [email, EMAIL] an error, but the rule it links (expression_language.md, Namespacing and Identifier Resolution) only says regular identifiers should be case insensitive, and that quoted-vs-unquoted comparison is DB specific. Can we either state case-insensitive resolution of key entries as its own rule here, or soften 'is invalid' to match the SHOULD?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

definitions that name the same fields, in any order and in any case, declare one
key twice; that is redundant rather than invalid, and validation reports it as a
warning.

### Example

```yaml
Expand Down Expand Up @@ -877,6 +885,7 @@ including rationale and migration impact for consumers, see the
- Breaking: metric expressions, `primary_key`, `unique_keys`, and relationship `from_columns`/`to_columns` refer to dataset fields, not columns of the dataset's `source`. Model-scoped metric expressions must use qualified `dataset.field` references; dataset-scoped metric expressions use unqualified field names. Earlier versions did not specify this, and some converters read these names as source columns; those converters must now resolve them as fields. See [Name Resolution](#name-resolution).
- Dataset-scoped metric expressions may reference columns of the dataset's `source`, written as `source.column`. See [Metric Scoping](#metric-scoping).
- 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).
- **0.1.1** (2025-12-11): Initial release
- Core semantic model structure
- Support for datasets, relationships, fields, and metrics
Expand Down
1 change: 1 addition & 0 deletions docs/spec_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ the [current core specification](../core-spec/spec.md) and
| 2026-11-09 | Core / Ontology [#691](https://github.com/apache/ossie/pull/691) | **Move the in-development version to `0.3.0.dev0`.** The next planned release is `0.3.0-incubating`; no `0.2.0` release is planned. | **Breaking for development documents.** Version constants in the current schemas reject `0.2.0.dev0`; producers must declare `0.3.0.dev0` and coordinate schema/package/converter versions. This is a development-version change, not a release announcement. |
| 2026-11-10 | Core [#522](https://github.com/apache/ossie/pull/522) | **Object `nonportable_extensions` data.** Vendor extension payloads become objects, and the field is renamed from `custom_extensions` so portable core semantics stay separate from vendor state. The core schema does not describe keys under `data`. | **Breaking within unreleased `0.3.0.dev0`.** Rename the field to `nonportable_extensions` and write `data` as an object, not a JSON string. The old name does not validate. Quote scalars under `data` that YAML may read as a boolean, number, or date. See [nonportable extensions](../extensions/nonportable_extensions.md). |
| 2026-11-12 | Expression language [#687](https://github.com/apache/ossie/pull/687) | **`ROUND` ties and true division in `OSSIE_SQL_2026`.** `ROUND` rounds half away from zero, and `/` is true division also for two integers, because engines differ on both and the same portable metric returned different numbers ([#643](https://github.com/apache/ossie/issues/643); [dev@ lazy consensus](https://lists.apache.org/thread/c1hy8vw7fqcp2y2hhxzj582516wqkoq6)). | Engines and converters with half-to-even `ROUND` or integer division emit the equivalent expressions the Numeric Semantics section gives; exact where `DECIMAL` arithmetic stays `DECIMAL`, best effort for exact ties of binary floating-point values. Documents need no change. |
| 2026-11-13 | Core / Ontology [#705](https://github.com/apache/ossie/pull/705) | **A key, and an ontology list of names or expressions, names each thing once.** A key is the set of fields it names, and a supertype, identifying relationship, constraint or verbalization pattern given twice says nothing the first already said. | **Validation becomes stricter.** `primary_key` and each `unique_keys` definition reject a repeated field, as do the ontology's `extends`, `identify_by` and `verbalizes` lists and `requires` and `derived_by` wherever they appear. Field names resolve case-insensitively, so `[email, EMAIL]` repeats one field; that case is reported by the validator rather than the schema. Remove the duplicate entry; a document that had one declared less than it appeared to. A `unique_keys` definition that restates another remains valid and is reported as a warning. |

## Semi-automated discovery and upkeep

Expand Down
8 changes: 8 additions & 0 deletions ontology/ontology.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"items": {
"$ref": "#/$defs/Expression"
},
"uniqueItems": true,
"description": "Expressions that constrain the population of this ontology"
},
"ontology": {
Expand Down Expand Up @@ -80,13 +81,15 @@
"type": "string",
"minLength": 1
},
"uniqueItems": true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same for the ontology. Since #673, ontology.md states each schema constraint in its field tables ("each must be non-empty"). The rows for extends, derived_by, identify_by, requires and verbalizes don't yet say that entries must be distinct.

Could we add that to those rows (e.g. "each must be non-empty and listed once") and add a Version History entry? Otherwise we bring back the schema/spec drift that #673 just fixed.

"description": "Indicates that this concept extends one or more other concepts"
},
"derived_by": {
"type": "array",
"items": {
"$ref": "#/$defs/Expression"
},
"uniqueItems": true,
"description": "Expressions that define how this concept is derived"
},
"identify_by": {
Expand All @@ -95,13 +98,15 @@
"type": "string",
"minLength": 1
},
"uniqueItems": true,
"description": "Names of relationships to use as the preferred identifier of this concept"
},
"requires": {
"type": "array",
"items": {
"$ref": "#/$defs/Expression"
},
"uniqueItems": true,
"description": "Expressions that constrain the population of this concept"
},
"relationships": {
Expand Down Expand Up @@ -153,13 +158,15 @@
"items": {
"$ref": "#/$defs/Expression"
},
"uniqueItems": true,
"description": "Expressions that define how this concept is derived"
},
"requires": {
"type": "array",
"items": {
"$ref": "#/$defs/Expression"
},
"uniqueItems": true,
"description": "Expressions that constrain the population of this relationship"
},
"verbalizes": {
Expand All @@ -168,6 +175,7 @@
"type": "string",
"minLength": 1
},
"uniqueItems": true,
"description": "Natural language expressions that verbalize this relationship"
},
"iri": {
Expand Down
21 changes: 14 additions & 7 deletions ontology/ontology.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ A field described below as non-empty cannot be the empty string `""`. This appli
string that names or references something, to IRIs, and to expressions. Descriptions are free
text and may be empty.

A list whose entries are described below as listed once cannot repeat one. A supertype, an

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: 'described below as listed once cannot repeat one' took me two reads. Maybe 'A list marked listed once must not repeat an entry.'?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

identifying relationship, a constraint or a verbalization pattern given twice says nothing
the first one does not already say.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Unique name of this specification; must be non-empty |
| `description` | string | No | Human-readable description |
| `ai_context` | string/object | No | Additional context for AI tools |
| `requires` | list | No | Expressions that constrain the population of this ontology; each must be non-empty and listed once |
| `ontology` | list | Yes | Concepts and relationships they group that form this ontology |
| `prefixes` | object | No | Namespace prefixes used to abbreviate [IRIs](#global-identifiers); each prefix's IRI must be non-empty |
| `ontology_mappings` | list | No | Deprecated; accepted only so existing documents continue to validate. Write mappings as [mapping documents](#mapping-documents) instead |
Expand All @@ -114,10 +119,10 @@ Concepts have the following schema:
| `concept` | string | Yes | Unique name of this concept; must be non-empty |
| `type` | ConceptType | Yes | Entity type or value type |
| `description` | string | No | Human-readable description |
| `extends` | list | No | Names of this concept's supertypes; each must be non-empty |
| `derived_by` | list | No | Expressions that derive this concept's population; each must be non-empty |
| `identify_by` | list | No | Names of relationships that uniquely reference objects of this concept; each must be non-empty |
| `requires` | list | No | Expressions that constrain this concept's population; each must be non-empty |
| `extends` | list | No | Names of this concept's supertypes; each must be non-empty and listed once |
| `derived_by` | list | No | Expressions that derive this concept's population; each must be non-empty and listed once |
| `identify_by` | list | No | Names of relationships that uniquely reference objects of this concept; each must be non-empty and listed once |
| `requires` | list | No | Expressions that constrain this concept's population; each must be non-empty and listed once |
| `relationships` | list | No | Relationships where this concept plays the first role |
| `iri` | string | No | Optional [global identifier](#global-identifiers) of this concept; must be non-empty when present |

Expand Down Expand Up @@ -161,9 +166,9 @@ Each relationship that is declared under a concept conforms to the following sch
| `description` | string | No | Human-readable description |
| `multiplicity` | enum | No | Multiplicity constraint |
| `roles` | list | No | List of additional roles in this relationship |
| `derived_by` | list | No | Expressions that derive links of this relationship; each must be non-empty |
| `requires` | list | No | Expressions that constrain this relationship's population; each must be non-empty |
| `verbalizes` | list | Yes | Patterns describing how to verbalize links; each must be non-empty |
| `derived_by` | list | No | Expressions that derive links of this relationship; each must be non-empty and listed once |
| `requires` | list | No | Expressions that constrain this relationship's population; each must be non-empty and listed once |
| `verbalizes` | list | Yes | Patterns describing how to verbalize links; each must be non-empty and listed once |
| `iri` | string | No | Optional [global identifier](#global-identifiers) of this relationship; must be non-empty when present |

Each relationship is uniquely identified by prepending its declared name with that of the containing
Expand Down Expand Up @@ -699,6 +704,8 @@ though `Store` plays a role in three of the relationships.
- **0.3.0.dev0** (Unreleased; started as 0.2.0.dev0 on 2026-05-29): Basic support for ontologies and logical schema mappings
- Breaking: each ontology map's `semantic_model` now requires its own `version`.
- Breaking: names, IRIs, prefix IRIs and expressions can no longer be empty strings.
- Breaking: `extends`, `identify_by`, `verbalizes`, and `requires` and `derived_by` wherever
they appear, list each entry once; a repeated name or expression is no longer accepted.
- Core ontology structure: Concepts, relationships, and business rules (requires and derived_by)
- Schema mappings from one or more logical models into an ontology
- Optional IRIs on concepts and relationships, with namespace prefixes declared at the top level
Expand Down
25 changes: 23 additions & 2 deletions python/src/ossie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import yaml
from pydantic import (
AfterValidator,
BaseModel,
ConfigDict,
Field,
Expand Down Expand Up @@ -339,6 +340,20 @@ class OssieMetric(BaseModel):
nonportable_extensions: Optional[list[OssieNonportableExtension]] = None


def _distinct(names: list[str]) -> list[str]:
"""Mirror the schema's `uniqueItems`, which `Field` cannot express.

Names are compared as written, as the keyword does, so this serves one key:
`primary_key` and each definition inside `unique_keys`.
"""
seen: set[str] = set()
for name in names:
if name in seen:
raise ValueError(f"repeats {name!r}")
seen.add(name)
return names


class OssieDataset(BaseModel):
"""Logical dataset representing a business entity (fact or dimension table)."""

Expand All @@ -348,10 +363,16 @@ class OssieDataset(BaseModel):
source: str = Field(..., min_length=1)
# The schema gives both `minItems: 1`, as it does the relationship column arrays.
# An empty key names nothing, and `Field` mirrors minItems as `min_length` here.
primary_key: Optional[list[str]] = Field(default=None, min_length=1)
unique_keys: Optional[list[Annotated[list[str], Field(min_length=1)]]] = Field(
# Each key is also `uniqueItems`: one that names a field twice declares fewer
# columns than it appears to. The list of definitions is not, since two holding
# the same key are redundant rather than wrong; validate.py warns about them,
# reordered and recased ones included, which a schema keyword cannot reach.
primary_key: Optional[Annotated[list[str], AfterValidator(_distinct)]] = Field(
default=None, min_length=1
)
unique_keys: Optional[
list[Annotated[list[str], Field(min_length=1), AfterValidator(_distinct)]]
] = Field(default=None, min_length=1)
description: Optional[str] = None
ai_context: Optional[OssieAIContext] = None
fields: Optional[list[OssieField]] = None
Expand Down
72 changes: 72 additions & 0 deletions python/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,78 @@ def test_unique_key_definitions_may_not_be_empty() -> None:
assert any(item["loc"] == ("unique_keys", 0) for item in error.value.errors())


# One repeat per property the schema marks `uniqueItems`, so a keyword added to the
# schema without a matching model constraint fails the parity test below.
_REPEATED_CASES = {
("Dataset", "primary_key"): lambda: OssieDataset(
name="orders", source="db.s.orders", primary_key=["order_id", "order_id"]
),
}


def test_unique_items_parity_with_core_schema() -> None:
"""The models must reject the repeats the schema rejects.

Pydantic 2 dropped `unique_items`, so there is no `Field` keyword to compare
against the schema's; each property is exercised instead.
"""
schema_path = Path(__file__).parents[2] / "core-spec" / "ossie-schema.json"
schema = json.loads(schema_path.read_text())

checked = 0
for node, model in _CONSTRAINED_NODES.items():
for prop, prop_schema in schema["$defs"][node]["properties"].items():
if not prop_schema.get("uniqueItems"):
continue
build = _REPEATED_CASES.get((node, prop))
assert build is not None, (
f"{node}.{prop} is uniqueItems in the schema with no case here"
)
with pytest.raises(ValidationError) as error:
build()
assert any(item["loc"] == (prop,) for item in error.value.errors())
checked += 1

# Guards against the loop silently checking nothing if the schema moves.
assert checked == 1


def test_a_unique_key_definition_may_be_written_twice() -> None:
"""`unique_keys` carries no `uniqueItems`, so the model does not reject one either.

A definition written twice is redundant rather than wrong; validate.py warns
about it, where a rejection here would refuse to build the document at all.
"""
schema_path = Path(__file__).parents[2] / "core-spec" / "ossie-schema.json"
schema = json.loads(schema_path.read_text())
unique_keys = schema["$defs"]["Dataset"]["properties"]["unique_keys"]

assert "uniqueItems" not in unique_keys

dataset = OssieDataset(
name="orders", source="db.s.orders", unique_keys=[["order_id"], ["order_id"]]
)

assert dataset.unique_keys == [["order_id"], ["order_id"]]


def test_a_unique_key_definition_may_not_repeat_a_field() -> None:
"""The constraint nests, as the one on emptiness does.

The field names inside one definition are a set too, and the parity test
above reads only the top level of each property.
"""
schema_path = Path(__file__).parents[2] / "core-spec" / "ossie-schema.json"
schema = json.loads(schema_path.read_text())
unique_keys = schema["$defs"]["Dataset"]["properties"]["unique_keys"]

assert unique_keys["items"]["uniqueItems"] is True

with pytest.raises(ValidationError) as error:
OssieDataset(name="orders", source="db.s.orders", unique_keys=[["a", "a"]])
assert any(item["loc"] == ("unique_keys", 0) for item in error.value.errors())


@pytest.mark.parametrize(
("build", "label"),
[
Expand Down
Loading
Loading