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 conditional more complex CASE WHEN fails #46316

Closed
astefan opened this issue Sep 4, 2019 · 1 comment · Fixed by #43072
Closed

SQL: GROUPing BY conditional more complex CASE WHEN fails #46316

astefan opened this issue Sep 4, 2019 · 1 comment · Fixed by #43072
Labels

Comments

@astefan
Copy link
Contributor

astefan commented Sep 4, 2019

The following query fails SELECT (CASE WHEN bool0 = TRUE THEN '1' WHEN NOT bool0 = TRUE THEN '0' ELSE CAST(NULL AS STRING) END) AS x FROM calcs GROUP BY x with

{
    "error": {
        "root_cause": [
            {
                "type": "folding_exception",
                "reason": "line 1:9: Cannot find grouping for 'CASE WHEN bool0 = TRUE THEN '1' WHEN NOT bool0 = TRUE THEN '0' ELSE CAST(NULL AS STRING) END'"
            }
        ],
        "type": "folding_exception",
        "reason": "line 1:9: Cannot find grouping for 'CASE WHEN bool0 = TRUE THEN '1' WHEN NOT bool0 = TRUE THEN '0' ELSE CAST(NULL AS STRING) END'"
    },
    "status": 400
}

While a simpler one - SELECT (CASE WHEN bool0 = TRUE THEN '1' ELSE '0' END) AS x FROM calcs GROUP BY x works as expected.

@astefan astefan added >bug :Analytics/SQL SQL querying labels Sep 4, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

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)
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.

2 participants