Skip to content

fix(core-spec, ontology): reject a list that names the same thing twice - #705

Merged
jbonofre merged 2 commits into
apache:mainfrom
ayushtkn:schema-unique-items
Nov 19, 2026
Merged

jbonofre merged 2 commits into
apache:mainfrom
ayushtkn:schema-unique-items

Conversation

@ayushtkn

@ayushtkn ayushtkn commented Nov 7, 2026

Copy link
Copy Markdown
Member

Summary

No schema used uniqueItems, so a key could name one field twice and a list could carry the same entry twice:


  primary_key: [order_id, order_id]
  unique_keys: [[email], [email]]
  verbalizes: ["{Order} has {Total}", "{Order} has {Total}"]

A key that repeats a field declares fewer columns than it appears to, and a repeated entry constrains, derives, names or verbalizes nothing the first already did.

ossie-schema.json marks primary_key, unique_keys and each definition inside unique_keys. ontology.json marks the eight lists of names and expressions: extends, identify_by and verbalizes, and requires and derived_by wherever they appear.

models.py mirrors the two core-spec keys. Pydantic 2 dropped unique_items, so an AfterValidator stands in for it, as min_length already stands in for minItems.

uniqueItems compares entries as written, while a key means the set of fields its entries name, and regular identifiers are case insensitive (expression_language.md), so these still reached the semantic checks:

primary_key: [order_id, ORDER_ID]
unique_keys: [[order_id, line_number], [line_number, order_id]]

validate_key_declarations reports them. A key that names one field twice claims a column it does not have, which is an error. Two unique_keys definitions holding the same set of fields are one key written twice, which is redundant rather than wrong, so that is a warning.

An entry whose folded form names no declared field is left out of both: it names nothing to compare, validate_references reports it as undeclared, and calling it a repeat would name a field the dataset does not have. An empty entry, which passes the schema because key items carry no minLength, is dropped the same way but without discarding the entries beside it.

A dataset that declares two field names differing only in case declares one field twice, so a key naming both spellings names that field twice and is reported. validate_unique_names compares field names as written and does not report the declaration itself; closing that gap is a change of its own, and it does not make the key's two entries two fields.

A unique key that restates the primary key stays silent: DDL commonly declares both, and examples/tpcds_semantic_model.yaml does so in five of its datasets. Relationship from_columns and to_columns are left alone as well: they correspond positionally, so one column of the from dataset may legitimately be compared with two columns of the to dataset.

Related Issues

Checklist

Specification

  • Spec changes are included in core-spec/ and follow the existing structure
  • Spec changes have been discussed on the mailing list or in a linked issue
  • Breaking changes to the spec are clearly called out in the summary

Ontology

  • Ontology changes in ontology/ are consistent with spec changes
  • New or modified terms are defined and documented

Converters

Validation

  • Validation rules in validation/ are updated if the spec changed
  • New validation cases are covered by tests

Documentation

  • docs/ is updated to reflect any user-facing changes
  • New features or behaviors are documented with examples where appropriate
  • CONTRIBUTING.md is updated if the contribution process changed

Examples

  • examples/ are added or updated for any new spec constructs

Tests

  • All existing tests pass (pytest / CI green)
  • New functionality is covered by tests

Compliance

  • ASF license headers are present on all new source files
  • No third-party dependencies are added without PMC/IPMC approval
  • If third-party source code is vendored/copied (not just declared as a dependency), NOTICE and/or LICENSE have been updated per ASF policy

Copilot AI lite review requested due to automatic review settings November 7, 2026 03:16

Copilot AI 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.

🟢 Approval recommended

No active review issues remain, and the schema, validation, model, and regression-test changes collectively address duplicate-entry and uniqueness handling.

No open issues 🎉

What changed in this PR

This pull request prevents duplicate entries in core-spec keys and ontology lists, adds semantic validation for case-insensitive and reordered key duplicates, and keeps the Python models aligned with the updated schemas.

Changes:

  • Adds uniqueItems constraints to core-spec and ontology schemas.
  • Validates repeated key fields and redundant unique-key definitions.
  • Adds Pydantic validators mirroring schema uniqueness rules.
  • Expands regression coverage for schema, model, key, and ontology validation.

This pull request is too complex or risky for automated approval.

File Description
validation/​validate.py Adds case-insensitive key-declaration checks and redundancy warnings.
validation/​tests/​test_validate.py Tests duplicate, case-variant, undeclared, and redundant key scenarios.
validation/​tests/​test_ontology.py Tests duplicate detection across ontology lists.
python/​tests/​test_models.py Verifies model/schema uniqueness parity, including nested unique keys.
python/​src/​ossie/​models.py Adds Pydantic validators mirroring schema uniqueness constraints.
ontology/​ontology.json Rejects repeated entries across ontology expression and naming lists.
core-spec/​ossie-schema.json Rejects repeated primary-key fields and duplicate unique-key definitions.

Review effort: Lite

kayemkim
kayemkim previously approved these changes Nov 8, 2026

@kayemkim kayemkim left a comment

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.

On the tree merged with current main: 37 checks pass on the four Python versions, and validate.py agrees with main on the 78 model and ontology documents I could find, converter fixtures included, so nothing shipped today repeats an entry. The folded cases behave as described: [order_id, ORDER_ID] is an error, the reordered unique_keys pair is a warning with exit 0, and a unique key restating the primary key stays silent. It also merges cleanly over #697.

Not blocking: this is a tightening, so a document with a repeated key entry that validated yesterday fails at the schema step today, which is a line for the migration notes #686 is collecting, and spec.md's description of primary_key could say the fields are distinct.

@jbonofre
jbonofre self-requested a review November 9, 2026 17:41
Comment thread core-spec/ossie-schema.json Outdated
"uniqueItems": true
},
"minItems": 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.

This outer uniqueItems makes unique_keys: [[email], [email]] a schema error. The validator stops on schema errors ("Semantic checks skipped until schema errors are fixed."), so the author also loses every reference and SQL diagnostic until it's fixed.

Meanwhile [[email], [EMAIL]] and [[id, email], [email, id]] are the same redundancy, and they only get the warning from validate_key_declarations, so those document pass. That function docstring, and the comment on OssieDataset.unique_keys, both call a repeated definition redundant rather than wrong. That points to a warning in every case.

Could we drop this outer uniqueKeys, and the outer AfterValidator(_distinct) on unique_keys in models.py, and let validate_key_declarations warn on exact repeats too?

If so, the repeat check there should compare definitions by position rather than with earlier is not key. Otherwise a YAML alias (unique_keys: [&k [email], *k]) passes the same list twice and isn't reported. The inner uniqueItems on each key and the one on primary_key are fine as errors: a key that names a field twice really is wrong.

"type": "string"
},
"minItems": 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.

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.

Comment thread ontology/ontology.json
"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.

@jbonofre

Copy link
Copy Markdown
Member

For the record, here's the [DISCUSS] thread on the dev mailing list: https://lists.apache.org/thread.html/4pn2rjbh36brt99pdqgjw0mhx7606ql8

@orca-review-bot orca-review-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.

Nice, careful change. Each layer catches what it can see: the schema catches exact repeats, and the validator catches the recased and reordered ones. The warning-not-error choice for a repeated unique_keys definition keeps the semantic checks running. I traced the edge cases (non-strings, empty, undeclared, YAML alias) through validate_key_declarations and found no wrong output. Python and validation tests pass locally, the tpcds example still validates, and generate-spec-types.py --check is clean.

Main ask: spec.md makes [email, EMAIL] invalid by citing expression_language.md, but that rule is only a SHOULD (see the inline comment). Since this is marked Breaking, could we also link a dev@ thread or issue in the change log, like the #687 row does?

Small test ask: can we add a key like [id, ID, ghost] in test_validate.py, to pin that the repeat is still reported next to the undeclared-field error?

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

Comment thread core-spec/spec.md
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.

Comment thread validation/validate.py
earlier = first_seen.setdefault(frozenset(identities), position)
if earlier != position: # another definition held this set first
errors.append(ValidationWarning(
f"[Unique] Warning: {prefix}: unique_keys {key} declares the "

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: for an exact repeat this prints unique_keys ['email'] declares the same key as unique_keys ['email'], which doesn't say which definitions match. Can we include the positions, e.g. unique_keys[1] ... unique_keys[0]?

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

Comment thread ontology/ontology.md
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.

christianeu-db pushed a commit to apache/ossie-converters that referenced this pull request Nov 18, 2026
…ns, derived keys, join type, and query-dependent expressions (#208)

* fix(thoughtspot): a derived key is the set of columns it names

`derive_keys` built each key candidate from a relationship's `to_columns`
verbatim and compared candidates by exact list equality. Neither holds.

`to_columns` corresponds positionally to `from_columns`, so one column of
the `to` dataset may legitimately be compared with two of the `from`
dataset. apache/ossie#705 says so explicitly and leaves `to_columns` alone
for that reason. Copied into a key, that repeat declares a column the
dataset does not have -- `primary_key: [customer_id, customer_id]` -- and
nothing reported it.

Two relationships naming the same columns in a different order, or in a
different case, are one key written twice. Read as two, the dataset was
judged to disagree with itself and lost the primary key it has. The
realistic shape is two fact tables on one composite-key dimension with the
AND written the other way round; the order is the author's choice.

Regular identifiers are case-insensitive (`expression_language.md`), which
is what puts the case axis in the same rule rather than a second one. The
spelling emitted is always the one the document used, since that is what
the dataset declares as a field.

The coverage claim is folded on both sides too. Folding the candidates
without folding that comparison would newly predict an upstream warning
that will not fire, for a relationship that covers the key perfectly well.

1059 tests pass (1052 before). Four mutations, four caught: no dedup within
one relationship; compare ordered rather than as a set; do not fold case;
coverage check compares as written. The last one survived first, because
the test written for it used two qualifying relationships and so never
reached the branch -- rewritten with a disqualified sibling, it kills it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(thoughtspot): a model alias is not the name of a table

A role-playing dimension is modelled in ThoughtSpot by listing one table
once per role, each `model_tables[]` entry carrying its own `alias`. Two
namespaces then meet in every join, and this converter read them as one.

The MODEL namespace is `alias or name`. It names the datasets, every
`column_id` prefix, and `joins[].with`. The PHYSICAL namespace is the
table's own `name`. A Table's `joins_with[]` belongs to the table, which
knows nothing about the aliases a model gives it, so its `destination` and
every prefix inside its `on` are physical. ThoughtSpot enforces the split:
an alias name in a join condition is refused outright with "Invalid
srcTable or destTable in join expression", and that is true of a join
between two different tables, not only a self-join.

Reading one as the other cost every join in every aliased model:

- the referencing form took its target from `destination.name`, which is
  no dataset once the target is aliased, so the relationship was dropped
  as having an unknown target;
- both forms then matched the condition's physical prefixes against the
  model-level ones, found no equality pair, and demoted the join to an
  unrepresentable stash entry.

Measured on a document exported from a cluster: three datasets, zero
relationships, in a model whose joins all converted before an alias was
added. The dimension lost its derived key along with its join.

The return leg had the mirror of it: `destination` and the rebuilt `on`
were written with the dataset name, so the TML we handed back named an
alias in both places. Round-tripping a real aliased model and importing
the result gives `Schema validation failed` before this change and status
OK after (`--policy VALIDATE_ONLY`, same cluster, same document).

Two ends that share one table are left alone in both directions. The
condition says the same word on both sides, so which end each column
belongs to cannot be read, and guessing would silently reverse a join.
ThoughtSpot has no self-join in any spelling (13125 against an alias of
the same table, 14565 against itself), so this reaches us only from
hand-written TML; it is declared, not converted.

`test_a_self_join_gives_each_alias_its_own_dataset_and_key` asserted the
opposite -- that an aliased self-join written in alias names converts
cleanly with no issue. Both of its premises are refused by a cluster, so
it pinned a document that cannot exist. Rewritten to assert the declared
loss, keeping what it got right: each alias is its own dataset, and the
two share one source.

1073 tests pass (1059 before; 14 added). Six mutations, six caught --
three of them only after the first run showed every writer-side mutation
surviving, which said the round-trip probe was carrying that half of the
change and no test was.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(thoughtspot): assume the row-preserving join type, and say so

An Ossie relationship carries no join type. A document this converter did
not write therefore has none to recover: RELATIONSHIP_STASH_TYPE is the only
source of one, and it exists solely on a document that came from ThoughtSpot.
ThoughtSpot in turn REQUIRES `type` on an inline join -- there is no omit-it-
and-let-the-platform-decide -- so a value has to be invented, and every value
in the vocabulary imports. A bad choice is a wrong number, not a failed
conversion.

The invented value was INNER, chosen in silence. `from` is the many side and
`to` is the one side, so INNER drops every `from` row matching nothing on the
`to` side -- in a star schema, every fact row with an unmatched or NULL
foreign key -- and lowers every measure computed over it with nothing on
screen to say so.

LEFT_OUTER keeps those rows, and is what the one vendor here that fixes the
semantics means: Databricks offers no `type:` field on a metric-view join
because it joins the fact source to every dimension with a LEFT OUTER JOIN.

The assumption is now reported, at WARNING, under TS-JOIN-TYPE-ASSUMED, with
a remedy naming the four values. A stashed type is recovered fact, so it is
still used as it stands and nothing is logged for it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(thoughtspot): report the four spec constructs that were dropped silently

The converter's standing rule is that nothing is discarded without saying
so. Four parts of the core specification were read past instead, so an
author converting a dbt, Databricks or Snowflake document had no way to
learn the information was gone.

None of these is a translation this converter could have performed. Each
genuinely has no home in TML, so the fix is the issue, not a mapping.

* TS-DATASET-METRICS-DROPPED (WARNING) -- `Dataset.metrics`. Only
  `SemanticModel.metrics` was read, so every dataset-scoped metric vanished.
  Their operands resolve within the dataset by single-part name, a namespace
  `resolve_field` does not implement (#101). A measure
  disappearing from a model earns a WARNING.
* TS-FIELD-IS-TIME-DROPPED (INFO) -- `Field.dimension.is_time`. The spec
  makes it a role flag independent of datatype; ThoughtSpot derives the role
  from the column's own type and has no separate flag.
* TS-JOIN-AI-CONTEXT-UNSUPPORTED (WARNING) -- `Relationship.ai_context`, the
  one ai_context scope with no issue of its own. The dataset, field, metric
  and model scopes were already reported.
* TS-VENDOR-EXTENSIONS-DROPPED (INFO) -- another vendor's custom_extensions.
  The forward leg deliberately preserves foreign entries alongside our own;
  the return leg has nowhere in TML to put them. Reported once per vendor for
  the document, not once per object: a foreign converter stashes on every
  field it writes, and one issue each would bury the rest of the log.

Eight mutations of the new code were run; all eight were killed. A ninth,
removing the extension walk's recursion guard, survives and is equivalent --
noted at the line, since `data` is a JSON string and cannot nest.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(thoughtspot): close the defects an adversarial review of this branch found

Seven, two of them regressions introduced by the commits below.

**An alias-spelled inline condition stopped converting.** Matching the `on`
prefixes against the PHYSICAL namespace alone did not fix the class, it moved
it: before, the MODEL namespace was matched alone, so a physical-spelled
condition was demoted; after, an alias-spelled one was. Neither failure is
visible to a round trip -- the verbatim condition is stashed and replayed, so
the TML returns byte-identical -- and both cost the Ossie document the
relationship, which is the part every other converter reads. The reader now
accepts either spelling. The writer still emits physical names.

**A dataset joined to itself slipped past the self-join guard**, which was
conditioned on the two datasets having different names. The plainest case of
all -- `from` and `to` the same dataset -- emitted `[EMPLOYEE::MGR_ID] =
[EMPLOYEE::ID]`, exactly the 14565 refusal. One physical table on both ends is
the whole cause; how many datasets sit over it is not part of it. Widened on
both legs.

**The extensions scan could fail the conversion it only reports on.** Plain
recursion raised RecursionError on a cyclic document (a YAML alias builds one)
or a deeply nested one, and `cli.py` does not catch it, so a document that
converted before arrived as a bare traceback. Walked iteratively with a
visited set.

**LEFT_OUTER ignored the cardinality it is justified by.** With a stashed
`ONE_TO_MANY` and no stashed type, `from` is the ONE side, so LEFT_OUTER keeps
unmatched DIMENSION rows and NULL-extends every measure grouped by them -- the
same wrong-number failure, inverted. The assumption now follows the
cardinality, and the message no longer names the wrong side.

**The key deduplication created an upstream warning in silence.** Upstream
compares key columns exactly; folding two spellings into one key leaves the
others uncovered by its rule. Deduplicating is still right -- two unique keys
that are one key in two cases assert a uniqueness the data does not have, and
only silenced upstream by accident -- but saying nothing was not. The coverage
prediction now compares exactly, as upstream does (it folded, which made it
foresee the opposite of what upstream reports), and a qualifying relationship
whose spelling was not the one emitted is reported.

**`is_time` was reported on presence rather than disagreement.** The spec
defaults the flag FROM the datatype, and ThoughtSpot derives the same default,
so a flag agreeing with its datatype costs nothing -- while `is_time: false`
on a temporal column is a loss the first version missed entirely.

**A join type was assumed for joins that are then dropped**, with a remedy
pointing at a join not in the output. Moved below the self-join guard.

Also: `_fold` uses `.lower()`, not `.casefold()`, which maps the German sharp
s onto two characters and read two distinct identifiers as one key; the
unrepresentable-join call site has tests, having had none; its object_ref no
longer collides with a real relationship's; two citations named the wrong
lines of validate.py; a return type still said `dict` where None is now
returned.

Evidence claims trimmed to what was probed: the alias-in-`on` refusal was
observed on a document that was independently invalid, so it cannot be
attributed to the alias names alone, and the two-different-tables case has not
been probed. The Table leg's physical rule is structural and stands.

15 mutations run, 15 killed. 1129 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(thoughtspot): record the join type this converter assumes

A user-visible behaviour change needs a home a reader will find. The
README's Mapping section now states which type is assumed, that it follows
the cardinality so the many side is kept, and that a stashed type is used
unchanged and reported nothing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(thoughtspot): refuse a window whose partition is the query's, not the formula's

Live-probed on a cluster, 2026-11-16, by generating the warehouse SQL for one
formula under two different queries:

    moving_sum(SALES, 1, 0, TIMESTAMP)   asked for by Category
      -> ... over (partition by "CATEGORY" order by "TIMESTAMP" rows between
                   1 PRECEDING and CURRENT ROW)

    the same formula                      asked for by Brand
      -> ... over (partition by "BRAND"   order by "TIMESTAMP" ...)

ThoughtSpot injects the PARTITION BY from the query's own dimensions every
time. The ORDER BY is the formula's, and does translate exactly.

What this module emitted carried the frame and order and NO partition, which
in SQL means one partition over the whole result: a running total across every
category where ThoughtSpot computes one per category. That is a different
number, not an approximate one.

It could not be marked as such either. An Ossie `Expression` has exactly two
fields, `sql` and `dialects`, with no way to say "incomplete" -- so the WARNING
stayed in our issue log while the wrong SQL travelled to the consumer. The
whole `moving_*`/`cumulative_*` ordered family is STASH now, under
TS-EXPR-DYNAMIC-PARTITION.

One form survives and is new: `cumulative_sum(m)` with no order columns
compiles to `sum(...) over ()`, unchanged across two query grains, so it
composes exactly. The old code could not produce it -- it required at least
two arguments and raised on this one.

The frame sign convention is kept as a comment rather than as code. It cost a
real bug to establish (until 2026-09 both offsets shared one "positive means
PRECEDING" rule, which read the wrong rows for every forward-looking window)
and the next implementer should not rediscover it.

PARTIAL is now unused. Kept as a concept, with the question that retired it
written beside it.

1129 tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(thoughtspot): a level of detail is not a window, so emit no SQL for it

`group_aggregate` defines a LEVEL OF DETAIL -- an aggregate at a grain other
than the query's. It is not a window function, and ThoughtSpot does not
compile it as one: live-probed 2026-11-16, every form of it became a nested
GROUP BY, a derived table at the finer grain with an outer re-aggregation.
No window function appeared in the SQL for any of them.

The two shapes do not even return the same thing. A derived table returns one
row per group; `OVER (PARTITION BY ...)` returns one row per input row with
the group total attached. So the `OVER (PARTITION BY ...)` this emitted for a
fixed `{ ... }` grain was the WRONG CONSTRUCT, not a lossy version of the
right one -- and Ossie has no level-of-detail construct to target instead.

Refused now, under TS-EXPR-LEVEL-OF-DETAIL, for a fixed grain and for the
`query_groups ( ) ± { attr }` form alike. They are the same case: a grain
that is not the query's. The four `group_*` shorthands follow.

One shape still composes, and it is the only one that can: `query_groups ( )`
alone with `query_filters ( )` is the query's OWN grain, and an aggregate at
the query's grain is what a bare aggregate already means. Live-probed to a
plain GROUP BY identical in shape to an ordinary SUM.

The reason for that case was recorded backwards. The docstring said its
partition is "declared in the formula rather than completed from the query",
when `query_groups ( )` is explicitly the dynamic one. It is exact BECAUSE it
is dynamic: it always means whatever the query means.

The generated reverse-inventory notes now say which shapes compose, so a
reader of the published reference is not left to infer it from a row that
reads "compose".

1130 tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
ayushtkn and others added 2 commits November 19, 2026 10:25
No schema used uniqueItems, so a key could name one field twice and a list
could carry the same entry twice:

  primary_key: [order_id, order_id]
  unique_keys: [[order_id, order_id]]
  verbalizes: ["{Order} has {Total}", "{Order} has {Total}"]

A key that repeats a field declares fewer columns than it appears to, and a
repeated entry constrains, derives, names or verbalizes nothing the first
already did.

ossie-schema.json marks primary_key and each definition inside unique_keys.
ontology.json marks the eight lists of names and expressions: extends,
identify_by and verbalizes, and requires and derived_by wherever they appear.

models.py mirrors the two core-spec keys. Pydantic 2 dropped unique_items, so
an AfterValidator stands in for it, as min_length already stands in for
minItems.

The list of unique_keys definitions carries no uniqueItems. A definition
written twice is redundant rather than wrong, and a schema error stops the
semantic checks, so the author would lose every reference and SQL diagnostic
over a document that states nothing untrue.

uniqueItems also compares entries as written, while a key means the set of
fields its entries name, and regular identifiers are case insensitive
(expression_language.md), so a schema keyword could not reach these at all:

  primary_key: [order_id, ORDER_ID]
  unique_keys: [[order_id, line_number], [line_number, order_id]]

validate_key_declarations reports both, and the verbatim repeat with them. A
key that names one field twice claims a column it does not have, which is an
error. Two unique_keys definitions holding the same set of fields are one key
written twice, which is redundant, so that is a warning. Definitions are
compared by position rather than by identity, because a YAML alias,
unique_keys: [&k [email], *k], makes one list object the value of two.

An entry whose folded form names no declared field is left out of both: it
names nothing to compare, validate_references reports it as undeclared, and
calling it a repeat would name a field the dataset does not have. An empty
entry, which passes the schema because key items carry no minLength, is
dropped the same way but without discarding the entries beside it.

A dataset that declares two field names differing only in case declares one
field twice, so a key naming both spellings names that field twice and is
reported. validate_unique_names compares field names as written and does not
report the declaration itself; closing that gap is a change of its own, and it
does not make the key's two entries two fields.

A unique key that restates the primary key stays silent: DDL commonly declares
both, and examples/tpcds_semantic_model.yaml does so in five of its datasets.
Relationship from_columns and to_columns are left alone as well: they
correspond positionally, so one column of the from dataset may legitimately be
compared with two columns of the to dataset.

The field tables state the constraints alongside the others they already
state. spec.md describes primary_key and unique_keys as naming each field
once, with a paragraph on the recased and reordered cases; ontology.md marks
its seven documented lists in the convention apache#673 introduced and documents the
root requires, which no row covered. Both Version Histories record the change,
and docs/spec_changes.md records its migration impact.
…erge date

The key paragraph cited Name Resolution for case-insensitive field names,
but that section says nothing about case. The rule lives in
expression_language.md and covers unquoted identifiers only, since quoted
ones match exactly.

The spec_changes.md row records the merge date, so it now carries today's
date rather than the date the change was written.
@jbonofre
jbonofre force-pushed the schema-unique-items branch from 1faf06e to 24c5bf5 Compare November 19, 2026 09:26

@jbonofre jbonofre left a comment

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.

LGTM, thanks @ayushtkn!

The schema constraints and semantic checks consistently reject repeated fields in a key and warn on redundant unique_keys definitions.

@jbonofre
jbonofre merged commit 6deb2fb into apache:main Nov 19, 2026
12 checks passed
christianeu-db added a commit to christianeu-db/ossie that referenced this pull request Nov 20, 2026
Resolve conflicts with apache#705 in core-spec/spec.md and docs/spec_changes.md by
keeping both sides. The apache#726 entries stay last in each change log.

Co-authored-by: Isaac <no-reply@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants