Skip to content

Conversation

@LantaoJin
Copy link
Member

@LantaoJin LantaoJin commented Jul 4, 2025

Description

PPL where clause throws syntax error for:

  • SOURCE=test | WHERE x
  • SOURCE=test | WHERE x OR y
  • SOURCE=test | WHERE true
  • SOURCE=test | WHERE (x < 1) = (y > 1)

Related Issues

Resolves #3273, #3272 and #3317

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • 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.

Signed-off-by: Lantao Jin <ltjin@amazon.com>
@LantaoJin LantaoJin added the bug Something isn't working label Jul 4, 2025
LantaoJin added 4 commits July 4, 2025 18:25
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
@LantaoJin
Copy link
Member Author

LantaoJin commented Jul 8, 2025

| (SEARCH)? logicalExpression fromClause # searchFilterFrom
: (SEARCH)? fromClause # searchFrom
| (SEARCH)? fromClause logicalExpression (logicalExpression)* # searchFromFilter
| SEARCH logicalExpression fromClause # searchFilterFrom
Copy link
Member Author

Choose a reason for hiding this comment

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

The SEARCH keyword changed to required since the query describe source=t could be ambiguous.
describe source=t should throw syntax error "describe source= <==== .."
But it could be matched to

(SEARCH)? logicalExpression fromClause

logicalExpression -> valueExpr -> fieldExpr -> describe
fromClause -> source=t

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why we supported the syntax of (SEARCH)? logicalExpression fromClause.

Copy link
Collaborator

Choose a reason for hiding this comment

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

search keywords is optional, this is valid query status=200 source=index

Copy link
Member Author

@LantaoJin LantaoJin Jul 18, 2025

Choose a reason for hiding this comment

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

updated, now the logicalExpression could be both before and after source clause which is similar to SPL search command.

searchCommand
  : (SEARCH)? (logicalExpression)* fromClause (logicalExpression)*     # searchFrom

| NOT logicalExpression # logicalNot
| left = logicalExpression (AND)? right = logicalExpression # logicalAnd
: NOT logicalExpression # logicalNot
| left = logicalExpression AND right = logicalExpression # logicalAnd
Copy link
Member Author

@LantaoJin LantaoJin Jul 8, 2025

Choose a reason for hiding this comment

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

The AND will be required in Where expression. But it is still optional in Search filter expression:

source=t a=1 b=c

source=t | where a=1 b=c

❌ (SPL cannot work either)

source=t | where a=1 and b=c

This limitation is because functionArgs could be ambiguous. For example:

source=t | eval f=position('substr' IN 'str')

can be parsed to an incorrect syntax tree:
Screenshot 2025-07-08 at 16 39 31

The correct syntax tree is

Screenshot 2025-07-08 at 16 41 02

qianheng-aws
qianheng-aws previously approved these changes Jul 8, 2025
Copy link
Collaborator

@qianheng-aws qianheng-aws left a comment

Choose a reason for hiding this comment

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

LGTM if above 2 limitation are acceptable.

Another concern is that we may not able to push down such filter condition of single field in DSL. But that issue could be addressed in a separate PR.

@LantaoJin
Copy link
Member Author

@penghuo this pr did some refactoring on antlr g4 file, could you take another look? There are multiple PPL new command PRs filed, to avoid conflicts, let's complete this refactoring ASAP.

@penghuo penghuo merged commit 988ab2e into opensearch-project:main Jul 21, 2025
23 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.x
# Create a new branch
git switch --create backport/backport-3849-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 988ab2ea13d533f761558c18c0844c4f206a18d6
# Push it to GitHub
git push --set-upstream origin backport/backport-3849-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-3849-to-2.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.19-dev failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.19-dev 2.19-dev
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.19-dev
# Create a new branch
git switch --create backport/backport-3849-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 988ab2ea13d533f761558c18c0844c4f206a18d6
# Push it to GitHub
git push --set-upstream origin backport/backport-3849-to-2.19-dev
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.19-dev

Then, create a pull request where the base branch is 2.19-dev and the compare/head branch is backport/backport-3849-to-2.19-dev.

LantaoJin added a commit to LantaoJin/search-plugins-sql that referenced this pull request Jul 22, 2025
* Support full expression in WHERE clauses

Signed-off-by: Lantao Jin <ltjin@amazon.com>

* add unit tests

Signed-off-by: Lantao Jin <ltjin@amazon.com>

* revert typo

Signed-off-by: Lantao Jin <ltjin@amazon.com>

* Fix IT

Signed-off-by: Lantao Jin <ltjin@amazon.com>

* Fix IT

Signed-off-by: Lantao Jin <ltjin@amazon.com>

* Address comment

Signed-off-by: Lantao Jin <ltjin@amazon.com>

---------

Signed-off-by: Lantao Jin <ltjin@amazon.com>
(cherry picked from commit 988ab2e)
penghuo pushed a commit that referenced this pull request Jul 22, 2025
* Support full expression in WHERE clauses



* add unit tests



* revert typo



* Fix IT



* Fix IT



* Address comment



---------


(cherry picked from commit 988ab2e)

Signed-off-by: Lantao Jin <ltjin@amazon.com>
@vamsimanohar vamsimanohar added the backport-manually Filed a PR to backport manually. label Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.x backport 2.19-dev backport-failed backport-manually Filed a PR to backport manually. bug Something isn't working

Projects

None yet

4 participants