Repository navigation
feat(core-spec): make relationship cardinality explicit - #794
christianeu-db wants to merge 6 commits into
Conversation
f3c0012 to
13813a0
Compare
A relationship may declare `cardinality`: ManyToOne, OneToMany, or OneToOne, stated from `from` to `to`. An absent value means ManyToOne, so existing documents keep their meaning. There is no many-to-many value. Layer 2 semantics are unchanged; its mapping text now maps `cardinality`. Layer 3 paths follow every step that does not increase granularity: from `from` to `to` for ManyToOne and OneToOne, and from `to` to `from` for OneToMany and OneToOne. Filter propagation stays out of scope. The validator checks key coverage on each one side of the cardinality. The schema, spec.yaml, the spec type generator, and the Python SDK gain the Cardinality enum. Discussion: https://lists.apache.org/thread/1kggjhy5tjqjyvlf6rsvs9ygxt6x9zkr Co-authored-by: Isaac <no-reply@databricks.com>
13813a0 to
d6267ef
Compare
kayemkim
left a comment
There was a problem hiding this comment.
The glossary in relational_semantics.md still has the old direction: "Relationship (Ossie). … from is the many side, to the one" (line 1242). The mapping table and Section 11.3 in the same file are updated, and this sentence is not.
| 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. |
There was a problem hiding this comment.
#803's lowering walks a relationship from from to to only and doesn't read cardinality (edges and paths() in ost/src/ossie_ost/lowering.py). With both branches merged, a relationship declared from the other dataset as OneToMany goes the wrong way:
from: customers, to: orders, cardinality: OneToMany
orders.total_revenue by customers.region E_NO_PATH
customers.customer_count by orders.order_id lowers, one row per order
Declared from orders with no cardinality, the first gives EAST 150 and WEST 30 and the second is E_NO_PATH. Whichever of the two lands second needs the other's rule, and a wide table case with a OneToMany relationship would hold it.
There was a problem hiding this comment.
Done now that #803 has landed (d0fb147). The lowering reads cardinality: a step crosses a relationship from from to to for ManyToOne and OneToOne, and from to to from for OneToMany and OneToOne. Instead of adding a model, retail_model now declares customers_to_visits from customers as OneToMany. Your two examples are the new a22 (visit count by customer region: NORTH 2, WEST 1) and e26 (customer count per visit: E_NO_PATH). Both fail with the #803 lowering, and a03 lowers as before.
| "from": (from_ds, from_dataset, from_columns, missing_from), | ||
| "to": (to_ds, to_dataset, to_columns, missing_to), | ||
| } | ||
| for side in _ONE_SIDES.get(rel.get("cardinality", "ManyToOne"), ()): |
There was a problem hiding this comment.
Called on a document the schema has not vetted, a cardinality that is a list or a mapping raises TypeError: unhashable type here, where main returns its findings. The CLI is not affected, since it stops at the schema error. An isinstance(cardinality, str) check before the lookup keeps this to the shape guards the docstring above describes.
There was a problem hiding this comment.
Good catch, thanks. Fixed in b52dc54: a non-string cardinality now skips key coverage the same way an unknown value does, and the unknown-cardinality test now covers a list and a mapping.
Also fixed the glossary entry in relational_semantics.md in b52dc54. It now names the optional cardinality instead of saying that from is the many side.
validate_references skips key coverage when `cardinality` is not a string, as it already does for an unknown value. A list or a mapping raised TypeError when the checks ran on a document that failed the schema. The relational_semantics.md glossary no longer says that `from` is the many side. It names the optional `cardinality` instead. Co-authored-by: Isaac <no-reply@databricks.com>
|
+1 on the placement, and on keeping filter flow out of scope. The placement is the part that matters most to a converter. A join is a fact about One thing I would like to raise before the 28th, because it touches the validation The PR says the validator checks key coverage on each one side of the cardinality. That is worth separating now, so the attribute does not get blamed later for a case it On what the condition should look like, I have a measurement rather than an opinion. I built his case on two platforms this week. Four fact rows against a six-row period 32 is the true figure. On Snowflake the range form is written on the relationship, as Both platforms gave the same two numbers, and both matched the warehouse. The part I would ask the list to note is which condition form travels. Snowflake also I want to be careful here, because the operator is not the problem. A bare The problem is using So if a condition vocabulary is ever added beside the cardinality value, a half-open For Gareth's case specifically, this is also a practical answer. His consultant dataset None of this needs to ride on this PR. I would rather it merged as it stands than grew. Happy to contribute the probe as a compliance case if it is useful. It is ten rows of |
…ality # Conflicts: # python/src/ossie/__init__.py # python/src/ossie/models.py # python/tests/test_models.py # validation/validate.py
The cardinality tests build an OssieSemanticModel, which replaced OssieDocument as the semantic model class in apache#651. A coverage warning is wrapped to the line limit that ruff checks since apache#818. Co-authored-by: Isaac <no-reply@databricks.com>
A step of the Layer 3 lowering now crosses a relationship from `from` to `to` if its cardinality is ManyToOne, the default, or OneToOne, and from `to` to `from` if it is OneToMany or OneToOne (Section 4). The join condition starts from the dataset where the step starts. retail_model declares customers_to_visits from customers, as OneToMany, so a03 crosses it from visits to customers and lowers as before. a22 groups visits by customer region, and e26 checks that customers does not reach visits. With the lowering of apache#803, a22 raises E_NO_PATH and e26 lowers to one row per visit. Co-authored-by: Isaac <no-reply@databricks.com>
Thanks for the feedback @djwaldo. I think addressing the complex conditions in #4 would be a great extension |
|
Thanks @christianeu-db — Discussion #4 is the right home, and I have written the One thing on this PR itself, though, before the 28th. Section 4 now contradicts
Two lines below it, unchanged by the diff:
The hunk ends at the third bullet, so that paragraph was never revisited. On Also minor: the |
Section 4 still said that only many-to-one steps are supported, which contradicted the new step rule for OneToMany and OneToOne. The paragraph now excludes steps in other directions, and Section 1.2 refers to many-to-one steps instead of many-to-one relationships. Co-authored-by: Isaac <no-reply@databricks.com>
Good call - I've updated the diff to incorporate that feedback |
kayemkim
left a comment
There was a problem hiding this comment.
d0fb147 closes the lowering point. The model from my earlier comment, declared from customers as OneToMany, now gives EAST 150 and WEST 30 and raises E_NO_PATH the other way, the same as when it is declared from orders. I also ran it with different column names on the two sides and with a OneToOne relationship crossed from each end, and the join conditions and paths come out as Section 4 says.
The glossary sentence and the guard are in as well, so this looks good to me.
Summary
A relationship may declare
cardinality: ManyToOne, OneToMany, or OneToOne, stated fromfromtoto. An absent value means ManyToOne, so existing documents keep their meaning. There is no many-to-many value.Layer 2 semantics are unchanged; its mapping text now maps
cardinality. Layer 3 paths follow every step that does not increase granularity: fromfromtotofor ManyToOne and OneToOne, and fromtotofromfor OneToMany and OneToOne. Filter propagation stays out of scope.The
ostlowering of #803 follows the same steps. The retail fixture now declarescustomers_to_visitsfromcustomersas OneToMany, so wide table casea03and the newa22cross it fromvisitstocustomers, and the newe26checks thatcustomersdoes not reachvisits.The validator checks key coverage on each one side of the cardinality. The schema, spec.yaml, the spec type generator, and the Python SDK gain the Cardinality enum.
Discussion: https://lists.apache.org/thread/1kggjhy5tjqjyvlf6rsvs9ygxt6x9zkr
Related Issues
#50, apache/ossie-converters#293 to update converters
Checklist
Specification
core-spec/and follow the existing structure[DISCUSS]thread ondev@with a stated end date, and reach lazy consensus (or pass a[VOTE]) before mergedocs/spec_changes.mdrecords rationale, compatibility and migration impact, or the PR explains why no entry is neededValidation
validation/are updated if the spec changedDocumentation
docs/is updated to reflect any user-facing changesTests
pytest/ CI green)Compliance
NOTICEand/orLICENSEhave been updated per ASF policy