Skip to content

Conversation

@currantw
Copy link
Contributor

@currantw currantw commented Oct 23, 2024

Description

Adds the cidr function to PPL, which returns whether an IP address is within an IP address range specified in CIDR notation.

Related Issues

Resolves #3036.

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • [N/A] 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
Contributor

@jduo jduo left a comment

Choose a reason for hiding this comment

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

There should be an integration test as well.
Please check if there is an explain test needed and others such as AstBuiderTest, AstExpressionBuliderTest

@currantw
Copy link
Contributor Author

@jduo Currently working on integration tests, which don't appear to yet support the IP address type in OpenSearch.

Copy link
Contributor

@jduo jduo left a comment

Choose a reason for hiding this comment

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

Generally a good practice is to mark local variables as final when possible.

- Update Lexer and Parser.
- Add `DSL::cidr` and BuiltinFunctionName.CIDR`.
- Add `BinaryPredicateOperator::cidr`.
- Add `IPUtils` with stub implementation of `isAddressInRange`.

Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
…nge` implementation to return `false` rather than raising an exception.

Signed-off-by: currantw <taylor.curran@improving.com>
Copy link
Collaborator

@MaxKsyunz MaxKsyunz left a comment

Choose a reason for hiding this comment

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

Changing base type for OpenSearchIP from UNKNOWN to STRING has far reaching consequence and I think best reverted. At the very least needs a dedicated PR and explicit discussion.

See latest action run -- several integration tests are now failing.

Have you seen prometheus module? It defines prometheus-specific function that work on prometheus-specific types.

Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
…ort for IP address type).

Signed-off-by: currantw <taylor.curran@improving.com>
"type": "keyword"
},
"method": {
"type": "text"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split into to fields with IP address and string data types, respectively. Should facilitate testing both once we add support for IP address data type in #3145.

assertTrue(ipValue.equal(new OpenSearchExprIpValue("192.168.0.1")));
void testEqual() {
assertTrue(ipValue.equal(new OpenSearchExprIpValue(ipString)));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes no longer necessary because chanegs to IP data type were reverted, but figured it wasn't necessary to "undo" any code cleanup work 🤷

MaxKsyunz
MaxKsyunz previously approved these changes Nov 26, 2024
Copy link
Collaborator

@MaxKsyunz MaxKsyunz left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Member

Choose a reason for hiding this comment

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

add CIDR to the can-be-Id commands list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added conditionFunctionName (LIKE, ISNULL, ISNOTNULL, and CIDRMATCH) to the keywordsCanBeId group.

Copy link
Member

Choose a reason for hiding this comment

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

nice - but next time lets separate general code refactory from a specific feature plz

YANG-DB
YANG-DB previously approved these changes Nov 27, 2024
Copy link
Member

@YANG-DB YANG-DB left a comment

Choose a reason for hiding this comment

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

@currantw LGTM - only a few minor comments and we can merge !!
thanks

Signed-off-by: currantw <taylor.curran@improving.com>
@currantw currantw dismissed stale reviews from YANG-DB and MaxKsyunz via 43d05d6 November 28, 2024 00:13
Signed-off-by: currantw <taylor.curran@improving.com>
YANG-DB
YANG-DB previously approved these changes Nov 28, 2024
acarbonetto
acarbonetto previously approved these changes Dec 2, 2024
return compile(FunctionProperties.None, BuiltinFunctionName.REGEXP, expressions);
}

public static FunctionExpression cidrmatch(Expression... expressions) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure why you added the match here:

Suggested change
public static FunctionExpression cidrmatch(Expression... expressions) {
public static FunctionExpression cidr(Expression... expressions) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@acarbonetto good catch 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, as mentioned, I used cidrmatch for consistency with Spark (even though I agree that cidr is a better name...)

@YANG-DB
Copy link
Member

YANG-DB commented Dec 2, 2024

@currantw I'll let u update the code according to @acarbonetto comments ...
ping me once its ready & I'll merge - thanks !!

Signed-off-by: currantw <taylor.curran@improving.com>
@currantw currantw dismissed stale reviews from acarbonetto and YANG-DB via d3be058 December 2, 2024 20:34
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
@acarbonetto acarbonetto merged commit 6712526 into opensearch-project:main Dec 3, 2024
14 of 15 checks passed
@acarbonetto acarbonetto deleted the opensearch-3036 branch December 3, 2024 17:14
@yuancu yuancu mentioned this pull request May 21, 2025
6 tasks
penghuo pushed a commit that referenced this pull request Jun 16, 2025
Signed-off-by: currantw <taylor.curran@improving.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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]PPL Add CIDR IP range command support

7 participants