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

Support time binding comparisons inside HAVING clauses #134

Merged
merged 10 commits into from
Aug 24, 2020

Conversation

rogerlucena
Copy link
Contributor

@rogerlucena rogerlucena commented Aug 17, 2020

If we extract a time binding inside the WHERE clause it would be useful to be able to use it for comparisons inside the HAVING clause, creating conditions around that binding. This PR comes to add support for this.

To illustrate, the query below is now possible:

SELECT ?p, ?time
FROM ?test
WHERE {
    /u<peter> ?p AT ?time ?o
}
HAVING ?time < 2016-03-01T00:00:00-08:00;

On which the time binding ?time extracted with the AT keyword can now be compared to a time literal (2016-03-01T00:00:00-08:00 above) inside the HAVING clause.

You can also combine it with ID bindings to create more complex conditions inside the HAVING clause:

SELECT ?s, ?p, ?p_id, ?time
FROM ?test
WHERE {
    ?s ?p ID ?p_id AT ?time ?o
}
HAVING (?p_id < "in"^^type:text) AND (?time > 2016-02-01T00:00:00-08:00);

NB: The comparisons with a time literal are not lexicographical, they indeed have the semantics of a time comparison: we consider the time zone, for example (as one should expect).

So, if you use a condition like ?time = 2012-03-10T00:00:00-08:00 in your HAVING clause, you may also get triples in your query result with the ?time binding being 2012-03-10T09:00:00+01:00 (which is equivalent to the timestamp requested in the condition, being in another time zone).

For more examples on this, please refer to the new tests added in planner_test.go and expression_test.go.

@rogerlucena rogerlucena force-pushed the at-binding-comparison branch 2 times, most recently from 179752d to bc200ec Compare August 17, 2020 17:40
@rogerlucena rogerlucena marked this pull request as draft August 18, 2020 14:41
@rogerlucena rogerlucena force-pushed the at-binding-comparison branch 3 times, most recently from 47d3630 to f6ca722 Compare August 18, 2020 22:42
@rogerlucena rogerlucena marked this pull request as ready for review August 21, 2020 13:48
@rbkloss rbkloss requested review from rbkloss and thiagovas and removed request for rbkloss August 21, 2020 13:54
bql/semantic/expression.go Show resolved Hide resolved
bql/semantic/expression_test.go Outdated Show resolved Hide resolved
bql/semantic/expression_test.go Outdated Show resolved Hide resolved
bql/semantic/expression_test.go Show resolved Hide resolved
@thiagovas thiagovas merged commit 792b20a into google:master Aug 24, 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.

None yet

4 participants