opensearch-project / opensearch-project/sql

[BUG] Inconsistent behavior when query falls back from v2 to v1 SQL engine with unsupported functions and index naming

Open
#3,541 1 comment 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?
There's an inconsistency in query handling when the fallback mechanism from v2 to v1 SQL engine is triggered. This creates a confusing user experience where queries might be rejected differently based on multiple unsupported features across both engines.

  1. V2 engine has stricter index identifier naming restrictions (e.g., select * from a.1 is not allowed)
  2. V2 engine supports additional functions (e.g., from_unixtime)
  3. When V2 engine cannot handle a query, it falls back to V1 engine
  4. This creates a scenario where:
    • select * from a.1 works in V1 (after V2 rejection)
    • select from_unixtime(t) from a.1 falls back to V1 but fails because V1 doesn't support from_unixtime

How can one reproduce the bug?

PUT /a.b
{
  "mappings": {
    "properties": {
      "test_time": {
        "type": "long"
      }
    }
  }
}

PUT /a.b/_doc/1
{"test_time": 17424371270}

# Returns formatted date
POST /_plugins/_sql
{
  "query": "select from_unixtime(test_time) from a.b"
}


PUT /a.1
{
  "mappings": {
    "properties": {
      "test_time": {
        "type": "long"
      }
    }
  }
}

PUT /a.1/_doc/1
{"test_time": 17424371270}

# Error: The following method is not supported in Schema: from_unixtime
POST /_plugins/_sql
{
  "query": "select from_unixtime(test_time) from a.1"
}

What is the expected behavior?
A clear and concise description of what you expected to happen.

What is your host/environment?

  • OS: [e.g. iOS]
  • Version [e.g. 22]
  • Plugins

Do you have any screenshots?
If applicable, add screenshots to help explain your problem.

Do you have any additional context?
Add any other context about the problem.

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

No source files or tests are named. Reproduce the two POST /_plugins/_sql cases, then trace how unsupported functions and index identifiers are handled during v2-to-v1 fallback; confirm the intended behavior with maintainers before changing code.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
backend-api-design, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.