-
Notifications
You must be signed in to change notification settings - Fork 5
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
batch: Use github.com/expr-lang/expr #41
Conversation
Looks pretty good from the reference link. I actually expect regexp queries to be pretty rare overall, I suspect we're likely to want something closer to this as an example batch filter:
Which it seems like this project can handle just fine, including support for some extra string management functions. |
How good is their error reporting? We're going to be exposing this to end users, so it'd be nice to have clear error messages so they can easily tell what's wrong with their filter and can fix it. |
The error returned from the expression package look like this: Example 1:
Example 2:
It will be our responsibility to prefix these errors with additional meaningful details about the step, that failed (e.g. compiling the expression or running it). |
replace include/exclude regex with include expression Signed-off-by: Lucas Bremgartner <lucas.bremgartner@futurfusion.io>
Signed-off-by: Lucas Bremgartner <lucas.bremgartner@futurfusion.io>
cffdc7d
to
3a43e2e
Compare
@stgraber, @gibmat I addressed the review comments and I extended the poc such that the more complex / realistic example provided by @stgraber in #41 (comment) becomes possible to filter for (see testcase https://github.com/FuturFusion/migration-manager/pull/41/files#diff-e3d7bfdcdd97202d2d2778d99715109ec9cb180125c0c318a51059193f027856R118-R124). |
replace include/exclude regex with include expression
@gibmat, @stgraber I looked into the task of improving the way we define a batch. In the respective task (Figure out better way of defining a batch) we listed 3 options:
After quickly checking on them, I found a 4th option, that was mentioned in an issue on govaluate and I found, that this actually the best option in my opinion.
This PR implements a PoC with the above mentioned expression package. Since this package provides complete boolean expressions, we are able to replace both, the include and the exclude regex we used so far. The expression package also allows to match against regex, so there is no reduction in functionality at all.
By passing the instance to the expression evaluation as argument, one does have access to all the methods (and fields, if the argument is a struct), which allows as for more fine grained logic if an instance should be included or excluded from a batch.
The functionality of the expr package can be extended by custom function. I also added an example for this by adding the filepath.Dir and filepath.Base functions additionally.
I think, the provided test cases do explain the usage the best.
Additional resources:
Side note: While integrating the package into our code base, I discovered an issue with the way interfaces are handled. There is already an open issue for this, so I added some context there as well: expr-lang/expr#744