Skip to content

Conversation

@yuancu
Copy link
Collaborator

@yuancu yuancu commented Jul 24, 2025

Description

Support casting to IP:

It supports:

  • IP -> IP
  • IPv4 string -> IP
  • IPv6 string -> IP

Implementation

I created a IP_CAST operator to handle IP casting. It is called in ExtendedRexBuilder.makeCast. Besides, I refactored type checkers relating to IP type checking, so that we don't have to create a new type checker class for each function that uses an UDT that can not be mapped to Calcite's data types.

Related Issues

Resolves #3918

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.

Copy link
Member

@LantaoJin LantaoJin left a comment

Choose a reason for hiding this comment

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

@yuancu
Copy link
Collaborator Author

yuancu commented Jul 24, 2025

I saw IP in the PPL Data Types section. Do you mean we need a specific section like Date and Time Data Types to describe its behaviors?

@LantaoJin
Copy link
Member

I saw IP in the PPL Data Types section. Do you mean we need a specific section like Date and Time Data Types to describe its behaviors?

Yes. we miss a IP type description in datatypes.rst. please add one. But I think it could be a separated PR.

@qianheng-aws qianheng-aws merged commit 411395d into opensearch-project:main Jul 28, 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-3919-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 411395dd595359acdd94a54f0544aa20a6f9833d
# Push it to GitHub
git push --set-upstream origin backport/backport-3919-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-3919-to-2.19-dev.

yuancu added a commit to yuancu/sql-plugin that referenced this pull request Jul 29, 2025
* Support casting ip

Signed-off-by: Yuanchun Shen <[email protected]>

* Refactor type checking for UDT (specifically, IP)

Signed-off-by: Yuanchun Shen <[email protected]>

* Remove IPCastFunctionTest

Signed-off-by: Yuanchun Shen <[email protected]>

* Remove unused IPUtil function

Signed-off-by: Yuanchun Shen <[email protected]>

* Fix error message of comparing with different types

Signed-off-by: Yuanchun Shen <[email protected]>

* Correct casting ip to string & update conversion doc

Signed-off-by: Yuanchun Shen <[email protected]>

* Change string representation form IP [ip] to [ip] to accomadate casting ip to string

Signed-off-by: Yuanchun Shen <[email protected]>

---------

Signed-off-by: Yuanchun Shen <[email protected]>
(cherry picked from commit 411395d)
yuancu added a commit to yuancu/sql-plugin that referenced this pull request Jul 29, 2025
* Support casting ip

Signed-off-by: Yuanchun Shen <[email protected]>

* Refactor type checking for UDT (specifically, IP)

Signed-off-by: Yuanchun Shen <[email protected]>

* Remove IPCastFunctionTest

Signed-off-by: Yuanchun Shen <[email protected]>

* Remove unused IPUtil function

Signed-off-by: Yuanchun Shen <[email protected]>

* Fix error message of comparing with different types

Signed-off-by: Yuanchun Shen <[email protected]>

* Correct casting ip to string & update conversion doc

Signed-off-by: Yuanchun Shen <[email protected]>

* Change string representation form IP [ip] to [ip] to accomadate casting ip to string

Signed-off-by: Yuanchun Shen <[email protected]>

---------

Signed-off-by: Yuanchun Shen <[email protected]>
(cherry picked from commit 411395d)
LantaoJin pushed a commit that referenced this pull request Jul 30, 2025
* Support casting ip



* Refactor type checking for UDT (specifically, IP)



* Remove IPCastFunctionTest



* Remove unused IPUtil function



* Fix error message of comparing with different types



* Correct casting ip to string & update conversion doc



* Change string representation form IP [ip] to [ip] to accomadate casting ip to string



---------


(cherry picked from commit 411395d)

Signed-off-by: Yuanchun Shen <[email protected]>
@LantaoJin LantaoJin added the backport-manually Filed a PR to backport manually. label Jul 31, 2025
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. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Casting to IP is not supported with Calcite

3 participants