Navya-Kumar commented on code in PR #13581:
URL: https://github.com/apache/pinot/pull/13581#discussion_r1683289048


##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/MapFunctions.java:
##########
@@ -0,0 +1,67 @@
+package org.apache.pinot.common.function.scalar;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+public class MapFunctions {
+    private MapFunctions() {

Review Comment:
   Attempted with new diff, please ping if it still isn't resolved.



##########
pinot-common/src/test/java/org/apache/pinot/common/function/scalar/MapFunctionsTest.java:
##########
@@ -0,0 +1,124 @@
+package org.apache.pinot.common.function.scalar;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+public class MapFunctionsTest {
+
+    @Test
+    public void testRegMapSameTypes()
+            throws JsonProcessingException {
+
+        // CHECKSTYLE:OFF
+        // @formatter:off
+
+        //test with all same type keys and values (Strings)
+        String jsonString = "{" +
+                "  \"id\": \"7044885078\"," +
+                "  \"type\": \"CreateEvent\"," +
+                "  \"public\": \"true\"," +
+                "  \"created_at\": \"2018-01-01T11:12:53Z\"," +
+                "    \"date\": \"November\"," +
+                "    \"occasion\": \"Anniversary\"," +
+                "    \"emotion\": \"Happiness\"" +
+                "}";
+
+        // @formatter:on
+        // CHECKSTYLE:ON
+
+        assertEquals(MapFunctions.listKeys(jsonString), new String[]{"id", 
"type", "public", "created_at",
+                "date", "occasion", "emotion"});
+    }
+
+    @Test
+    public void testRegMapDiffTypes1()
+            throws JsonProcessingException {
+
+        // CHECKSTYLE:OFF
+        // @formatter:off
+
+        //test with different type values (number, bool, array, string, null)
+        String jsonString = "{" +
+                "  \"id\": 704488," +
+                "  \"type\": false," +
+                "  \"public\": 4.0," +
+                "  \"created_at\": \"2018-01-01T11:12:53Z\"," +
+                "    \"date\": \"n\"," +
+                "    \"occasion\":  [80, 85, 90, 95, 100]," +
+                "    \"extra\": null," +
+                "    \"emotion\": [\"happy\",\"sad\",\"angry\"]" +
+                "}";
+
+        // @formatter:on
+        // CHECKSTYLE:ON
+
+        assertEquals(MapFunctions.listKeys(jsonString), new String[]{"id", 
"type", "public", "created_at", "date",
+                "occasion", "extra", "emotion"});
+    }
+
+    @Test
+    public void testRegMapDiffTypes2()
+            throws JsonProcessingException {
+
+        // CHECKSTYLE:OFF
+        // @formatter:off
+
+        //test different value types, emphasis on the case of "subjects" value
+        String jsonString = "{\n" +
+                "    \"name\": \"Pete\",\n" +
+                "    \"age\": 24,\n" +
+                "    \"subjects\": [\n" +
+                "        {\n" +
+                "            \"name\": \"maths\",\n" +
+                "            \"homework_grades\": [80, 85, 90, 95, 100],\n" +
+                "            \"grade\": \"A\"\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"name\": \"english\",\n" +
+                "            \"homework_grades\": [60, 65, 70, 85, 90],\n" +
+                "            \"grade\": \"B\"\n" +
+                "        }\n" +
+                "    ]\n" +
+                "}";
+
+        // @formatter:on
+        // CHECKSTYLE:ON
+
+        assertEquals(MapFunctions.listKeys(jsonString), new String[]{"name", 
"age", "subjects"});
+    }
+
+
+    @Test
+    public void testEmpty()
+            throws JsonProcessingException {
+
+        // CHECKSTYLE:OFF
+        // @formatter:off

Review Comment:
   Addressed



##########
pinot-common/src/test/java/org/apache/pinot/common/function/scalar/MapFunctionsTest.java:
##########
@@ -0,0 +1,124 @@
+package org.apache.pinot.common.function.scalar;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+public class MapFunctionsTest {
+
+    @Test
+    public void testRegMapSameTypes()
+            throws JsonProcessingException {
+
+        // CHECKSTYLE:OFF

Review Comment:
   Addressed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to