-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CIDR function to PPL (#3036) #3110
Add CIDR function to PPL (#3036) #3110
Conversation
There was a problem hiding this 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
.../test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java
Outdated
Show resolved
Hide resolved
@jduo Currently working on integration tests, which don't appear to yet support the IP address type in OpenSearch. |
There was a problem hiding this 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.
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/ip/IPFunctionTest.java
Outdated
Show resolved
Hide resolved
.../test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
- Update Lexer and Parser. - Add `DSL::cidr` and BuiltinFunctionName.CIDR`. - Add `BinaryPredicateOperator::cidr`. - Add `IPUtils` with stub implementation of `isAddressInRange`. Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
…nge` implementation to return `false` rather than raising an exception. Signed-off-by: currantw <[email protected]>
...earch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java
Outdated
Show resolved
Hide resolved
...h/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java
Show resolved
Hide resolved
There was a problem hiding this 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.
core/src/main/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator.java
Show resolved
Hide resolved
Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
…ort for IP address type). Signed-off-by: currantw <[email protected]>
"type": "ip" | ||
}, | ||
"host_string": { | ||
"type": "keyword" | ||
}, | ||
"method": { | ||
"type": "text" |
There was a problem hiding this comment.
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.
void equal() { | ||
assertTrue(ipValue.equal(new OpenSearchExprIpValue("192.168.0.1"))); | ||
void testEqual() { | ||
assertTrue(ipValue.equal(new OpenSearchExprIpValue(ipString))); | ||
} |
There was a problem hiding this comment.
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 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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 <[email protected]>
Signed-off-by: currantw <[email protected]>
@@ -563,6 +563,10 @@ public static FunctionExpression regexp(Expression... expressions) { | |||
return compile(FunctionProperties.None, BuiltinFunctionName.REGEXP, expressions); | |||
} | |||
|
|||
public static FunctionExpression cidrmatch(Expression... expressions) { |
There was a problem hiding this comment.
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:
public static FunctionExpression cidrmatch(Expression... expressions) { | |
public static FunctionExpression cidr(Expression... expressions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, to match with spark documentation: https://github.com/opensearch-project/opensearch-spark/blob/main/docs/ppl-lang/functions/ppl-ip.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acarbonetto good catch 👍
There was a problem hiding this comment.
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...)
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/ip/IPFunction.java
Outdated
Show resolved
Hide resolved
@currantw I'll let u update the code according to @acarbonetto comments ... |
Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
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
--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.