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

FILTER keyword for latest anchor queries (grammar/lexer/hooks) #149

Merged
merged 15 commits into from Oct 9, 2020

Conversation

rogerlucena
Copy link
Contributor

This PR comes as the first step on #129, starting to set up a FILTER keyword in BadWolf at the grammar, lexer and hooks levels. The first FILTER function chosen to be implemented is the latest one, to solve what was requested by #86.

It would be very useful to have in BQL a FILTER keyword that could allow us to filter out part of the results of a query in a level closer to the storage (closer to the driver), improving performance. This is exactly what this PR starts to introduce, setting up the foundations for this keyword in the grammar, lexer and hooks.

The final objective is to allow the user to specify, inside of WHERE, which bindings they want to apply a FILTER to, proceeding with a more fine-grained lookup on storage, avoiding unnecessary retrieval of data and optimizing query performance.

To illustrate, queries such as the one below will in the future be possible:

SELECT ?s, ?p, ?o
FROM ?test
WHERE {
    ?s ?p ?o .
    FILTER latest(?p)
};

That would return all the temporal triples of the ?test graph that have the latest timestamp of the time series they are part of (a recorrent use case in BadWolf), skipping immutable triples found along the way.

Regarding their position inside WHERE, FILTER clauses must come after all the graph pattern clauses, just by the end of the WHERE (closer to its closing bracket). Regarding trailing dots, a FILTER clause is understood just like any other graph clause inside of WHERE: the trailing dot is mandatory at the end of each clause (FILTER or graph ones indistinguishably), with the exception of the last one (for which the dot is optional).

@thiagovas thiagovas linked an issue Oct 6, 2020 that may be closed by this pull request
@rogerlucena rogerlucena marked this pull request as draft October 8, 2020 19:29
@rogerlucena rogerlucena marked this pull request as ready for review October 9, 2020 14:18
@thiagovas thiagovas merged commit b515c3e into google:master Oct 9, 2020
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.

FILTER keyword
3 participants