VForWaTer / metacatalog

Modular metadata management platform for environmental data.
https://vforwater.github.io/metacatalog
GNU General Public License v3.0
3 stars 1 forks source link

Find by detail #53

Closed mmaelicke closed 2 years ago

mmaelicke commented 4 years ago

We need some ideas, how the details can be utilized to find Entry records by ID. Either add as parameter to api.find_entry or put into a new api endpoint.

AlexDo1 commented 2 years ago

api.find_entry already accepts the parameter details since v0.2.2. Entries are found by passing name=value pairs as a dictionary. The name=value pairs must exactly match the key and the value in raw_value (jsonb) stored in metacatalog.

https://github.com/VForWaTer/metacatalog/blob/9a046f38191153b8326d79b99d76eacb1816b17b/metacatalog/api/find.py#L1028-L1046

Can we close this issue or did you want to implement other functionalities @mmaelicke?

AlexDo1 commented 2 years ago

sqlalchemy JSONB functions: https://docs.sqlalchemy.org/en/14/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSONB.Comparator.contains

mmaelicke commented 2 years ago

@AlexDo1 please provide a unittest to make sure that the current implementation can:

  1. find details by key
  2. find details by key and value
  3. find both nested (to one level)
  4. ~only value?~
AlexDo1 commented 2 years ago

Two of these tests already exist:

  1. find details by key and value: https://github.com/VForWaTer/metacatalog/blob/1ff57d379f49a45dd1aef07c3553b12e4514fc71/metacatalog/test/test_api_add_find.py#L274-L275
  2. find both nested (to one level): https://github.com/VForWaTer/metacatalog/blob/1ff57d379f49a45dd1aef07c3553b12e4514fc71/metacatalog/test/test_api_add_find.py#L277-L279

When searching for details, details must be a dictionary exactly representing the detail associated to an entry: https://github.com/VForWaTer/metacatalog/blob/9a046f38191153b8326d79b99d76eacb1816b17b/metacatalog/api/find.py#L1029-L1031

So it is currently not possible to (1.) find details by key and (4.) find details by value.

@mmaelicke do you want me to implement the functionality to find entries via details based only on the key or value?

mmaelicke commented 2 years ago

Great. Yes, I think at least the key-only part should be implemented. The best solution would be to implement like this:

  1. key and value:

    api.find(details=dict(mykey='myvalue'))  # isinstance(dict)
    api.find(details=dict(mykey='%value'))   # isinstance(dict) and '%' in value
  2. key only:

    api.find(details='mykey')              # isinstance(str)
    api.find(details=['mykey', 'mykey2'])  # isinstance(list)
  3. value only:

    api.find(details={'*': 'myvalue'})     # isinstance(dict) and key=='*'

Let me know if this is not as straightfoward as expected. But SQLAlchemy should have the functionality implemented.