8000 model extension: unique keys by cmungall · Pull Request #16 · linkml/linkml-model · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

model extension: unique keys #16

8000 New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2021
Merged

model extension: unique keys #16

merged 4 commits into from
Jun 30, 2021

Conversation

cmungall
Copy link
Member
@cmungall cmungall commented Apr 2, 2021

This introduces compound keys

need to add tests

this example should illustrate concept:

classes:
  isotope:
    slots:
      - id
      - atomic number
      - neutron number
      - symbol
   compound_keys:
     proton_neutron_key:
       unique_for: isotope
       primary: false
       compound_key_slots:
         - atomic number
         - neutron number
    symbol uniqueness:
      unique_for: isotope
       primary: false
      compound_key_slots:
         - symbol

slots:
   id:
    identifier: true

See linkml/linkml#42

@cmungall cmungall requested a review from hsolbrig April 2, 2021 00:37
@cmungall cmungall marked this pull request as draft April 2, 2021 00:38
@hsolbrig
Copy link
Contributor
hsolbrig commented Apr 6, 2021

We should draft a prototype of what compound keys looks like in each of the emitted idioms:

  • markdown - how to document
  • python - what does a compound key look like in generated python and what contract(s) does it enforce
  • owl -
  • rdf -
  • json schema -
  • others?

@cmungall
Copy link
Member Author
cmungall commented Apr 7, 2021

good Qs, rough sketch of answers:

markdown

should pretty much follow the yaml. Each compound key on one line. E.g.


### Compound Keys

1. proton_neutron_key: an isotope is uniquely identified by the combination of (atomic number, neutron number)
2. symbol_key: an isotype is uniquely identified by the symbol field

python

this may not be easy to validate at the python level

rdf/owl

trivial mapping to hasKey

jsonschema

no equivalent?

@cmungall
Copy link
Member Author

this is also necessary for sqlalchemy bindings - each class must have a primary key (which may be compound)

@cmungall cmungall marked this pull request as ready for review June 29, 2021 21:06
@cmungall cmungall changed the title model extension: compound keys model extension: unique keys Jun 29, 2021
Copy link
Contributor
@hsolbrig hsolbrig left a comment

Choose a reason for hiding this comment

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

I wonder whether we should use this as an opportunity to create a new mixin that has the set of slots and mixins that you've enumerated below. I think we ended up with a similar set in the enumerations and I'd prefer to minimize repetition and fragmentation.

If you agree, will be happy to make the proposal

@cmungall
Copy link
Member Author

regarding nul//none values in the key:

We could have slot to indicate whether nulls are to be treated as unknown vs a special None value. If the former, then it's not valid to translate the unique_key to SQL unique constraint (since Nulls represent unknowns)

@cmungall cmungall merged commit 2b930be into main Jun 30, 2021
@cmungall cmungall deleted the compound-key branch June 30, 2021 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0