opensearch-project / opensearch-project/sql

[BUG] Join query doesn't support multi_match function

Open
#3,135 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug SQL
Dominant language
Java
Stars
176
Forks
229
Avg merge
2d 21h
Merged PRs (30d)
43

Description

What is the bug?

The JOIN query does not support the multi_match function in the WHERE clause due to table alias missing. This limitation arises due to two primary reasons:

  1. A validation step requires that the left side of the expression use a table alias.
  2. The optimizer relies on the alias to determine which table should receive the filtering condition.

How can one reproduce the bug?

  @Test
  public void multiMatchQuerySingleField() throws IOException {
    assertThat(
        query(
            "SELECT a.firstname",
            FROM_ACCOUNTS + " AS a INNER JOIN " + TEST_INDEX_ACCOUNT + " AS b ON a.firstname = b.firstname",
            "WHERE MULTI_MATCH('query'='Ayers', 'fields'='firstname')"),
        hits(hasValueForFields("Ayers", "firstname")));
  }

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Field ['query' = 'Ayers'] with condition [AND 'query' = 'Ayers' EQ
MULTI_MATCH(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr@101a1ce6,
com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr@b5dbbdc4)] does not contain an alias",
    "type": "SqlParseException"
  },
  "status": 400
}

What is the expected behavior?

The JOIN query should support the multi_match function in the WHERE clause without problem.

Do you have any additional context?

N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search for the multiMatchQuerySingleField test shown in the issue and run it to reproduce the alias-related SqlParseException. Trace the JOIN WHERE-clause validation and optimization paths involved in that test; done means the query succeeds and returns the expected Ayers firstname hit.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.