Skip to content

SQL: HAVING throws an exception when used directly on a group column #31726

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

Closed
costin opened this issue Jul 2, 2018 · 1 comment
Closed

SQL: HAVING throws an exception when used directly on a group column #31726

costin opened this issue Jul 2, 2018 · 1 comment

Comments

@costin
Copy link
Member

costin commented Jul 2, 2018

When HAVING is used directly on a column (not on an aggregate over a column) it fails with a NPE since the code expects a different path.

SELECT languages AS l, COUNT(*) AS c FROM emp GROUP BY l HAVING l > 2

throws

java.sql.SQLException: Server encountered an error [null]. [java.lang.NullPointerException
	at org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate.aggPaths(ScriptTemplate.java:53)
	at org.elasticsearch.xpack.sql.querydsl.agg.AggFilter.<init>(AggFilter.java:28)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator$BinaryComparisons.asQuery(QueryTranslator.java:559)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator$BinaryComparisons.asQuery(QueryTranslator.java:504)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator$ExpressionTranslator.translate(QueryTranslator.java:844)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator.toQuery(QueryTranslator.java:157)
	at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldFilter.rule(QueryFolder.java:161)
	at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldFilter.rule(QueryFolder.java:153)
...
@costin costin added >bug :Analytics/SQL SQL querying labels Jul 2, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

costin added a commit to costin/elasticsearch that referenced this issue Jul 6, 2018
Improve Verifier to allow HAVING clauses only on aggregates

Close elastic#31726
costin added a commit that referenced this issue Jul 11, 2018
Improve Verifier to allow HAVING clauses only on aggregates

Close #31726
costin added a commit that referenced this issue Jul 11, 2018
Improve Verifier to allow HAVING clauses only on aggregates

Close #31726

(cherry picked from commit 6136e49)
costin added a commit that referenced this issue Jul 11, 2018
Improve Verifier to allow HAVING clauses only on aggregates

Close #31726

(cherry picked from commit 5440fb4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants