Skip to content

feat(compliance): grade key and relationship portability - #699

Open
MikeNitsenko wants to merge 6 commits into
apache:mainfrom
MikeNitsenko:codex/portability-keys-relationships
Open

MikeNitsenko wants to merge 6 commits into
apache:mainfrom
MikeNitsenko:codex/portability-keys-relationships

Conversation

@MikeNitsenko

Copy link
Copy Markdown
Contributor

The portability grader can report unchanged PORTABLE findings after a converter removes keys and relationships, truncates a compound key, or changes a join's column pairing. Collect and grade these declarations alongside expressions.

Closes #693.

Changes

  • Add key and relationship findings. Preserve key roles and compound grouping; ignore column ordering within a key and alternate-key list ordering.
  • Compare complete join-column pairs and endpoint datasets. Reordering both sides together is PORTABLE; changing the pairing is REWRITTEN. Retain unmatched columns so zip cannot hide truncation.
  • Recover unambiguous key-role changes, split compound keys, changed alternate keys, and relationship renames as REWRITTEN. Ambiguous matches remain drops and additions.
  • Require a diagnostic naming the original key, returned column, and surrogate before classifying a single-column replacement as PLACEHOLDER. Truncation alone is REWRITTEN.
  • Add an independent K0 fixture with the four-part customer-sales-area key, an alternate key, a fact primary key, and their compound relationship. Register the structural elements in the manifest and wire tests and fixture validation into CI.

Expression classification is unchanged. This compares declarations, not warehouse data. No runtime dependencies or schema changes.

Integration with #631

Draft while #631 is pending, following the discussion on #693. Targets current main; K0 stays separate from M0–M6.

The combined grader and fixtures passed 54 tests in a temporary checkout after resolving the two small _collect overlaps and expanding #631's manifest kind allowlist to key and relationship. These integration edits will be applied on rebase after #631 lands. Its pending implementation is not included here.

Validation

  • 49 passed on Python 3.11 with SQLGlot; 49 passed on Python 3.14 without SQLGlot.
  • K0 passed validation/validate.py and the CLI identity check returned all 16 elements PORTABLE, including four structural declarations.
  • Ruff E/F checks, Apache RAT, and git diff --check passed.
  • Regressions cover drops, truncation, role changes, split and ambiguous keys, join pairing and arity, scoped diagnostics, cross-dataset isolation, CLI JSON, and fixture/manifest agreement.

AI assistance

Prepared with AI assistance (Codex).

@github-actions github-actions Bot added the infra label Nov 5, 2026
@MikeNitsenko
MikeNitsenko marked this pull request as ready for review November 9, 2026 19:57
Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:57
@MikeNitsenko

Copy link
Copy Markdown
Contributor Author

Please merge #631 first. Once it lands, I’ll rebase this PR and rerun the checks before #699 is merged.

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Extends the portability grader to evaluate structural declarations (keys and relationships) alongside expressions, adding a dedicated K0 fixture, tests, and CI validation to prevent structural regressions in converter round-trips.

Changes:

  • Collects and grades key and relationship declarations (including key roles, compound grouping, and join-column pairings).
  • Adds K0 structural fixture and comprehensive structural grading tests (including diagnostics/scoping and CLI JSON output).
  • Wires portability grader tests + K0 fixture validation into CI and updates documentation/manifest wording.
File Description
compliance/​portability/​manifest.yaml Updates outcome descriptions and registers the new structural rung K0 and its elements.
compliance/​portability/​k0/​k0_compound_keys.ossie.yaml Adds standalone K0 fixture with compound keys and a compound relationship join.
compliance/​portability/​grader/​test_structure.py Introduces structural grading tests covering keys/relationships, ambiguity rules, diagnostics, and fixture/manifest alignment.
compliance/​portability/​grader/​grade.py Implements structural collection, structural repair pairing, and surrogate-diagnostic handling for keys.
compliance/​portability/​grader/​README.md Documents structural grading rules (naming/comparison/diagnostic requirements) and how to run tests.
compliance/​portability/​README.md Links the K0 rung and structural grading rules into the portability ladder docs.
.github/​workflows/​validation-ci.yml Runs portability grader tests and validates the K0 fixture in CI; expands workflow path filters to portability files.

Review effort: Lite

Comment thread compliance/portability/grader/grade.py Resolved
Comment thread compliance/portability/grader/grade.py Resolved
Comment thread compliance/portability/grader/grade.py Resolved
@MikeNitsenko

Copy link
Copy Markdown
Contributor Author

@jbonofre could you please take a look when you get a chance? thanks!

@christianeu-db christianeu-db 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.

Thanks @MikeNitsenko! Left two comments; the fixture version needs fixing before merge, and I'll take another look once this is rebased onto #631.

Comment thread compliance/portability/grader/grade.py Resolved

@christianeu-db christianeu-db 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.

Thanks @MikeNitsenko, both points are addressed. I'll take another look and approve once #631 lands and this is rebased onto it.

@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.

The new validation step covers k0 only, so the ladder fixtures under m*/ still never run through validate.py in CI (eight on main, thirteen once #631 is in). One glob covers them all, and on the merge with main it passes 9 of 9:

      - name: Validate portability fixtures
        run: uv run validation/validate.py compliance/portability/*/*.ossie.yaml

make compliance-validate globs m*/, so k0 is not in it either; the same glob there would keep the two in step.

@MikeNitsenko
MikeNitsenko force-pushed the codex/portability-keys-relationships branch from 9366204 to b494f1b Compare November 20, 2026 11:12

@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.

Two cases from real converter returns, inline. They come from the interop run on ossie-converters#247 with this branch as the submodule. On the same returns the metric and field findings are the same as with main's grader.

repaired = _repair_by_expression(dropped, added_elements, owners, aliases)
repaired_in = {id(a): b for a, b in repaired}
repaired_out = {id(b) for _, b in repaired}
structural_repairs = _repair_by_structure(dropped, added_elements)

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.

Keys and relationships do not follow a dataset the converter renamed, though expressions do. lightdash returns M4's sales as orders, after its source table, and the relationship comes back as orders_to_customers:

relationship  sales_to_customer    DROPPED_SILENT
relationship  orders_to_customers  ADDED

The fields and the metric of that dataset grade REWRITTEN through _dataset_aliases, and the converters that only rename this relationship (cube, dbt, omni and others) get "identity not preserved". In a hand-made return a key does the same: sales.primary_key dropped, erp_sales.primary_key added. Could the returned declarations go through aliases before they are compared? With that, this case grades "identity not preserved: returned as 'orders_to_customers'" and the suite still passes.

for part in parts:
remaining.remove(part)
pending.remove(element)
# A changed alternate key has no stable name. Match only one missing key to

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 pairs a dropped key with a restated primary key. thoughtspot returns K0 without [area_code] and with the primary key repeated under unique_keys:

key  customer_sales_area.unique_keys["area_code"]  REWRITTEN  review: key columns changed to ('customer', 'distr_channel', 'division', 'sales_org')

The key was dropped. honeydew repeats the primary key the same way and gets ADDED for it. Leaving out a returned unique key whose columns are the dataset's returned primary key gives DROPPED_SILENT plus ADDED here, and the suite still passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compliance/portability: grade keys and relationships, not only expressions

4 participants