Skip to content
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

add secondary key dictionaries #303

Merged
merged 24 commits into from
Jul 23, 2024

Conversation

hendrikmuhs
Copy link
Contributor

@hendrikmuhs hendrikmuhs commented May 25, 2024

Secondary key dictionaries match a set of key before the real matching. Those secondary keys can be arbitrary strings, e.g. a user, account or a tenant id.

At compile time, a list of secondary keys must be provided at construction, e.g. ["region", "account_id", "user_id"]. The order defines matching order. For every entry as well as for every match operation an unordered map of keys and values must be provided :

{
    "account_id": "xyz", 
    "region": "eu-west",
    "user_id": "abcd"
}

Example use:

dictionary.complete("sie", {"account_id": "xyz", "region": "eu-west", "user_id": "abcd" })

With other words: APIs are equal to ordinary dictionaries with the extension of a map with secondary keys next to the primary key.

Implementation details

Before doing the real matching, the root state is altered according to the additional secondary key(s) by matching a prefix. Given the "moved" start state, re-use the existing match functionality from Dictionary. This is implemented by wrapping an ordinary dictionary (most code changes are just refactorings to provide the altered start state).

The SecondaryKeyDictionaryCompiler is similar, it wraps the existing DictionaryCompiler. In addition it:

  • alters the lookup key by prefixing the secondary keys
  • the list of secondary keys are stored as property
  • The secondary key values are stored as dictionary which gets concatenated to the normal dictionary

To efficiently store secondary key values, values get replaced by a short representation. This helps e.g. for cases where secondary key values are long, e.g. UUIDs. Equally to the primary dictionary the replacement dict uses memory mapping.

Python bindings

Unfortunately the python bindings required a lot of boiler plate code. In theory it could be auto-generated, however I wonder how much effort we should put into the autowrap generated code. I am playing with the idea to migrate to pybind11.

@hendrikmuhs hendrikmuhs force-pushed the secondary_key_playground branch from e7e6d50 to fce56e4 Compare June 3, 2024 18:49
@hendrikmuhs hendrikmuhs changed the title playground for secondary key dictionaries add secondary key dictionaries Jun 17, 2024
@hendrikmuhs hendrikmuhs marked this pull request as ready for review June 17, 2024 19:21
@hendrikmuhs hendrikmuhs merged commit 0f0ffa4 into KeyviDev:master Jul 23, 2024
18 checks passed
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.

1 participant