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

[BUG] REGEXP filter failed due to IllegalStateException #2796

Open
bugmakerrrrrr opened this issue Jul 1, 2024 · 0 comments · May be fixed by #2797
Open

[BUG] REGEXP filter failed due to IllegalStateException #2796

bugmakerrrrrr opened this issue Jul 1, 2024 · 0 comments · May be fixed by #2797
Labels
bug Something isn't working

Comments

@bugmakerrrrrr
Copy link
Contributor

bugmakerrrrrr commented Jul 1, 2024

What is the bug?
When executing a SQL query with REGEXP filter, get the following exception:

{
  "error": {
    "reason": "Error occurred in OpenSearch engine: all shards failed",
    "details": "Shard[0]: java.lang.IllegalStateException: Expression has wrong result type instead of boolean: expression [regexp(field1, \"test.*\")], result [1]\n\nFor more details, please send request for Json format to see the raw response from OpenSearch engine.",
    "type": "SearchPhaseExecutionException"
  },
  "status": 500
}

How can one reproduce the bug?
Steps to reproduce the behavior:

  1. create an index with the following mappings:
{
  "mappings": {
    "properties": {
      "field1": {
        "type": "keyword"
      }
    }
  }
}
  1. write one doc using bulk API:
{"index": {"_id": 1}}
{"field1": "test search something"}
  1. run the following SQL query:
{
  "query": "SELECT field1 FROM test WHERE field1 REGEXP 'test.*'"
}

Do you have any additional context?
The root cause of this bug may be because what ExpressionFilterScript#evaluateExpression expects is a boolean value:

if (result.type() != ExprCoreType.BOOLEAN) {
throw new IllegalStateException(
String.format(
"Expression has wrong result type instead of boolean: "
+ "expression [%s], result [%s]",
expression, result));
}

but what OperatorUtils#matchesRegexp returns is an integer value:

public static ExprIntegerValue matchesRegexp(ExprValue text, ExprValue pattern) {
return new ExprIntegerValue(
Pattern.compile(pattern.stringValue()).matcher(text.stringValue()).matches() ? 1 : 0);
}

If we modify the return type of OperatorUtils#matchesRegexp, it will impact the return type of the REGEXP function, which could be a breaking change. To avoid this, we could consider converting the integer value to a boolean value in ExpressionFilterScript#evaluateExpression.

@bugmakerrrrrr bugmakerrrrrr added bug Something isn't working untriaged labels Jul 1, 2024
@bugmakerrrrrr bugmakerrrrrr linked a pull request Jul 1, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants