opensearch-project / opensearch-project/sql

[FEATURE] Join query doesn't support index alias

Open
#2,542 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is your feature request related to a problem?

When using index alias instead of index name in JOIN query, NPE is thrown from SQL plugin.

What solution would you like?

JOIN query (or any SQL query) can handle index alias without issue.

Do you have any additional context?

Error stacktrace:

[2024-03-06T22:33:27,579][ERROR][o.o.s.l.p.RestSqlAction  ]  Client side error during query execution
java.lang.NullPointerException: Cannot invoke "org.opensearch.sql.legacy.esdomain.mapping.FieldMappings.has(String)" because "fieldMappings" is null
    at org.opensearch.sql.legacy.rewriter.matchtoterm.TermFieldRewriter.visit(TermFieldRewriter.java:129)
    at com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr.accept0(SQLIdentifierExpr.java:65)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.accept(SQLObjectImpl.java:40)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.acceptChild(SQLObjectImpl.java:62)
    at com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr.accept0(SQLBinaryOpExpr.java:99)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.accept(SQLObjectImpl.java:40)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.acceptChild(SQLObjectImpl.java:62)
    at com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.accept0(MySqlSelectQueryBlock.java:258)
    at com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.accept0(MySqlSelectQueryBlock.java:246)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.accept(SQLObjectImpl.java:40)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.acceptChild(SQLObjectImpl.java:62)
    at com.alibaba.druid.sql.ast.statement.SQLSelect.accept0(SQLSelect.java:85)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.accept(SQLObjectImpl.java:40)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.acceptChild(SQLObjectImpl.java:62)
    at com.alibaba.druid.sql.ast.expr.SQLQueryExpr.accept0(SQLQueryExpr.java:55)
    at com.alibaba.druid.sql.ast.SQLObjectImpl.accept(SQLObjectImpl.java:40)
    at org.opensearch.sql.legacy.query.OpenSearchActionFactory.create(OpenSearchActionFactory.java:110)
    at org.opensearch.sql.legacy.plugin.SearchDao.explain(SearchDao.java:52)
    at org.opensearch.sql.legacy.plugin.RestSqlAction.explainRequest(RestSqlAction.java:208)
    at org.opensearch.sql.legacy.plugin.RestSqlAction.lambda$prepareRequest$1(RestSqlAction.java:160)
    at org.opensearch.sql.legacy.plugin.RestSQLQueryAction$1.onFailure(RestSQLQueryAction.java:130)
    at org.opensearch.sql.sql.SQLService.explain(SQLService.java:60)
    at org.opensearch.sql.legacy.plugin.RestSQLQueryAction.lambda$prepareRequest$2(RestSQLQueryAction.java:98)
    ...

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

Start in org.opensearch.sql.legacy.rewriter.matchtoterm.TermFieldRewriter.visit, where the stack trace reports the null FieldMappings access, and trace how JOIN index names or aliases are resolved. Reproduce the reported JOIN using an index alias, then verify that the query executes without the NullPointerException for aliases as well as index names.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Feature
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.