Skip to content

test(native): Add ipprefix and ipaddress tests to native-tests#26905

Merged
aditi-pandit merged 3 commits intoprestodb:masterfrom
wongquijote:ipprefix_tests
Feb 4, 2026
Merged

test(native): Add ipprefix and ipaddress tests to native-tests#26905
aditi-pandit merged 3 commits intoprestodb:masterfrom
wongquijote:ipprefix_tests

Conversation

@wongquijote
Copy link
Contributor

@wongquijote wongquijote commented Jan 6, 2026

Summary:
Ported the IpPrefix and IpAddress tests in https://github.com/prestodb/presto/blob/master/presto-main-base/src/test/java/com/facebook/presto/operator/scalar/TestIpPrefixFunctions.java to run with Presto Native engine in presto-native-tests.

This is a continuation of the work to refactor scalar function tests from presto-main-base to presto-main-tests from this PR: #26013

Also moved IpPrefixType and IpAddressType into presto-common from presto-main-base due to some dependency cycles that appeared after refactoring.

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jan 6, 2026
@prestodb-ci prestodb-ci requested review from a team, bibith4 and wanglinsong and removed request for a team January 6, 2026 01:08
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 6, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 6, 2026

Reviewer's Guide

Adds shared ipprefix/ipaddress test suite and native engine coverage, while refactoring IP type locations and dependencies to use common type classes and support IPPREFIX in test clients.

Class diagram for shared IP types, operators, functions, and tests

classDiagram
    class Type
    class AbstractType

    class IpAddressType {
    }
    class IpPrefixType {
    }

    class BuiltInTypeAndFunctionNamespaceManager {
    }

    class IpAddressOperators {
    }

    class IpPrefixOperators {
    }

    class IpPrefixFunctions {
    }

    class AbstractTestFunctions {
    }

    class AbstractTestNativeFunctions {
    }

    class AbstractTestIpPrefix {
    }

    class TestIpPrefixFunctions {
    }

    class TestingPrestoClient {
    }

    class CheckUnsupportedPrestissimoTypes {
    }

    Type <|-- AbstractType
    AbstractType <|-- IpAddressType
    AbstractType <|-- IpPrefixType

    BuiltInTypeAndFunctionNamespaceManager --> IpAddressType
    BuiltInTypeAndFunctionNamespaceManager --> IpPrefixType

    IpAddressOperators --> IpAddressType
    IpPrefixOperators --> IpPrefixType

    IpPrefixFunctions --> IpPrefixType

    AbstractTestFunctions <|-- AbstractTestNativeFunctions
    AbstractTestFunctions <|-- AbstractTestIpPrefix

    AbstractTestIpPrefix --> IpPrefixFunctions
    AbstractTestIpPrefix --> IpPrefixType

    AbstractTestNativeFunctions <|-- TestIpPrefixFunctions
    TestIpPrefixFunctions --> AbstractTestIpPrefix

    TestingPrestoClient --> IpPrefixType

    CheckUnsupportedPrestissimoTypes --> Type
    CheckUnsupportedPrestissimoTypes ..> IpAddressType

    class IpAddressType{
        <<moved_to_presto_common_type>>
    }
    class IpPrefixType{
        <<moved_to_presto_common_type>>
    }
Loading

File-Level Changes

Change Details Files
Extract shared IpPrefix/IPADDRESS function tests into a reusable test interface and reuse it for both legacy and native tests, while keeping only error-condition tests local to each suite.
  • Introduce AbstractTestIpPrefix interface under presto-main-tests with data providers and positive-path tests for IP_PREFIX, IP_SUBNET_MIN/MAX/RANGE, IS_SUBNET_OF, IP_PREFIX_COLLAPSE, IS_PRIVATE_IP, and IP_PREFIX_SUBNETS.
  • Update existing Hive/engine TestIpPrefixFunctions to implement AbstractTestIpPrefix and retain only invalid-input tests for IP_PREFIX, IP_PREFIX_COLLAPSE, and IP_PREFIX_SUBNETS.
  • Add native TestIpPrefixFunctions in presto-native-tests that extends AbstractTestNativeFunctions, implements AbstractTestIpPrefix, and defines native-specific invalid-input tests using assertInvalidFunction/assertInvalidCast helpers.
presto-main-tests/src/main/java/com/facebook/presto/tests/operator/scalar/AbstractTestIpPrefix.java
presto-main-base/src/test/java/com/facebook/presto/operator/scalar/TestIpPrefixFunctions.java
presto-native-tests/src/test/java/com/facebook/presto/nativetests/operator/scalar/TestIpPrefixFunctions.java
Enhance the native test base to assert failures for invalid function invocations and casts for use by new IP tests.
  • Add assertInvalidFunction helper to wrap computeActual and validate failure messages via assertExceptionMessage with Pattern.quote.
  • Add assertInvalidCast helper similar to assertInvalidFunction but allowing regex messages directly.
presto-native-tests/src/test/java/com/facebook/presto/nativetests/operator/scalar/AbstractTestNativeFunctions.java
Refactor IpAddressType and IpPrefixType into presto-common and update usages, ensuring tests and clients can reference the common types and support IPPREFIX values.
  • Move IpAddressType and IpPrefixType classes from presto-main-base to presto-common common.type package.
  • Update imports in tests and operator/type classes to use com.facebook.presto.common.type.IpAddressType and IpPrefixType instead of engine-specific types.
  • Extend TestingPrestoClient.convertToRowValue to handle IPPREFIX values pass-through alongside IPADDRESS.
presto-main-base/src/main/java/com/facebook/presto/type/IpAddressType.java
presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixType.java
presto-common/src/main/java/com/facebook/presto/common/type/IpAddressType.java
presto-common/src/main/java/com/facebook/presto/common/type/IpPrefixType.java
presto-main-base/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java
presto-main-base/src/main/java/com/facebook/presto/operator/scalar/IpPrefixFunctions.java
presto-main-base/src/main/java/com/facebook/presto/type/IpAddressOperators.java
presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java
presto-main-base/src/test/java/com/facebook/presto/type/TestIpAddressType.java
presto-main-base/src/test/java/com/facebook/presto/type/TestIpPrefixType.java
presto-main-base/src/test/java/com/facebook/presto/type/TestIpAddressOperators.java
presto-main-base/src/test/java/com/facebook/presto/type/TestIpPrefixOperators.java
presto-main-base/src/test/java/com/facebook/presto/operator/aggregation/TestApproximateCountDistinctIpAddress.java
presto-main-base/src/test/java/com/facebook/presto/sql/planner/sanity/TestCheckUnsupportedPrestissimoTypes.java
presto-tests/src/main/java/com/facebook/presto/tests/TestingPrestoClient.java
Adjust unsupported-type checking and dependencies to allow native IPADDRESS/IPPREFIX usage without pulling in unwanted Guava dependencies from presto-common.
  • Comment out the Prestissimo IPADDRESS unsupported-type branch in CheckUnsupportedPrestissimoTypes to avoid blocking native IPADDRESS usage, while leaving timestamp-with-time-zone enforcement intact.
  • Add Guava exclusions to presto-spi's presto-common dependency (main and test-jar) to ensure SPI doesn’t transitively bring in Guava from presto-common.
  • Change presto-common's Guava dependency to be non-test-scoped so it is available to relocated types without affecting SPI via new exclusions.
presto-main-base/src/main/java/com/facebook/presto/sql/planner/sanity/CheckUnsupportedPrestissimoTypes.java
presto-spi/pom.xml
presto-common/pom.xml
Minor test and import cleanups related to IP types.
  • Switch static imports of IPADDRESS/IPPREFIX in various tests from presto.type.* to presto.common.type.* to reflect refactor.
  • Ensure noisy aggregation tests and other IP-related tests compile against the new type locations.
presto-main-base/src/test/java/com/facebook/presto/operator/aggregation/noisyaggregation/TestNoisyCountGaussianAggregation.java
presto-main-base/src/test/java/com/facebook/presto/operator/aggregation/noisyaggregation/TestNoisyCountGaussianRandomSeedAggregation.java
presto-main-base/src/test/java/com/facebook/presto/type/TestIpPrefixOperators.java
presto-main-base/src/test/java/com/facebook/presto/type/TestIpAddressOperators.java
presto-main-base/src/test/java/com/facebook/presto/operator/aggregation/noisyaggregation/TestNoisyCountGaussianAggregation.java
presto-main-base/src/test/java/com/facebook/presto/operator/aggregation/noisyaggregation/TestNoisyCountGaussianRandomSeedAggregation.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In CheckUnsupportedPrestissimoTypes, instead of commenting out the IPADDRESS check, either remove the dead code and configuration flag or reintroduce it behind a clearly named feature toggle so the behavior is explicit and testable.
  • The new AbstractTestIpPrefix is an interface with default @test methods; consider renaming it (e.g., IpPrefixTestMixin) or adding a brief comment to clarify its intended use as a shared test mixin rather than an abstract base class.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In CheckUnsupportedPrestissimoTypes, instead of commenting out the IPADDRESS check, either remove the dead code and configuration flag or reintroduce it behind a clearly named feature toggle so the behavior is explicit and testable.
- The new AbstractTestIpPrefix is an interface with default @Test methods; consider renaming it (e.g., IpPrefixTestMixin) or adding a brief comment to clarify its intended use as a shared test mixin rather than an abstract base class.

## Individual Comments

### Comment 1
<location> `presto-main-tests/src/main/java/com/facebook/presto/tests/operator/scalar/AbstractTestIpPrefix.java:81-82` </location>
<code_context>
-        };
-    }
-
     @Test
-    public void testIpAddressIpPrefix()
+    public void testInvalidIpAddressIpPrefix()
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding null-handling tests for IP_PREFIX to cover SQL null semantics

Current `IP_PREFIX` tests cover various IPv4/IPv6 and prefix-length combinations, but not null inputs. Please add tests for cases like `IP_PREFIX(CAST(NULL AS IPADDRESS), 24)` and `IP_PREFIX(IPADDRESS '1.2.3.4', CAST(NULL AS INTEGER))` so null semantics are verified consistently for both engine and native implementations.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@pramodsatya pramodsatya self-requested a review January 6, 2026 03:35
Copy link
Contributor

@pramodsatya pramodsatya left a comment

Choose a reason for hiding this comment

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

Thanks @wongquijote, LGTM overall % few comments.

if (type.equals(IPADDRESS) && config.isDisableIPAddressForNative()) {
return Optional.of(ipAddressErrorMessage);
}
// if (type.equals(IPADDRESS) && config.isDisableIPAddressForNative()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change needed? For the ipaddress native-tests, can we not set this config to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved

@Test
public void testInvalidIpAddressIpPrefix()
{
assertInvalidFunction("IP_PREFIX(IPADDRESS '::ffff:1.2.3.4', -1)", "IPv4 subnet size must be in range [0, 32]");
Copy link
Contributor

Choose a reason for hiding this comment

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

These error messages seem to be the same as Presto java error messages? Why are these tests not a part of AbstractTestIpPrefix interface?

Copy link
Contributor Author

@wongquijote wongquijote Jan 6, 2026

Choose a reason for hiding this comment

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

The methods assertInvalidCast and assertInvalidFunction are protected utility methods defined within the AbstractTestNativeFunctions base class.

I wasn't sure if I should change these methods to public, but I'll update in another PR.

Initially, I took this design from AbstractTestFunctions which I believe designed it this way because these methods are specific implementation details of the testing framework that shouldn't be exposed rather than public behavioral specifications, therefore they are not included in the AbstractTestIpPrefix interface. Consequently, tests that rely on these protected helpers must reside in the concrete class (TestIpPrefixFunctions) which has access to the base class's internal methods via inheritance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added another commit addressing these comments.

* limitations under the License.
*/
package com.facebook.presto.type;
package com.facebook.presto.common.type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you separate the changes moving IpAddress and IpPrefix types to a separate commit/PR?

Copy link
Contributor Author

@wongquijote wongquijote Jan 6, 2026

Choose a reason for hiding this comment

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

It's updated now as two separate commits

@steveburnett
Copy link
Contributor

Please sign the Presto CLA as mentioned in this comment.

Please add

Release Notes

== NO RELEASE NOTE ==

in the PR description.

@aditi-pandit
Copy link
Contributor

Thanks @wongquijote for this PR. Want to check if Tim is comfortable with the refactor for IPAddressType module you have done.

@tdcmeehan : Do you have any concerns with moving IPAddress/IPPrefix types from presto-common to presto-main-base to consolidate all the tests as proposed here ?

@tdcmeehan tdcmeehan self-assigned this Feb 3, 2026
Copy link
Contributor

@tdcmeehan tdcmeehan left a comment

Choose a reason for hiding this comment

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

Fine by me

Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @wongquijote

@aditi-pandit aditi-pandit merged commit 9ab52f5 into prestodb:master Feb 4, 2026
120 of 126 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants