From fe8d600f60e2bf70f924c352445414c61787f8a1 Mon Sep 17 00:00:00 2001 From: YANGDB Date: Wed, 11 Dec 2024 15:43:32 -0800 Subject: [PATCH] fix tests Signed-off-by: YANGDB --- .../function/SerializableJsonUdfTest.java | 98 ------------------- 1 file changed, 98 deletions(-) diff --git a/ppl-spark-integration/src/test/java/org/opensearch/sql/expression/function/SerializableJsonUdfTest.java b/ppl-spark-integration/src/test/java/org/opensearch/sql/expression/function/SerializableJsonUdfTest.java index 884d3d5a2..fb47803cf 100644 --- a/ppl-spark-integration/src/test/java/org/opensearch/sql/expression/function/SerializableJsonUdfTest.java +++ b/ppl-spark-integration/src/test/java/org/opensearch/sql/expression/function/SerializableJsonUdfTest.java @@ -7,18 +7,10 @@ import org.junit.Test; import scala.collection.mutable.WrappedArray; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.apache.derby.vti.XmlVTI.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.opensearch.sql.expression.function.SerializableUdf.jsonAppendFunction; import static org.opensearch.sql.expression.function.SerializableUdf.jsonDeleteFunction; -import static org.opensearch.sql.expression.function.SerializableUdf.jsonExtendFunction; public class SerializableJsonUdfTest { @@ -158,94 +150,4 @@ public void testJsonAppendFunctionInvalidJson() { String result = jsonAppendFunction.apply(invalidJson, WrappedArray.make(new String[]{"key1", "newValue"})); assertNull(result); } - - @Test - public void testJsonExtendFunctionWithExistingPath() { - String jsonStr = "{\"path1\": [\"value1\", \"value2\"]}"; - List>> pathValuePairs = new ArrayList<>(); - pathValuePairs.add(Map.entry("path1", asList("value3", "value4"))); - - String result = jsonExtendFunction.apply(jsonStr, pathValuePairs); - String expectedJson = "{\"path1\":[\"value1\",\"value2\",\"value3\",\"value4\"]}"; - - assertEquals(expectedJson, result); - } - - @Test - public void testJsonExtendFunctionWithNewPath() { - String jsonStr = "{\"path1\": [\"value1\"]}"; - List>> pathValuePairs = new ArrayList<>(); - pathValuePairs.add(Map.entry("path2", asList("newValue1", "newValue2"))); - - String result = jsonExtendFunction.apply(jsonStr, pathValuePairs); - String expectedJson = "{\"path1\":[\"value1\"],\"path2\":[\"newValue1\",\"newValue2\"]}"; - - assertEquals(expectedJson, result); - } - - @Test - public void testJsonExtendFunctionWithNullInput() { - String result = jsonExtendFunction.apply(null, Collections.emptyList()); - assertNull(result); - } - - @Test - public void testJsonExtendFunctionWithInvalidJson() { - String result = jsonExtendFunction.apply("invalid json", Collections.emptyList()); - assertNull(result); - } - - @Test - public void testJsonExtendFunctionWithNonArrayPath() { - String jsonStr = "{\"path1\":\"value1\"}"; - List>> pathValuePairs = new ArrayList<>(); - pathValuePairs.add(Map.entry("path1", asList("value2"))); - - String result = jsonExtendFunction.apply(jsonStr, pathValuePairs); - String expectedJson = "{\"path1\":[\"value2\"]}"; - - assertEquals(expectedJson, result); - } - - @Test - public void testJsonExtendFunctionAddValuesToExistingArray() { - String jsonStr = "{\"key1\":\"value1\",\"key2\":[\"value2\"]}"; - List>> pathValuePairs = new ArrayList<>(); - pathValuePairs.add( Map.entry("key2", Arrays.asList("value3", "value4"))); - - String expectedJson = "{\"key1\":\"value1\",\"key2\":[\"value2\",\"value3\",\"value4\"]}"; - String result = jsonExtendFunction.apply(jsonStr, pathValuePairs); - - assertEquals(expectedJson, result); - } - - @Test - public void testJsonExtendFunctionAddNewArray() { - String jsonStr = "{\"key1\":\"value1\"}"; - List>> pathValuePairs = new ArrayList<>(); - pathValuePairs.add( Map.entry("key2", Arrays.asList("value2", "value3"))); - - String expectedJson = "{\"key1\":\"value1\",\"key2\":[\"value2\",\"value3\"]}"; - String result = jsonExtendFunction.apply(jsonStr, pathValuePairs); - - assertEquals(expectedJson, result); - } - - @Test - public void testJsonExtendFunctionHandleEmptyValues() { - String jsonStr = "{\"key1\":\"value1\",\"key2\":[\"value2\"]}"; - List>> pathValuePairs = new ArrayList<>(); - pathValuePairs.add( Map.entry("key2", Collections.emptyList())); - - String expectedJson = "{\"key1\":\"value1\",\"key2\":[\"value2\"]}"; - String result = jsonExtendFunction.apply(jsonStr, pathValuePairs); - - assertEquals(expectedJson, result); - } - - @Test - public void testJsonExtendFunctionHandleNullInput() { - String result = jsonExtendFunction.apply(null, Collections.singletonList( Map.entry("key2", List.of("value2")))); - assertEquals(null, result); - } }