Skip to content

Commit

Permalink
Fix remaining failing unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Oct 31, 2024
1 parent 4b60ae1 commit 08af013
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.opensearch.sql.data.model.ExprValueUtils.*;
import static org.opensearch.sql.data.model.ExprValueUtils.integerValue;
import static org.opensearch.sql.data.model.ExprValueUtils.longValue;
import static org.opensearch.sql.data.type.ExprCoreType.*;

import java.util.ArrayList;
Expand Down Expand Up @@ -195,7 +196,7 @@ public void test_percentile_with_invalid_size() {
"percentile_approx function expected"
+ " {[INTEGER,DOUBLE],[INTEGER,DOUBLE,DOUBLE],[LONG,DOUBLE],[LONG,DOUBLE,DOUBLE],"
+ "[FLOAT,DOUBLE],[FLOAT,DOUBLE,DOUBLE],[DOUBLE,DOUBLE],[DOUBLE,DOUBLE,DOUBLE]},"
+ " but get [DOUBLE,STRING]",
+ " but got [DOUBLE,STRING]",
exception2.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,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
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,9 @@

package org.opensearch.sql.opensearch.data.type;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.BYTE;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
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.LONG;
import static org.opensearch.sql.data.type.ExprCoreType.SHORT;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import static org.opensearch.sql.data.type.ExprCoreType.UNKNOWN;
import static org.opensearch.sql.data.type.ExprCoreType.*;
import static org.opensearch.sql.opensearch.data.type.OpenSearchDataType.MappingType;

import java.util.Map;
Expand Down Expand Up @@ -110,7 +90,7 @@ private static Stream<Arguments> getTestDataWithType() {
Arguments.of(MappingType.Nested, "nested", ARRAY),
Arguments.of(MappingType.GeoPoint, "geo_point", OpenSearchGeoPointType.of()),
Arguments.of(MappingType.Binary, "binary", OpenSearchBinaryType.of()),
Arguments.of(MappingType.Ip, "ip", OpenSearchIpType.of()));
Arguments.of(MappingType.Ip, "ip", STRING));
}

@ParameterizedTest(name = "{1}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,9 @@

package org.opensearch.sql.opensearch.data.value;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opensearch.sql.data.model.ExprValueUtils.booleanValue;
import static org.opensearch.sql.data.model.ExprValueUtils.byteValue;
import static org.opensearch.sql.data.model.ExprValueUtils.collectionValue;
import static org.opensearch.sql.data.model.ExprValueUtils.doubleValue;
import static org.opensearch.sql.data.model.ExprValueUtils.floatValue;
import static org.opensearch.sql.data.model.ExprValueUtils.integerValue;
import static org.opensearch.sql.data.model.ExprValueUtils.longValue;
import static org.opensearch.sql.data.model.ExprValueUtils.nullValue;
import static org.opensearch.sql.data.model.ExprValueUtils.shortValue;
import static org.opensearch.sql.data.model.ExprValueUtils.stringValue;
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.BYTE;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
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.LONG;
import static org.opensearch.sql.data.type.ExprCoreType.SHORT;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import static org.junit.jupiter.api.Assertions.*;
import static org.opensearch.sql.data.model.ExprValueUtils.*;
import static org.opensearch.sql.data.type.ExprCoreType.*;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -49,19 +24,16 @@
import org.junit.jupiter.api.Test;
import org.opensearch.OpenSearchParseException;
import org.opensearch.geometry.utils.Geohash;
import org.opensearch.sql.data.model.ExprCollectionValue;
import org.opensearch.sql.data.model.ExprDateValue;
import org.opensearch.sql.data.model.ExprTimeValue;
import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprTupleValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.model.*;
import org.opensearch.sql.opensearch.data.type.OpenSearchDataType;
import org.opensearch.sql.opensearch.data.type.OpenSearchDateType;
import org.opensearch.sql.opensearch.data.type.OpenSearchTextType;
import org.opensearch.sql.opensearch.data.utils.OpenSearchJsonContent;

class OpenSearchExprValueFactoryTest {

static final String fieldIp = "ipV";

private static final Map<String, OpenSearchDataType> MAPPING =
new ImmutableMap.Builder<String, OpenSearchDataType>()
.put("byteV", OpenSearchDataType.of(BYTE))
Expand Down Expand Up @@ -112,7 +84,7 @@ class OpenSearchExprValueFactoryTest {
"textKeywordV",
OpenSearchTextType.of(
Map.of("words", OpenSearchDataType.of(OpenSearchDataType.MappingType.Keyword))))
.put("ipV", OpenSearchDataType.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 @@ -660,12 +632,12 @@ public void constructArrayOfGeoPointsReturnsAll() {

@Test
public void constructArrayOfIPsReturnsAll() {
final String ip1 = "192.168.0.1";
final String ip2 = "192.168.0.2";

assertEquals(
new ExprCollectionValue(
List.of(
new OpenSearchExprIpValue("192.168.0.1"),
new OpenSearchExprIpValue("192.168.0.2"))),
tupleValue("{\"ipV\":[\"192.168.0.1\",\"192.168.0.2\"]}").get("ipV"));
new ExprCollectionValue(List.of(new ExprStringValue(ip1), new ExprStringValue(ip2))),
tupleValue(String.format("{\"%s\":[\"%s\",\"%s\"]}", fieldIp, ip1, ip2)).get(fieldIp));
}

@Test
Expand Down Expand Up @@ -741,9 +713,17 @@ public void constructStruct() {

@Test
public void constructIP() {
final String valueIpv4 = "192.168.0.1";
assertEquals(
stringValue(valueIpv4),
tupleValue(String.format("{\"%s\":\"%s\"}", fieldIp, valueIpv4)).get(fieldIp));
assertEquals(stringValue(valueIpv4), constructFromObject(fieldIp, valueIpv4));

final String valueIpv6 = "2001:0db7::ff00:42:8329";
assertEquals(
new OpenSearchExprIpValue("192.168.0.1"),
tupleValue("{\"ipV\":\"192.168.0.1\"}").get("ipV"));
stringValue(valueIpv6),
tupleValue(String.format("{\"%s\":\"%s\"}", fieldIp, valueIpv6)).get(fieldIp));
assertEquals(stringValue(valueIpv6), constructFromObject(fieldIp, valueIpv6));
}

private static final double TOLERANCE = 1E-5;
Expand Down

0 comments on commit 08af013

Please sign in to comment.