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

SQL: Exception thrown for HAVING on aggregate with nested cast #36056

Closed
matriv opened this issue Nov 29, 2018 · 4 comments
Closed

SQL: Exception thrown for HAVING on aggregate with nested cast #36056

matriv opened this issue Nov 29, 2018 · 4 comments
Labels
:Analytics/SQL SQL querying >bug Team:QL (Deprecated) Meta label for query languages team

Comments

@matriv
Copy link
Contributor

matriv commented Nov 29, 2018

SELECT gender
FROM test_emp
GROUP BY 1
HAVING (SUM({fn CONVERT(emp_no, SQL_BIGINT)}) > 1000);

throws:

java.sql.SQLException: Server encountered an error [Does not know how to convert argument Cast[LONG] for function Sum[]]. [SqlIllegalArgumentException[Does not know how to convert argument Cast[LONG] for function Sum[]]
	at org.elasticsearch.xpack.sql.planner.QueryTranslator.field(QueryTranslator.java:396)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator$Sums.toAgg(QueryTranslator.java:702)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator$Sums.toAgg(QueryTranslator.java:698)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator$SingleValueAggTranslator.asAgg(QueryTranslator.java:794)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator$AggTranslator.apply(QueryTranslator.java:784)
	at org.elasticsearch.xpack.sql.planner.QueryTranslator.toAgg(QueryTranslator.java:170)
	at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldAggregate.addAggFunction(QueryFolder.java:410)
	at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldAggregate.rule(QueryFolder.java:343)
	at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldAggregate.rule(QueryFolder.java:196)
	at org.elasticsearch.xpack.sql.tree.Node.lambda$transformUp$11(Node.java:188)
	at org.elasticsearch.xpack.sql.tree.Node.transformUp(Node.java:182)
	at org.elasticsearch.xpack.sql.tree.Node.lambda$transformUp$10(Node.java:180)
	at org.elasticsearch.xpack.sql.tree.Node.transformChildren(Node.java:201)
	at org.elasticsearch.xpack.sql.tree.Node.transformUp(Node.java:180)
	at org.elasticsearch.xpack.sql.tree.Node.lambda$transformUp$10(Node.java:180)
	at org.elasticsearch.xpack.sql.tree.Node.transformChildren(Node.java:201)
	at org.elasticsearch.xpack.sql.tree.Node.transformUp(Node.java:180)
	at org.elasticsearch.xpack.sql.tree.Node.transformUp(Node.java:188)
	at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldingRule.apply(QueryFolder.java:554)
	at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldingRule.apply(QueryFolder.java:550)
	at org.elasticsearch.xpack.sql.rule.RuleExecutor$Transformation.<init>(RuleExecutor.java:82)
	at org.elasticsearch.xpack.sql.rule.RuleExecutor.executeWithInfo(RuleExecutor.java:155)
	at org.elasticsearch.xpack.sql.rule.RuleExecutor.execute(RuleExecutor.java:130)
	at org.elasticsearch.xpack.sql.planner.QueryFolder.fold(QueryFolder.java:82)
	at org.elasticsearch.xpack.sql.planner.Planner.foldPlan(Planner.java:38)
	at org.elasticsearch.xpack.sql.planner.Planner.plan(Planner.java:28)
	at org.elasticsearch.xpack.sql.session.SqlSession.lambda$physicalPlan$4(SqlSession.java:153)
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:60)
	at org.elasticsearch.xpack.sql.session.SqlSession.lambda$optimizedPlan$3(SqlSession.java:149)
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:60)
	at org.elasticsearch.xpack.sql.session.SqlSession.lambda$preAnalyze$2(SqlSession.java:137)
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:60)
	at org.elasticsearch.xpack.sql.analysis.index.IndexResolver.lambda$resolveAsMergedMapping$3(IndexResolver.java:246)
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:60)
	at org.elasticsearch.action.support.ThreadedActionListener$1.doRun(ThreadedActionListener.java:97)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:759)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
@matriv matriv added >bug :Analytics/SQL SQL querying labels Nov 29, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@matriv
Copy link
Contributor Author

matriv commented Jan 7, 2019

We currently don't support aggregate functions on top of scalar functions

@matriv
Copy link
Contributor Author

matriv commented Mar 30, 2020

@elastic/es-ql

@rjernst rjernst added the Team:QL (Deprecated) Meta label for query languages team label May 4, 2020
@matriv
Copy link
Contributor Author

matriv commented Jun 15, 2021

Closing as this has been solved over time.

@matriv matriv closed this as completed Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying >bug Team:QL (Deprecated) Meta label for query languages team
Projects
None yet
Development

No branches or pull requests

3 participants