opensearch-project / opensearch-project/sql
[BUG] Runtime exception thrown if duplicate name in SELECT items
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 176
- Forks
- 229
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 43
Description
What is the bug?
Currently duplicate name in SELECT statement is not supported and runtime exception is thrown at execution time.
How can one reproduce the bug?
Steps to reproduce the behavior:
- Go to Query Workbench or DevTools
- Find any index
- Run query with duplicate name in SELECT
- See error as below
curl -XPOST "localhost:9200/_plugins/_sql" -H 'Content-Type: application/json' -d '
{
"query": "SELECT region, region FROM testmv "
}
'
{
"error": {
"type": "IllegalArgumentException",
"reason": "There was internal problem at backend",
"details": "Multiple entries with same key: region=\"CA\" and region=\"CA\""
},
"status": 503
}
What is the expected behavior?
Either semantic check performed and semantic exception thrown with clear error message
Or support this case as other database if needed.
What is your host/environment?
- OpenSearch 2.2
- Plugins: SQL
Do you have any screenshots?
N/A
Do you have any additional context?
Tested MySQL and SQLServer. Both has same behavior as below:
CREATE TABLE Test(name VARCHAR(100));
INSERT INTO Test(name) VALUES('hello');
SELECT name, name FROM Test;
name | name
-- | --
hello | hello
Exception stacktrace:
Server side error during query execution
java.lang.IllegalArgumentException: Multiple entries with same key: region="CA" and region="CA"
at com.google.common.collect.ImmutableMap.conflictException(ImmutableMap.java:376) ~[guava-31.0.1-jre.jar:?]
at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:370) ~[guava-31.0.1-jre.jar:?]
at com.google.common.collect.RegularImmutableMap.checkNoConflictInKeyBucket(RegularImmutableMap.java:153) ~[guava-31.0.1-jre.jar:?]
at com.google.common.collect.RegularImmutableMap.fromEntryArray(RegularImmutableMap.java:115) ~[guava-31.0.1-jre.jar:?]
at com.google.common.collect.ImmutableMap$Builder.buildOrThrow(ImmutableMap.java:574) ~[guava-31.0.1-jre.jar:?]
at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:538) ~[guava-31.0.1-jre.jar:?]
at org.opensearch.sql.planner.physical.ProjectOperator.next(ProjectOperator.java:82) ~[core-2.2.0.0-SNAPSHOT.jar:?]
at org.opensearch.sql.planner.physical.ProjectOperator.next(ProjectOperator.java:28) ~[core-2.2.0.0-SNAPSHOT.jar:?]
at org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine.lambda$execute$0(OpenSearchExecutionEngine.java:40) [opensearch-2.2.0.0-SNAPSHOT.jar:?]
at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.lambda$withCurrentContext$5(OpenSearchNodeClient.java:197) [opensearch-2.2.0.0-SNAPSHOT.jar:?]
at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:747) [opensearch-2.2.0.jar:2.2.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the SELECT region, region FROM testmv query, then inspect org.opensearch.sql.planner.physical.ProjectOperator.java at line 82, where the stack trace shows the failure. Check how duplicate SELECT names are handled and verify that execution no longer returns the internal 503 exception, either by producing the expected duplicate columns or a clear semantic error.
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
- 35/100