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: NullPointerException when GROUPing BY #41239

Closed
astefan opened this issue Apr 16, 2019 · 2 comments · Fixed by #42014
Closed

SQL: NullPointerException when GROUPing BY #41239

astefan opened this issue Apr 16, 2019 · 2 comments · Fixed by #42014

Comments

@astefan
Copy link
Contributor

astefan commented Apr 16, 2019

I think this one is from the same area of issues as #41200.

sql> SELECT ((CONVERT("calcs"."date2", SQL_DATE) + 5 * INTERVAL '1' DAY) + CONVERT(TRUNCATE((3 * (CONVERT(TRUNCATE(QUARTER("calcs"."date2"),0), SQL_BIGINT) - 1)),0), SQL_BIGINT) * INTERVAL '1' MONTH) AS result
> FROM "calcs"
> GROUP BY 1;
Server error [Server encountered an error [null]. [java.lang.NullPointerException
        at org.elasticsearch.xpack.sql.type.DataTypeConversion.commonType(DataTypeConversion.java:75)
        at org.elasticsearch.xpack.sql.expression.predicate.operator.arithmetic.ArithmeticOperation.dataType(ArithmeticOperation.java:40)
        at org.elasticsearch.xpack.sql.expression.Expressions.isNull(Expressions.java:107)
        at org.elasticsearch.xpack.sql.tree.Node.anyMatch(Node.java:118)
        at org.elasticsearch.xpack.sql.expression.Expressions.anyMatch(Expressions.java:61)
        at org.elasticsearch.xpack.sql.optimizer.Optimizer$FoldNull.rule(Optimizer.java:1171)
        at org.elasticsearch.xpack.sql.tree.Node.transformUp(Node.java:190)
        at org.elasticsearch.xpack.sql.plan.QueryPlan.lambda$transformExpressionsUp$4(QueryPlan.java:64)
        at org.elasticsearch.xpack.sql.plan.QueryPlan.doTransformExpression(QueryPlan.java:69)
        at org.elasticsearch.xpack.sql.plan.QueryPlan.doTransformExpression(QueryPlan.java:85)
        at org.elasticsearch.xpack.sql.plan.QueryPlan.lambda$transformExpressionsUp$5(QueryPlan.java:64)
        at org.elasticsearch.xpack.sql.tree.NodeInfo.lambda$transform$0(NodeInfo.java:55)
        at org.elasticsearch.xpack.sql.tree.NodeInfo$4.innerTransform(NodeInfo.java:146)
        at org.elasticsearch.xpack.sql.tree.NodeInfo.transform(NodeInfo.java:59)
        at org.elasticsearch.xpack.sql.tree.Node.transformNodeProps(Node.java:253)
        at org.elasticsearch.xpack.sql.tree.Node.lambda$transformPropertiesUp$13(Node.java:241)
        at org.elasticsearch.xpack.sql.tree.Node.transformUp(Node.java:190)
        at org.elasticsearch.xpack.sql.tree.Node.transformPropertiesUp(Node.java:241)
        at org.elasticsearch.xpack.sql.plan.QueryPlan.transformExpressionsUp(QueryPlan.java:64)
        at org.elasticsearch.xpack.sql.optimizer.Optimizer$OptimizerExpressionRule.apply(Optimizer.java:2006)
        at org.elasticsearch.xpack.sql.optimizer.Optimizer$OptimizerExpressionRule.apply(Optimizer.java:1995)
        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.optimizer.Optimizer.optimize(Optimizer.java:116)
        at org.elasticsearch.xpack.sql.session.SqlSession.lambda$optimizedPlan$3(SqlSession.java:152)
        at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:62)
        at org.elasticsearch.xpack.sql.session.SqlSession.lambda$preAnalyze$2(SqlSession.java:140)
        at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:62)
        at org.elasticsearch.xpack.sql.analysis.index.IndexResolver.lambda$resolveAsMergedMapping$3(IndexResolver.java:245)
        at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:62)
        at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:68)
        at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:64)
        at org.elasticsearch.action.fieldcaps.TransportFieldCapabilitiesAction.lambda$doExecute$0(TransportFieldCapabilitiesAction.java:84)

SELECT (({fn CONVERT("calcs"."datetime0", SQL_DATE)} + {fn CONVERT({fn TRUNCATE((-1 * ({fn DAYOFYEAR("calcs"."datetime0")} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' DAY) + {fn CONVERT({fn TRUNCATE((3 * ({fn CONVERT({fn TRUNCATE({fn QUARTER("calcs"."datetime0")},0)}, SQL_BIGINT)} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' MONTH) AS result FROM "calcs" GROUP BY 1

SELECT (({fn CONVERT("calcs"."date2", SQL_DATE)} + {fn CONVERT({fn TRUNCATE((-1 * ({fn DAYOFYEAR("calcs"."date2")} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' DAY) + {fn CONVERT({fn TRUNCATE((3 * ({fn CONVERT({fn TRUNCATE({fn QUARTER("calcs"."date2")},0)}, SQL_BIGINT)} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' MONTH) AS result FROM "calcs" GROUP BY 1

SELECT (({fn CONVERT("calcs"."date2", SQL_DATE)} + {fn CONVERT({fn TRUNCATE((-1 * ({fn DAYOFYEAR("calcs"."date2")} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' DAY) + {fn CONVERT({fn TRUNCATE((3 * ({fn CONVERT({fn TRUNCATE({fn QUARTER("calcs"."date2")},0)}, SQL_BIGINT)} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' MONTH) AS result FROM "calcs" GROUP BY 1

SELECT (({fn CONVERT("calcs"."datetime0", SQL_DATE)} + {fn CONVERT({fn TRUNCATE((-1 * ({fn DAYOFYEAR("calcs"."datetime0")} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' DAY) + {fn CONVERT({fn TRUNCATE((3 * ({fn CONVERT({fn TRUNCATE({fn QUARTER("calcs"."datetime0")},0)}, SQL_BIGINT)} - 1)),0)}, SQL_BIGINT)} * INTERVAL '1' MONTH) AS result FROM "calcs" GROUP BY 1

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@matriv matriv self-assigned this Apr 23, 2019
matriv added a commit to matriv/elasticsearch that referenced this issue May 9, 2019
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: elastic#41239
pull bot pushed a commit to rogues-gallery/elasticsearch that referenced this issue May 15, 2019
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: elastic#41239
Fixes: elastic#41200
matriv added a commit that referenced this issue May 15, 2019
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: #41239
Fixes: #41200
(cherry picked from commit 91039ba)
matriv added a commit that referenced this issue May 15, 2019
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: #41239
Fixes: #41200
(cherry picked from commit 91039ba)
matriv added a commit that referenced this issue May 15, 2019
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: #41239
Fixes: #41200
(cherry picked from commit 91039ba)
@matriv
Copy link
Contributor

matriv commented May 15, 2019

Backported to 7.x with 7473742
to 7.1 with 08d38da
to 6.8 with 3a20503

gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this issue May 27, 2019
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

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

Successfully merging a pull request may close this issue.

4 participants