Skip to content

Commit 8dd6f41

Browse files
committed
Update UT
Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent 7d0b0c3 commit 8dd6f41

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

opensearch/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.junit.jupiter.api.Assertions.assertAll;
99
import static org.junit.jupiter.api.Assertions.assertEquals;
1010
import static org.junit.jupiter.api.Assertions.assertFalse;
11+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1112
import static org.junit.jupiter.api.Assertions.assertThrows;
1213
import static org.junit.jupiter.api.Assertions.assertTrue;
1314
import static org.opensearch.sql.data.model.ExprValueUtils.booleanValue;
@@ -1101,6 +1102,77 @@ public void constructWithMiddleDotsFieldNameReturnsValue() {
11011102
assertEquals(stringValue("value"), structValue.tupleValue().get("a..b"));
11021103
}
11031104

1105+
@Test
1106+
public void constructWithTopLevelTrailingDotFieldName() {
1107+
// Top-level field name "field." should be preserved
1108+
Map<String, ExprValue> result = tupleValue("{\"field.\":\"value\"}");
1109+
assertEquals(stringValue("value"), result.get("field."));
1110+
}
1111+
1112+
@Test
1113+
public void constructWithTopLevelLeadingDotFieldName() {
1114+
// Top-level field name ".field" should be preserved
1115+
Map<String, ExprValue> result = tupleValue("{\".field\":\"value\"}");
1116+
assertEquals(stringValue("value"), result.get(".field"));
1117+
}
1118+
1119+
@Test
1120+
public void constructWithMultipleMalformedFieldsAtSameLevel() {
1121+
// Multiple malformed fields at same level should all be preserved
1122+
Map<String, ExprValue> result =
1123+
tupleValue("{\"structV\":{\".\":\"v1\",\"..\":\"v2\",\"...\":\"v3\"}}");
1124+
ExprValue structValue = result.get("structV");
1125+
assertEquals(stringValue("v1"), structValue.tupleValue().get("."));
1126+
assertEquals(stringValue("v2"), structValue.tupleValue().get(".."));
1127+
assertEquals(stringValue("v3"), structValue.tupleValue().get("..."));
1128+
}
1129+
1130+
@Test
1131+
public void constructWithMalformedFieldContainingValue() {
1132+
// Malformed field name "a." containing a value should be preserved
1133+
Map<String, ExprValue> result = tupleValue("{\"structV\":{\"a.\":\"value\"}}");
1134+
ExprValue structValue = result.get("structV");
1135+
ExprValue aValue = structValue.tupleValue().get("a.");
1136+
assertNotNull(aValue);
1137+
assertEquals(stringValue("value"), aValue);
1138+
}
1139+
1140+
@Test
1141+
public void constructWithVariousMalformedFieldPatterns() {
1142+
// Test various malformed field name patterns
1143+
Map<String, ExprValue> result =
1144+
tupleValue("{\"structV\":{\"a.b.\":\"v1\",\".a.b\":\"v2\",\"a..b\":\"v3\"}}");
1145+
ExprValue structValue = result.get("structV");
1146+
assertEquals(stringValue("v1"), structValue.tupleValue().get("a.b."));
1147+
assertEquals(stringValue("v2"), structValue.tupleValue().get(".a.b"));
1148+
assertEquals(stringValue("v3"), structValue.tupleValue().get("a..b"));
1149+
}
1150+
1151+
@Test
1152+
public void jsonPathLiteralPreservesFieldName() {
1153+
// JsonPath.literal() should preserve the exact field name
1154+
JsonPath path = JsonPath.literal("a..b");
1155+
assertEquals(1, path.getPaths().size());
1156+
assertEquals("a..b", path.getRootPath());
1157+
}
1158+
1159+
@Test
1160+
public void jsonPathLiteralWithDotOnlyFieldName() {
1161+
// JsonPath.literal() with "." should create single-element path
1162+
JsonPath path = JsonPath.literal(".");
1163+
assertEquals(1, path.getPaths().size());
1164+
assertEquals(".", path.getRootPath());
1165+
}
1166+
1167+
@Test
1168+
public void jsonPathFromPathSplitsByDots() {
1169+
// JsonPath.fromPath() should split by dots for nested paths
1170+
JsonPath path = JsonPath.fromPath("a.b.c");
1171+
assertEquals(3, path.getPaths().size());
1172+
assertEquals("a", path.getRootPath());
1173+
assertEquals(List.of("b", "c"), path.getChildPath().getPaths());
1174+
}
1175+
11041176
public Map<String, ExprValue> tupleValue(String jsonString) {
11051177
final ExprValue construct = exprValueFactory.construct(jsonString, false);
11061178
return construct.tupleValue();

0 commit comments

Comments
 (0)