Skip to content
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

#3145 Add IP Address Data Type #3175

Merged
merged 26 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a8da96d
Add `ExprIpValue` and `IP` data type
currantw Nov 27, 2024
19b9100
Add support for casting (`cast(field_name to ip)`) and remove existin…
currantw Nov 28, 2024
f842ddb
Update comparison logic to compare in IPv6
currantw Dec 2, 2024
16b1825
Fix bug casting to IP
currantw Dec 2, 2024
8e33635
Fix failing tests
currantw Dec 2, 2024
24aa29e
Assert that comparison only valid if same type, update tests accordingly
currantw Dec 2, 2024
021b727
Add additional tests to increase code coverage
currantw Dec 3, 2024
d203425
Integrate `cidrmatch` changes
currantw Dec 4, 2024
aadc8f8
Remove `OpenSearchIPType` data type
currantw Dec 4, 2024
1aed13e
Fix more failing tests
currantw Dec 4, 2024
47746e4
Minor cleanup
currantw Dec 5, 2024
d03bd4f
Add new tests for IP data type to `SortCommandIT`, and update `weblog…
currantw Dec 11, 2024
7569d08
Fixing IT test failure.
currantw Dec 11, 2024
bfcd86d
Spotless and update test to sort in SQL
currantw Dec 11, 2024
9cd9817
Fix broken link
currantw Dec 11, 2024
8c52d2b
Fix failing code coverage
currantw Dec 11, 2024
0278f0b
Fix failing doctest
currantw Dec 11, 2024
f0d4f6d
Fix failing `ip.rst` doctest
currantw Dec 13, 2024
774861b
Fix test failure due to merge.
currantw Dec 13, 2024
a2ec8cf
Fix spotless
currantw Dec 13, 2024
7036e5f
Add missing `url` field
currantw Dec 17, 2024
ac9c300
Address minor review comments.
currantw Dec 17, 2024
6355b2d
Revert sort syntax changes
currantw Dec 18, 2024
b8bf9b8
Minor doc update
currantw Dec 18, 2024
5298b38
FIx failing `ip.rst` doctest
currantw Dec 18, 2024
4718848
Add `IPComparisonIT` tests for comparison operators, rename modules a…
currantw Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove OpenSearchIPType data type
Signed-off-by: currantw <[email protected]>
currantw committed Dec 18, 2024
commit aadc8f8ccdef8ec28ec56b2f9b51f8dab8c50710
Original file line number Diff line number Diff line change
@@ -155,10 +155,7 @@ public void dateFunctionNameCaseInsensitiveTest() {
public void ipTypeShouldPassJdbcFormatter() {
assertThat(
executeQuery(
"SELECT host FROM "
+ TestsConstants.TEST_INDEX_WEBLOG
+ " ORDER BY host",
"jdbc"),
"SELECT host FROM " + TestsConstants.TEST_INDEX_WEBLOG + " ORDER BY host", "jdbc"),
containsString("\"type\": \"ip\""));
}

Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ public void init() throws IOException {

@Test
public void test_cidrmatch() throws IOException {

JSONObject result;

// No matches
Original file line number Diff line number Diff line change
@@ -160,8 +160,6 @@ public static OpenSearchDataType of(MappingType mappingType, Map<String, Object>
return OpenSearchGeoPointType.of();
case Binary:
return OpenSearchBinaryType.of();
case Ip:
return OpenSearchIpType.of();
case Date:
case DateNanos:
// Default date formatter is used when "" is passed as the second parameter

This file was deleted.

Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
import static org.opensearch.sql.data.type.ExprCoreType.IP;
import static org.opensearch.sql.data.type.ExprCoreType.LONG;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
@@ -64,7 +65,6 @@
import org.opensearch.sql.opensearch.data.type.OpenSearchBinaryType;
import org.opensearch.sql.opensearch.data.type.OpenSearchDataType;
import org.opensearch.sql.opensearch.data.type.OpenSearchDateType;
import org.opensearch.sql.opensearch.data.type.OpenSearchIpType;
import org.opensearch.sql.opensearch.data.utils.Content;
import org.opensearch.sql.opensearch.data.utils.ObjectContent;
import org.opensearch.sql.opensearch.data.utils.OpenSearchJsonContent;
@@ -203,14 +203,12 @@ private ExprValue parse(
} else if (type.equals(OpenSearchDataType.of(OpenSearchDataType.MappingType.Object))
|| type == STRUCT) {
return parseStruct(content, field, supportArrays);
} else if (typeActionMap.containsKey(type)) {
return typeActionMap.get(type).apply(content, type);
} else {
if (typeActionMap.containsKey(type)) {
return typeActionMap.get(type).apply(content, type);
} else {
throw new IllegalStateException(
String.format(
"Unsupported type: %s for value: %s.", type.typeName(), content.objectValue()));
}
throw new IllegalStateException(
String.format(
"Unsupported type: %s for value: %s.", type.typeName(), content.objectValue()));
}
}

@@ -419,10 +417,10 @@ private ExprValue parseGeoPoint(Content content, boolean supportArrays) {
*/
private ExprValue parseInnerArrayValue(
Content content, String prefix, ExprType type, boolean supportArrays) {
if (type instanceof OpenSearchIpType
|| type instanceof OpenSearchBinaryType
|| type instanceof OpenSearchDateType) {
if (type instanceof OpenSearchBinaryType || type instanceof OpenSearchDateType) {
return parse(content, prefix, Optional.of(type), supportArrays);
} else if (content.isString() && type.equals(OpenSearchDataType.of(IP))) {
return parse(content, prefix, Optional.of(OpenSearchDataType.of(IP)), supportArrays);
} else if (content.isString()) {
return parse(content, prefix, Optional.of(OpenSearchDataType.of(STRING)), supportArrays);
} else if (content.isLong()) {
Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.opensearch.data.type.OpenSearchDataType;
import org.opensearch.sql.opensearch.data.type.OpenSearchDateType;
import org.opensearch.sql.opensearch.data.type.OpenSearchIpType;
import org.opensearch.sql.opensearch.data.type.OpenSearchTextType;
import org.opensearch.sql.opensearch.data.utils.OpenSearchJsonContent;

@@ -117,7 +116,7 @@ class OpenSearchExprValueFactoryTest {
"textKeywordV",
OpenSearchTextType.of(
Map.of("words", OpenSearchDataType.of(OpenSearchDataType.MappingType.Keyword))))
.put(fieldIp, OpenSearchIpType.of(OpenSearchDataType.MappingType.Ip))
.put(fieldIp, OpenSearchDataType.of(OpenSearchDataType.MappingType.Ip))
.put("geoV", OpenSearchDataType.of(OpenSearchDataType.MappingType.GeoPoint))
.put("binaryV", OpenSearchDataType.of(OpenSearchDataType.MappingType.Binary))
.build();
@@ -688,10 +687,10 @@ public void constructBinaryArrayReturnsAll() {
public void constructArrayOfIPsReturnsAll() {
final String ipv4String = "1.2.3.4";
final String ipv6String = "2001:db7::ff00:42:8329";

assertEquals(
new ExprCollectionValue(List.of(ipValue(ipv4String), ipValue(ipv6String))),
tupleValue(String.format("{\"%s\":[\"%s\",\"%s\"]}", fieldIp, ipv4String, ipv6String))
.get(fieldIp));
new ExprCollectionValue(List.of(ipValue("1.2.3.4"), ipValue("2001:db7::ff00:42:8329"))),
tupleValue("{\"ipV\":[" + "\"1.2.3.4\"," + "\"2001:db7::ff00:42:8329\"" + "]}").get("ipV"));
}

@Test