Skip to content

Conversation

RyanL1997
Copy link
Collaborator

@RyanL1997 RyanL1997 commented Sep 22, 2025

Signed-off-by: Jialiang Liang [email protected]

Description

Better error handling for known limitation of sql JOIN

example:

❯   curl -X POST "localhost:9200/_plugins/_sql" -H 'Content-Type: application/json' -d'
  {
    "query": "SELECT SUM(a.balance) FROM accounts a JOIN accounts b ON a.account_number = b.account_number"
  }'

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "JOIN queries do not support aggregations on the joined result. For more information, see https://docs.opensearch.org/3.2/search-plugins/sql/limitation/#join-does-not-support-aggregations-on-the-joined-result",
    "type": "SqlParseException"
  },
  "status": 400
}% 

Related Issues

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@RyanL1997 RyanL1997 added enhancement New feature or request SQL labels Sep 22, 2025
@RyanL1997 RyanL1997 changed the title [Enhancement] Better error handling for known limitation of sql JOIN [Enhancement] Add error handling for known limitation of sql JOIN Sep 22, 2025
@RyanL1997 RyanL1997 marked this pull request as ready for review September 22, 2025 15:23
Copy link
Collaborator

@Swiddis Swiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions -- I think this could be designed better if changing JoinSelect doesn't cause cascading breakage, otherwise this approach is fine.

Swiddis
Swiddis previously approved these changes Sep 25, 2025
Swiddis
Swiddis previously approved these changes Sep 25, 2025
Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you remove your test accidentally? I don't see any UT or IT now.

@RyanL1997
Copy link
Collaborator Author

RyanL1997 commented Sep 30, 2025

Added the new tests in AntlrSqlParseTreeVisitorTest.java cc @dai-chen

Comment on lines 295 to 305
if (ctx.tableSource().size() > 1) {
return true;
}

for (int i = 0; i < ctx.tableSource().size(); i++) {
Boolean hasJoinInTableSource = visit(ctx.tableSource(i));
if (hasJoinInTableSource != null && hasJoinInTableSource) {
return true;
}
}
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this trying to check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transferring some offline communication with @dai-chen here: we should limit the scope of this for only check the explicit join only - so removed this section.

Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
Signed-off-by: Jialiang Liang <[email protected]>
@RyanL1997 RyanL1997 force-pushed the join-limitation-error-handling branch from 9240c00 to 1634610 Compare September 30, 2025 23:30
@RyanL1997
Copy link
Collaborator Author

#4378 is failing at the same

@Swiddis
Copy link
Collaborator

Swiddis commented Oct 1, 2025

Failures exist in main and are only with recently added tests, think this is ok to merge

@Swiddis Swiddis merged commit 649ce41 into opensearch-project:main Oct 1, 2025
48 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SQL v3.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Better error handling for JOIN query limitation
3 participants