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: error when an aggregate function is used in combination with two full-text search conditions #47365

Closed
astefan opened this issue Oct 1, 2019 · 2 comments · Fixed by #47444
Assignees
Labels

Comments

@astefan
Copy link
Contributor

astefan commented Oct 1, 2019

SELECT AVG(salary) FROM test_emp WHERE QUERY('first_name:x') OR QUERY('first_name:y')

and same goes for

SELECT AVG(salary) FROM test_emp WHERE MATCH(first_name, 'x') OR MATCH(first_name, 'y')

The generated error and stacktrace:

{
    "error": {
        "root_cause": [
            {
                "type": "sql_illegal_argument_exception",
                "reason": "Cannot evaluate script for expression MatchQueryPredicate[first_name{f}#532,x,]"
            }
        ],
        "type": "sql_illegal_argument_exception",
        "reason": "Cannot evaluate script for expression MatchQueryPredicate[first_name{f}#532,x,]"
    },
    "status": 500
}
Server error [Server encountered an error [Cannot evaluate script for expression MatchQueryPredicate[first_name{f}#557,x,]]. [org.elasticsearch.xpack.sql.SqlIllegalArgumentException: Cannot evaluate script for expression MatchQueryPredicate[first_name{f}#557,x,]
        at org.elasticsearch.xpack.sql.expression.gen.script.ScriptWeaver.asScript(ScriptWeaver.java:54)
        at org.elasticsearch.xpack.sql.expression.function.scalar.BinaryScalarFunction.asScript(BinaryScalarFunction.java:52)
        at org.elasticsearch.xpack.sql.expression.function.scalar.ScalarFunction.toAttribute(ScalarFunction.java:38)
        at org.elasticsearch.xpack.sql.expression.function.scalar.ScalarFunction.toAttribute(ScalarFunction.java:23)
        at org.elasticsearch.xpack.sql.expression.Expressions.attribute(Expressions.java:124)
        at org.elasticsearch.xpack.sql.optimizer.Optimizer$ReplaceAggsWithStats.lambda$updateAggAttributes$3(Optimizer.java:496)
        at org.elasticsearch.xpack.sql.tree.Node.anyMatch(Node.java:118)
        at org.elasticsearch.xpack.sql.optimizer.Optimizer$ReplaceAggsWithStats.lambda$updateAggAttributes$4(Optimizer.java:495)
        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.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$3.innerTransform(NodeInfo.java:116)
        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.lambda$transformUp$10(Node.java:188)
        at org.elasticsearch.xpack.sql.tree.Node.transformChildren(Node.java:209)
        at org.elasticsearch.xpack.sql.tree.Node.transformUp(Node.java:188)
        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$ReplaceAggsWithStats.updateAggAttributes(Optimizer.java:466)
        at org.elasticsearch.xpack.sql.optimizer.Optimizer$ReplaceAggsWithStats.apply(Optimizer.java:404)
        at org.elasticsearch.xpack.sql.optimizer.Optimizer$ReplaceAggsWithStats.apply(Optimizer.java:351)
        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:121)
        at org.elasticsearch.xpack.sql.session.SqlSession.lambda$optimizedPlan$3(SqlSession.java:156)
@astefan astefan added >bug :Analytics/SQL SQL querying labels Oct 1, 2019
@astefan astefan self-assigned this Oct 1, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@astefan
Copy link
Contributor Author

astefan commented Oct 4, 2019

master (8.0.0): bb14ba8
7.x (7.5.0): a46f312
7.4 (7.4.1): 111e4e1

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