Skip to content

SQL: SIGNUM cannot be used in script context #35654

@imotov

Description

@imotov

Due to the name mismatch between

@Override
protected String mathFunction() {
return "signum";
}

and
public static Double sign(Number value) {
return MathOperation.SIGN.apply(value);
}

The SIGN/SIGNUM function fail when used in GROUP BY or ORDER BY.

To reproduce:

SELECT SIGNUM(salary - 50000) sig FROM test_emp GROUP BY sig 
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "InternalSqlScriptUtils.signum(InternalSqlScript ...",
          "                      ^---- HERE"
        ],
        "script": "InternalSqlScriptUtils.signum(InternalSqlScriptUtils.sub(InternalSqlScriptUtils.docValue(doc,params.v0),params.v1))",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "test_emp",
        "node": "uzOJf9yTSGGYtJILcwpG5Q",
        "reason": {
          "type": "script_exception",
          "reason": "compile error",
          "script_stack": [
            "InternalSqlScriptUtils.signum(InternalSqlScript ...",
            "                      ^---- HERE"
          ],
          "script": "InternalSqlScriptUtils.signum(InternalSqlScriptUtils.sub(InternalSqlScriptUtils.docValue(doc,params.v0),params.v1))",
          "lang": "painless",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "method [org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalSqlScriptUtils, signum/1] not found"
          }
        }
      }
    ]
  },
  "status": 400
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions