Skip to content

Commit

Permalink
Remove OpenSearchIPType data type
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 4, 2024
1 parent 1766211 commit e34a834
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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\""));
}

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

@Test
public void test_cidrmatch() throws IOException {

JSONObject result;

// No matches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e34a834

Please sign in to comment.