deemoliu commented on code in PR #13581:
URL: https://github.com/apache/pinot/pull/13581#discussion_r1681916232


##########
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:
   is this convertedMap.keySet() order guaranteed? if we ingest data with the 
udf, will the output consistent from the all partitions?



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to