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


##########
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() {
+    }
+
+    /**
+     * Internal Helper Function to convert Json String Values to Java Maps
+     * @param jsonString
+     * @return converted Java Map from JSON String
+     */
+    public static Map stringToMap(String jsonString) {
+        //input validation for ObjectMapper.readValue();
+        if (jsonString == null) {
+            return null;
+        }
+
+        Map<Object, Object> convertedMap = null;
+        try {
+            //object --> java map with objectMapper
+            convertedMap = new ObjectMapper().readValue(jsonString,
+                    new TypeReference<Map<Object, Object>>() { });
+        } catch (Exception e) {
+            throw new RuntimeException("Unknown issue: " + jsonString);
+        }
+
+        return convertedMap;
+    }
+
+    /**
+     * Scalar listKeys UDF that lists all keys from a String representation of 
JSON Map
+     * @param jsonString
+     * @return string array of all keys from JSON map in data
+     */
+    @ScalarFunction
+    public static String[] listKeys(String jsonString) {
+        //handle empty string case
+        if (jsonString == null) {
+            return new String[]{};
+        }
+
+        //convert string input to equivalent java map
+        Map convertedMap = stringToMap(jsonString);
+
+        //add map keys to an object list
+        List<Object> mapList = new ArrayList<>(convertedMap.size());
+        mapList.addAll(convertedMap.keySet());

Review Comment:
   No, addressed with LinkedHashMap change in new commit



-- 
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