google / google/badwolf

HAVING clause should not require parentheses when involving AND or OR

Open
#111 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
984
Forks
65
PR merge metrics
No merged PRs in 30d

Description

When using a HAVING clause, it should not be required for the expressions around AND or OR operators to be surrounded by parentheses.

To illustrate, nowadays the following query in BQL works:

```
SELECT ?parent_name, ?child_name, ?child_height
FROM ?family
WHERE {
?parent ID ?parent_name "parent_of"@[] ?child ID ?child_name .
?child "height_cm"@[] ?child_height
}
HAVING (?child_height > "150"^^type:int64) AND (?parent = /u);
```

But the following does not:

```
SELECT ?parent_name, ?child_name, ?child_height
FROM ?family
WHERE {
?parent ID ?parent_name "parent_of"@[] ?child ID ?child_name .
?child "height_cm"@[] ?child_height
}
HAVING ?child_height > "150"^^type:int64 AND ?parent = /u;
```

It yields the following error:

```
[FAIL] [ERROR] Failed to parse BQL statement with error Parser.parse: Failed to consume symbol HAVING, with error failed to consume all token; left over [{false 0xc00021af50} {false 0xc00021afa0} {false 0xc00021aff0} {false 0xc00021b040}]
```

This may be related with the `NewEvaluator` inside `expression.go` in semantics, as the grammar is not the one restricting this behavior.

You can use the code in the file below to reproduce the aforementioned results.

[parentheses_in_having.pdf](https://github.com/google/badwolf/files/4871985/parentheses_in_having.pdf)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.