-
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
[FEATURE] Add Support for IP Data Type #3145
Comments
we really need this feature, we can't even do basic IP lookups right now! query SELECT *
FROM logs-vpc
WHERE dstaddr = "10.100.138.82"
LIMIT 10; log
|
Hi @currantw - this is a great idea Can we explicitly use an This should be applicable for any
|
…ort for IP address type). Signed-off-by: currantw <taylor.curran@improving.com>
PROPOSED SOLUTION
Additional notes:
|
@currantw I think that comparisons should support both IPv4 and IPv6 addresses. For example an IPv4 address could be compared to an IPv6 address. To implement this, I think it makes sense to have all IPv6 addresses be greater than all IPv4 addresses. Consider an index that has an IP field. The field contains both IPv4 and IPv6 addresses. We should be able to sort based on that column. Sorting needs to be able to compare values. For IPv6, |
Another thing to consider is IPv4 address in IPv6 representation. This could mean that some IPv6 addresses are equal to some IPv4 addresses, such as:
|
Thanks @normanj-bitquill for the comments and suggestions. I think it makes sense to try (to the extent possible) to model the SQL plugin's IP address data type behaviour on the existing core OpenSearch behaviour.
|
UPDATE IP Data Type Behaviour As discussed above, the IP address data type in the SQL plugin is intended to mirror the core OpenSearch behaviour:
Casting to IP Address Data Type
Outdated Sorting Syntax During work on this issue, I discovered that PPL supports syntax for sorting numerically, lexicographically, or by IP address (e.g. As such, I have removed this syntax from the SQL plugin as part of this issue (to avoid clashes with the Some Examples Important note. Some queries are executed entirely within core OpenSearch, rather than within the SQL plugin. There are indicated with an asterisk (*) below, in order to verify that the behaviour is the same (e.g. sorting order) between core OpenSearch and the SQL plugin.
|
Hi @currantw |
Issues raised:
As mentioned, I will resolve #3180 as part of the same PR as this issue, and address the Spark one separately. |
* Add `ExprIpValue` and `IP` data type Signed-off-by: currantw <taylor.curran@improving.com> * Add support for casting (`cast(field_name to ip)`) and remove existing unused sorting syntax. Signed-off-by: currantw <taylor.curran@improving.com> * Update comparison logic to compare in IPv6 Signed-off-by: currantw <taylor.curran@improving.com> * Fix bug casting to IP Signed-off-by: currantw <taylor.curran@improving.com> * Fix failing tests Signed-off-by: currantw <taylor.curran@improving.com> * Assert that comparison only valid if same type, update tests accordingly Signed-off-by: currantw <taylor.curran@improving.com> * Add additional tests to increase code coverage Signed-off-by: currantw <taylor.curran@improving.com> * Integrate `cidrmatch` changes Signed-off-by: currantw <taylor.curran@improving.com> * Remove `OpenSearchIPType` data type Signed-off-by: currantw <taylor.curran@improving.com> * Fix more failing tests Signed-off-by: currantw <taylor.curran@improving.com> * Minor cleanup Signed-off-by: currantw <taylor.curran@improving.com> * Add new tests for IP data type to `SortCommandIT`, and update `weblogs` test data. Signed-off-by: currantw <taylor.curran@improving.com> * Fixing IT test failure. Signed-off-by: currantw <taylor.curran@improving.com> * Spotless and update test to sort in SQL Signed-off-by: currantw <taylor.curran@improving.com> * Fix broken link Signed-off-by: currantw <taylor.curran@improving.com> * Fix failing code coverage Signed-off-by: currantw <taylor.curran@improving.com> * Fix failing doctest Signed-off-by: currantw <taylor.curran@improving.com> * Fix failing `ip.rst` doctest Signed-off-by: currantw <taylor.curran@improving.com> * Fix test failure due to merge. Signed-off-by: currantw <taylor.curran@improving.com> * Fix spotless Signed-off-by: currantw <taylor.curran@improving.com> * Add missing `url` field Signed-off-by: currantw <taylor.curran@improving.com> * Address minor review comments. Signed-off-by: currantw <taylor.curran@improving.com> * Revert sort syntax changes Signed-off-by: currantw <taylor.curran@improving.com> * Minor doc update Signed-off-by: currantw <taylor.curran@improving.com> * FIx failing `ip.rst` doctest Signed-off-by: currantw <taylor.curran@improving.com> * Add `IPComparisonIT` tests for comparison operators, rename modules and weblogs test index to make plural for consistency. Signed-off-by: currantw <taylor.curran@improving.com> --------- Signed-off-by: currantw <taylor.curran@improving.com>
Is your feature request related to a problem?
OpenSearch SQL plugin does not support the IP address field type.
🚫 IP address fields are converted to strings:
search=weblog | fields host
returns
host
with field typestring
.🚫 IP address fields cannot be correctly for equality:
search=weblog | where host = "2001:0db7::ff00:42:8329" | fields host
will not return the value
2001:0db7:0000:0000:0000:ff00:0042:8329
, even though both strings represent the same IP address.What solution would you like?
Outcomes:
=
and!=
).<
,<=
,>
, and>
) if they are both IPv4 or IPv6.cidrmatch
- see Add CIDR function to PPL (#3036) #3110).Proposed Solution:
IP
type toExprCoreType
.OpenSearchExprIpValue
withExprIpValue
, and update implementation.OpenSearchDataType.MappingType
to map"ip"
fields toExprCoreType.IP
.OpenSearchExprValueFactory
.What alternatives have you considered?
None
Do you have any additional context?
This is closely related to #3110. This issue added a new
cidrmatch(ip, cidr)
function that returns whether the given IP address is within the specified CIDR IP address range. As part of this work, the SQL plugin was updated to cast IP addresses to strings - previously, it would raise an exception.The text was updated successfully, but these errors were encountered: