-
Notifications
You must be signed in to change notification settings - Fork 7
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
Translate parser to database query language #6
Comments
Hi @albehrens! You're certainly welcome for the lib – all the hard work is being done by apg-lib 🙃 The point you're bringing up has been discussed internally here, and our very first implementation actually made some attempts in that direction. However, in our use case the schemas specified by SCIM do not match our own internal schema: not only do field names differ, but the actual structure of entities, relational constructs and even concepts are quite different. The necessary transformations might be able to solved in the database layers using views, but even that assumes everything exists on a single database. For our use case, we only have single-digit thousands of users (as this is only being used on internal systems) so it was far easier to just load and transform the entities in code and then apply the filter. I will say that while the examples show arrays being filtered, the returned functions can be used for observables or async iterators such that you don't have to load everything into memory at once. All of that said, if you're interested in tackling this I can certainly point you in the right direction! Generating GrammarEssentially, the grammar is all defined in grammar.abnf. This was hand-written while referencing the formal syntax from the spec, but with a focus on practicality (left recursion, for example, isn't supported by most tools) and with a goal of naming each meaningful syntax feature. Running When a new filter expression is to be compiled, it first is parsed: scim-query-filter-parser-js/src/index.ts Lines 46 to 50 in 6cb88fe
Then, we use APG's AST translation utilities to translate it, providing an instance of scim-query-filter-parser-js/src/index.ts Lines 52 to 54 in 6cb88fe
This works by traversing the parsed grammar, and calling the registerred callbacks as the corresponding symbols are encountered. scim-query-filter-parser-js/src/index.ts Lines 27 to 43 in 6cb88fe
Each of these "callbacks" manipulates the I created the General Building & TestingObviously this is written in TypeScript. You can compile to JS by running Tests are run from the compiled files by either I often have two panes open in iTerm2: one building, one testing. Helpful links:
Hope that helps! |
Hey @mike-marcacci! Thank you very much for your elaborate response. I will definitely have a look at the hints and resources that you gave. We "only" have a few thousand users per client as well. So scanning them before filtering is probably fine. We will probably look into this issue more closely if we actually run into a performance problem. |
@mike-marcacci Really wish I saw this discussion earlier! Your motivation for a simple-to-use expression-based filterer makes a lot of sense now (N is small for you, and it's internal-use). As for the lazy-filtering, it's nice to be able to "stream" users into the filterer expression to avoid using tons of memory at any given time, but that still doesn't solve the problem of having to do the filtering processing outside of the DB layer (e.g. having to fetch all the results in the first place). This library should not solve the
|
First of all I would like to thank the authors of this repository for their contribution. This package helped us to prototype our own SCIM server quickly. Unfortunately the way that this filter parser works is not very efficient. We have to load all our SCIM users into memory or at least scan our whole database.
Is there maybe an opportunity to translate your filter parser to a database query language like SQL or Elasticsearch's Query DSL? I would like to contribute and do it myself. I would only ask for some advise on where I should begin?
The text was updated successfully, but these errors were encountered: