Skip to content

Conversation

@songkant-aws
Copy link
Contributor

@songkant-aws songkant-aws commented Jul 1, 2025

Description

Support relevance query functions pushdown implementation in Calcite

Related Issues

Resolves #3462

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: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
String query =
"source = %s| WHERE match_phrase_prefix(Title, 'in to', analyzer=english,"
+ " zero_terms_query='ALL') | sort -Title | head 1 | fields Title";
+ " zero_terms_query='ALL') | head 1 | fields Title";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modify this IT query because sort pushdown is not merged to Calcite yet.

Copy link
Member

Choose a reason for hiding this comment

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

it merged, can you rebase the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebased the code but the Sort pushdown has different behavior of handling missing_: first/last than V2. Calcite IT still has different assertion. So I leave my change here.

Waiting for @yuancu new PR merging.

@LantaoJin LantaoJin added enhancement New feature or request calcite calcite migration releated pushdown pushdown related issues labels Jul 1, 2025
Signed-off-by: Songkan Tang <songkant@amazon.com>
if (node.getFuncName().equalsIgnoreCase("reduce")) { // analyze again with calculate type
lambdaContext =

if (SINGLE_FIELD_RELEVANCE_FUNCTION_SET.contains(node.getFuncName())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't get why not replying on visitRelevanceFieldList to resolve all fields and then we don't need specific handing for relevance functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, we can support UnresolvedArgument as alias(literal). Making such changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed UnresolvedArgument change. The amount of changes is less than I expected.

@penghuo
Copy link
Collaborator

penghuo commented Jul 1, 2025

I don't think we should support relevance query functions directly. The concern is that it would allow users to use them anywhere a predicate expression is valid. However, the query engine does not support relevance evaluation, so it must always push down these functions to the DSL. If pushdown fails, the query will throw an exception.

Instead, I propose supporting relevance-based queries only within the search command.

Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
@songkant-aws
Copy link
Contributor Author

@penghuo As discussed, since V2 relevance function cannot be removed quickly. We can mark these functions deprecated once we introduce new syntax of relevance query in search command directly.

@qianheng-aws qianheng-aws merged commit 74b4de0 into opensearch-project:main Jul 2, 2025
23 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.19-dev 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.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-3834-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 74b4de067cefc821055076bd108249cef777c3f9
# Push it to GitHub
git push --set-upstream origin backport/backport-3834-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-3834-to-2.19-dev.

@LantaoJin
Copy link
Member

@songkant-aws please manually backport it to 2.19-dev

songkant-aws added a commit to songkant-aws/sql that referenced this pull request Jul 4, 2025
…pensearch-project#3834)

* Support relevance query functions pushdown implementation

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Remove unused change

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Remove ITs from NoPushDownIT list

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Add more UTs and javadocs

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Support analyzing UnresolvedArgument RexNode and refactor code

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Fix spotless check

Signed-off-by: Songkan Tang <songkant@amazon.com>

---------

Signed-off-by: Songkan Tang <songkant@amazon.com>
qianheng-aws pushed a commit that referenced this pull request Jul 7, 2025
…entation in Calcite (#3834) (#3848)

* Support relevance query functions pushdown implementation in Calcite (#3834)

* Support relevance query functions pushdown implementation

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Remove unused change

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Remove ITs from NoPushDownIT list

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Add more UTs and javadocs

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Support analyzing UnresolvedArgument RexNode and refactor code

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Fix spotless check

Signed-off-by: Songkan Tang <songkant@amazon.com>

---------

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Fix compiling issue

Signed-off-by: Songkan Tang <songkant@amazon.com>

* Fix java syntax

Signed-off-by: Songkan Tang <songkant@amazon.com>

---------

Signed-off-by: Songkan Tang <songkant@amazon.com>
@LantaoJin LantaoJin added the backport-manually Filed a PR to backport manually. label Jul 22, 2025
@penghuo penghuo mentioned this pull request Jul 30, 2025
7 tasks
@songkant-aws songkant-aws deleted the relevance-query branch August 1, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.19-dev backport-failed backport-manually Filed a PR to backport manually. calcite calcite migration releated enhancement New feature or request pushdown pushdown related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Discussion] Search relevant functions with Calcite

5 participants