add secondary key dictionaries#303
Merged
hendrikmuhs merged 24 commits intoKeyviDev:masterfrom Jul 23, 2024
Merged
Conversation
e7e6d50 to
fce56e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 :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
SecondaryKeyDictionaryCompileris similar, it wraps the existingDictionaryCompiler. In addition it: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.