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: grouping by an INTERVAL formula throws error #37044

Closed
astefan opened this issue Dec 31, 2018 · 2 comments · Fixed by #43072
Closed

SQL: grouping by an INTERVAL formula throws error #37044

astefan opened this issue Dec 31, 2018 · 2 comments · Fixed by #43072
Labels

Comments

@astefan
Copy link
Contributor

astefan commented Dec 31, 2018

date2 is a date field in ES. If I remove 1 * and make the formula to be an interval added to a date, then I get the exception from #37042. So, the multiplication seems to be the issue here...

sql> SELECT date2 + 1 * INTERVAL '1' DAY FROM calcs GROUP BY 1;                                                                                                                          
Server error [Server sent bad type [folding_exception]. Original type was [line 1:14: Cannot find grouping for '(date2) + 1 * INTERVAL '1' DAY']. [FoldingException[line 1:14: Cannot fin
d grouping for '(date2) + 1 * INTERVAL '1' DAY']                                                                                                                                         
        at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldAggregate.rule(QueryFolder.java:312)                                                                                      
        at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldAggregate.rule(QueryFolder.java:197)                                                                                      
        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.transformUp(Node.java:188)                                                                                                              
        at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldingRule.apply(QueryFolder.java:560)                                                                                       
        at org.elasticsearch.xpack.sql.planner.QueryFolder$FoldingRule.apply(QueryFolder.java:556)                                                                                       
        at org.elasticsearch.xpack.sql.rule.RuleExecutor$Transformation.<init>(RuleExecutor.java:82)                                                                                     
        at org.elasticsearch.xpack.sql.rule.RuleExecutor.executeWithInfo(RuleExecutor.java:158)                                                                                          
        at org.elasticsearch.xpack.sql.rule.RuleExecutor.execute(RuleExecutor.java:130)                                                                                                  
        at org.elasticsearch.xpack.sql.planner.QueryFolder.fold(QueryFolder.java:83)                                                                                                     
        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.TransportAction$1.onResponse(TransportAction.java:64)                                                                                        
        at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:60)                                                                                        
        at org.elasticsearch.action.fieldcaps.TransportFieldCapabilitiesAction.lambda$doExecute$1(TransportFieldCapabilitiesAction.java:84)                                              
        at org.elasticsearch.action.fieldcaps.TransportFieldCapabilitiesAction$1.onResponse(TransportFieldCapabilitiesAction.java:97)                                                    
        at org.elasticsearch.action.fieldcaps.TransportFieldCapabilitiesAction$1.onResponse(TransportFieldCapabilitiesAction.java:93)                                                    
        at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:64)                                                                                        
        at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:60)                                                                                        
        at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$AsyncSingleAction$2.handleResponse(TransportSingleShardAction.java:271)                              
        at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$AsyncSingleAction$2.handleResponse(TransportSingleShardAction.java:255)                              
        at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleResponse(TransportService.java:1094)                                                         
        at org.elasticsearch.transport.TransportService$DirectResponseChannel.processResponse(TransportService.java:1175)                                                                
        at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1155)                                                                   
        at org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:54)                                                                                   
        at org.elasticsearch.action.support.HandledTransportAction$ChannelActionListener.onResponse(HandledTransportAction.java:93)                                                      
        at org.elasticsearch.action.support.HandledTransportAction$ChannelActionListener.onResponse(HandledTransportAction.java:77)                                                      
        at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$1.doRun(TransportSingleShardAction.java:117)                                                         
        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)                                                                                                                               
]]                                                                                                                                                                                       
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@matriv
Copy link
Contributor

matriv commented Jul 29, 2019

Also SELECT birth_date + 5 * INTERVAL '10' DAY FROM test_emp GROUP BY birth_date + 5 * INTERVAL '10' DAY ORDER BY birth_date + 5 * INTERVAL '10' DAY DESC LIMIT 10;
throws:

java.sql.SQLDataException: Found 1 problem(s)
    line 1:110: Cannot use non-grouped column [birth_date], expected [birth_date + 5 * INTERVAL '10' DAY]

matriv pushed a commit that referenced this issue Oct 31, 2019
Fix an issue that arises from the use of ExpressionIds as keys in a lookup map
that helps the QueryTranslator to identify the grouping columns. The issue is
that the same expression in different parts of the query (SELECT clause and GROUP BY clause)
ends up with different ExpressionIds so the lookup fails. So, instead of ExpressionIds
use the hashCode() of NamedExpression.

Fixes: #41159
Fixes: #40001
Fixes: #40240
Fixes: #33361
Fixes: #46316
Fixes: #36074
Fixes: #34543
Fixes: #37044

Fixes: #42041
matriv pushed a commit that referenced this issue Oct 31, 2019
Fix an issue that arises from the use of ExpressionIds as keys in a lookup map
that helps the QueryTranslator to identify the grouping columns. The issue is
that the same expression in different parts of the query (SELECT clause and GROUP BY clause)
ends up with different ExpressionIds so the lookup fails. So, instead of ExpressionIds
use the hashCode() of NamedExpression.

Fixes: #41159
Fixes: #40001
Fixes: #40240
Fixes: #33361
Fixes: #46316
Fixes: #36074
Fixes: #34543
Fixes: #37044

Fixes: #42041
(cherry picked from commit 3c38ea5)
matriv pushed a commit that referenced this issue Oct 31, 2019
Fix an issue that arises from the use of ExpressionIds as keys in a lookup map
that helps the QueryTranslator to identify the grouping columns. The issue is
that the same expression in different parts of the query (SELECT clause and GROUP BY clause)
ends up with different ExpressionIds so the lookup fails. So, instead of ExpressionIds
use the hashCode() of NamedExpression.

Fixes: #41159
Fixes: #40001
Fixes: #40240
Fixes: #33361
Fixes: #46316
Fixes: #36074
Fixes: #34543
Fixes: #37044

Fixes: #42041
(cherry picked from commit 3c38ea5)
matriv pushed a commit that referenced this issue Oct 31, 2019
Fix an issue that arises from the use of ExpressionIds as keys in a lookup map
that helps the QueryTranslator to identify the grouping columns. The issue is
that the same expression in different parts of the query (SELECT clause and GROUP BY clause)
ends up with different ExpressionIds so the lookup fails. So, instead of ExpressionIds
use the hashCode() of NamedExpression.

Fixes: #41159
Fixes: #40001
Fixes: #40240
Fixes: #33361
Fixes: #46316
Fixes: #36074
Fixes: #34543
Fixes: #37044

Fixes: #42041
(cherry picked from commit 3c38ea5)
matriv pushed a commit that referenced this issue Oct 31, 2019
Fix an issue that arises from the use of ExpressionIds as keys in a lookup map
that helps the QueryTranslator to identify the grouping columns. The issue is
that the same expression in different parts of the query (SELECT clause and GROUP BY clause)
ends up with different ExpressionIds so the lookup fails. So, instead of ExpressionIds
use the hashCode() of NamedExpression.

Fixes: #41159
Fixes: #40001
Fixes: #40240
Fixes: #33361
Fixes: #46316
Fixes: #36074
Fixes: #34543
Fixes: #37044

Fixes: #42041
(cherry picked from commit 3c38ea5)
debadair pushed a commit to debadair/elasticsearch that referenced this issue Nov 13, 2019
…#43072)

Fix an issue that arises from the use of ExpressionIds as keys in a lookup map
that helps the QueryTranslator to identify the grouping columns. The issue is
that the same expression in different parts of the query (SELECT clause and GROUP BY clause)
ends up with different ExpressionIds so the lookup fails. So, instead of ExpressionIds
use the hashCode() of NamedExpression.

Fixes: elastic#41159
Fixes: elastic#40001
Fixes: elastic#40240
Fixes: elastic#33361
Fixes: elastic#46316
Fixes: elastic#36074
Fixes: elastic#34543
Fixes: elastic#37044

Fixes: elastic#42041
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants