opensearch-project / sql

Query your data using familiar SQL or intuitive Piped Processing Language (PPL)
https://opensearch.org/docs/latest/search-plugins/sql/index/
Apache License 2.0
121 stars 140 forks source link

[BUG] Join query doesn't support multi_match function #3135

Open dai-chen opened 3 weeks ago

dai-chen commented 3 weeks ago

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