Skip to content

Support function coalesce with Calcite#3628

Merged
LantaoJin merged 3 commits intoopensearch-project:mainfrom
yuancu:coalesce-udf
May 21, 2025
Merged

Support function coalesce with Calcite#3628
LantaoJin merged 3 commits intoopensearch-project:mainfrom
yuancu:coalesce-udf

Conversation

@yuancu
Copy link
Copy Markdown
Collaborator

@yuancu yuancu commented May 16, 2025

Description

Support functions coalesce with Calcite, which returns the first non-null value in its parameter list.

Issues Resolved

Resolves #3610

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

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: Yuanchun Shen <yuanchu@amazon.com>
@yuancu yuancu changed the title Support function coalesce with Calcite Support function coalesce with Calcite May 16, 2025
@LantaoJin LantaoJin added the calcite calcite migration releated label May 19, 2025
JSONObject actual =
executeQuery(
String.format(
"source=%s | where age = 10 | eval new_country = coalesce(name, state, country) | fields name, state, country, new_country",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you add a case if the values of name, state, country are all null

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added a cased of coalesce(name, state, name) = null to avoid injecting another row. Does this suffice?


Example::

os> source=accounts | eval result = coalesce(employer, firstname, lastname) | fields result, firstname, lastname, employer
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Change the os> to PPL to disable it in current doctest since this is only working with Calcite enabled.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done


Usage: coalesce(field1, field2, ...) return the first non-null value in the argument list.

Argument type: all the supported data type, (NOTE : if parameters have different type, you will fail semantic check)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(NOTE : if parameters have different type, you will fail semantic check)
Change to the The data types of all fields must be same.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
@LantaoJin LantaoJin merged commit f480958 into opensearch-project:main May 21, 2025
22 checks passed
@anasalkouz
Copy link
Copy Markdown
Member

Is this merged to 3.1?

@yuancu
Copy link
Copy Markdown
Collaborator Author

yuancu commented Jun 14, 2025

Is this merged to 3.1?

Yes!

penghuo pushed a commit that referenced this pull request Jun 16, 2025
* Support function coalesce with Calcite

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Add antoher test case for coalesce & disable coalesce's doctest

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

---------

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

calcite calcite migration releated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Support function coalesce

4 participants