opensearch-project / opensearch-project/sql

[BUG] NPE with json respone formatter on "SELECT 1"

Open
#3,188 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What is the bug?
NPE with json respone formatter on "SELECT 1"

It works fine with default format

curl -X POST "localhost:9200/_plugins/_sql" -H "Content-Type: application/json" -d'
{
        "query": "select 1"
}'
{
  "schema": [
    {
      "name": "1",
      "type": "integer"
    }
  ],
  "datarows": [
    [
      1
    ]
  ],
  "total": 1,
  "size": 1,
  "status": 200
}%    

How can one reproduce the bug?


 curl -X POST "localhost:9200/_plugins/_sql?format=json&pretty=true" -H "Content-Type: application/json" -d'
{
	"query": "select 1"
}'

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Cannot invoke \"com.alibaba.druid.sql.ast.statement.SQLTableSource.getAlias()\" because the return value of \"com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getFrom()\" is null",
    "type": "NullPointerException"
  },
  "status": 400
}

What is the expected behavior?
Return valid json response

Additional info

Stacktrace

java.lang.NullPointerException: Cannot invoke "com.alibaba.druid.sql.ast.statement.SQLTableSource.getAlias()" because the return value of "com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getFrom()" is null
	at org.opensearch.sql.legacy.parser.SqlParser.parseSelect(SqlParser.java:81) ~[legacy-3.0.0.0-SNAPSHOT.jar:?]
	at org.opensearch.sql.legacy.parser.SqlParser.parseSelect(SqlParser.java:68) ~[legacy-3.0.0.0-SNAPSHOT.jar:?]
	at org.opensearch.sql.legacy.query.OpenSearchActionFactory.create(OpenSearchActionFactory.java:120) ~[legacy-3.0.0.0-SNAPSHOT.jar:?]
	at org.opensearch.sql.legacy.plugin.SearchDao.explain(SearchDao.java:48) ~[legacy-3.0.0.0-SNAPSHOT.jar:?]
	at org.opensearch.sql.legacy.plugin.RestSqlAction.explainRequest(RestSqlAction.java:243) [legacy-3.0.0.0-SNAPSHOT.jar:?]
	at org.opensearch.sql.legacy.plugin.RestSqlAction.lambda$prepareRequest$1(RestSqlAction.java:172) [legacy-3.0.0.0-SNAPSHOT.jar:?]
	at org.opensearch.sql.legacy.plugin.RestSQLQueryAction.lambda$prepareRequest$0(RestSQLQueryAction.java:92) [legacy-3.0.0.0-SNAPSHOT.jar:?]

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 at org.opensearch.sql.legacy.parser.SqlParser.parseSelect in SqlParser.java:81, using the reproduced POST request with format=json and the SELECT 1 query. Trace how a query without a FROM source is handled and verify the endpoint returns valid JSON without a NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.