-
Notifications
You must be signed in to change notification settings - Fork 135
Improve query interpretation format #720
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
Improve query interpretation format #720
Conversation
|
@garberg I'm not sure we should actually merge this just yet but I want your feedback on the look of it at least. I have updated the web UI to display the new format but it isn't very visually pleasing so before merging to master we might want to revisit that and perhaps write something with AngularJS. |
|
I realize I should perhaps comment on the structure, because while the interpretation format can closely follow the query hierarchy it doesn't have to. In fact, in many cases it is desirable that it does not. Performing a smart_search_pool on the string 'foo' will result in a query that looks like this: And inserting the query interpretation in this, it could look like this: Which in turn would generate two interpretation lines in the CLI or web UI. The alternative is this: Ie, we let one interpretation node describe a deeper structure so that it a bit briefer. This is often the preferred way. |
|
The only comment I have is regarding the different keys in the interpretation-dict which varies a bit in the smart_search_prefix-function. Depending on the input the interpretation sometimes has an As soon as the interpretation is displayed prettier in the web UI I'm happy with merging this pull request. |
|
What do you think of this format for the CLI: As compared to what the PR currently renders: I quite like it. It's more compact (not width-wise though) and is easier to read. |
|
Okay, here's a new version of the interpretation in the web UI I know alignment is a little bit off but this is a hack. I really don't want to spend more time on it right now. It should be rewritten as AngularJS thingy anyway. @garberg feedback plxz. This is the last thing for this PR. Please comment on looks of interpretation in CLI (previous comment) and web UI. If we are happy, I'll update the PR and we should be good to merge. |
|
Looks great! The hierarchies are quite deep, but that's just motivation to build the support for multi-parameter operators (so only one AND-operator is needed for multiple values) we've spoken about for so long time 😄 |
The code for parsing a smart search prefix query wasn't very testable as it issued a database query after parsing the query. This has been refactored into two functions so that the parsing is done separately and thus becomes testable. Four tests are added to check for three different types of queries and a fourth to check that we correctly detect non-balanced quotes.
Instead of sending a separate data struct (which was just a list) with the query interpretation, we modify the query dictSQL and insert our interpretation into it which means that the change of discrepancy between the actual query and the interpretation is minimized. Naturally, this new format allows us to express a much more complex query than before when we assumed all entries in the interpretation list to be ANDed together. This change only affects the smart_search_prefix function at this time and subsequently the format for VRFs and pool searches remain the same. Part of SpriteLink#683.
The CLI now accepts the improved query interpretation format implemented by nipapd for prefixes. Part of SpriteLink#683.
The web UI now accepts the improved prefix query interpretation format implemented in nipapd. We need to work on the layout of the interpretation as it is quite verbose and not so pretty in its current incarnation. I suppose we should rewrite the whole thing using AngularJS as well, unfortunately I'm on a plane and haven't worked enough with Angular to remember from the top of my head how to implement this nicely. Part of SpriteLink#683.
The unittests testing the smart parser now passes as the expected results are updated with the extra interpretation struct according to the new and improved query interpretation format for prefixes. Part of SpriteLink#683.
This implements for VRF the same improved query interpretation format that was implemeneted for prefixes. In essence, it is more tightly integrated with the query and is therefore just as expressive as the query itself. Part of SpriteLink#683.
The CLI now accepts the improved query interpretation format implemented by the backend for VRFs. Part of SpriteLink#683.
This implements for pools the same improved query interpretation format that was implemented for prefixes and VRFs. Part of SpriteLink#683.
The CLI now accepts the improved query interpretation format implemented by the backend for pools. Part of SpriteLink#683.
This implements for ASNs the same improved query interpretation format that was implemented for prefixes, VRFs and pools. Part of SpriteLink#683.
In addition to testing the prefix smart query parser this adds similar tests for the smart query parsers of VRF and pool queries. Part of SpriteLink#683.
Flip order of showing interpretation and checking if we got any results so that we always display the interpretation, even when we don't find any matches. Part of SpriteLink#683.
This makes it much easier to overlook the interpretation. Visual brackets are used to show which atoms a boolean operator (AND/OR) joins together. It is also more compact than the previous format. Part of SpriteLink#683.
Instead of printing AND operators on a separate line they are now on the same line as a match statement making the output a lot more compact in number of lines, although a bit wider. Through some ASCII art we try to show which statements are joined together by a boolean operator. I believe readability is greatly enhanced by this change, though that might be biased ;)
171d0a3 to
85d5a25
Compare
|
Okay, did a slight rebase so had to force push. @garberg This should now be ready to go. Have a last read if you want and push the magic button ;) |
|
k'POW! |
Improve query interpretation format


This changes the query interpretation format to a new and improved format that is able to correctly model a query. The old format is a list with an entry for each element, which doesn't allow correctly grouping a more complex query.
For example, the query 'a b c' means we have three elements; a, b and c. There is an implicit boolean AND operator between them and so the query interpretation could be correctly represented with just a list and an implicit AND operator. However, as we wish to support a query like 'a AND (b or c)' we now have a different operator and it is (explicitly) grouped in a way that isn't possible to express with a flat list. The new format follows the query format, ie it is a hierarchy and the new query interpretation format can thus express all possible queries.