Copilot commented on code in PR #16306:
URL: https://github.com/apache/pinot/pull/16306#discussion_r2193899383
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java:
##########
@@ -332,6 +332,55 @@ private static void setValuesToMap(String keyColumnName,
String valueColumnName,
}
}
+ /**
+ * Returns all key paths in a JSON object up to the specified depth.
+ * Each key path is dot-separated for nested keys.
+ * @param jsonObj JSON object or string
+ * @param maxDepth Maximum depth to recurse (inclusive)
+ * @return Array of key paths (dot notation)
+ */
+ @ScalarFunction(nullableParameters = true)
+ public static List jsonKeys(@Nullable Object jsonObj, int maxDepth) {
+ if (jsonObj == null || maxDepth < 1) {
+ return List.of();
+ }
+ ObjectMapper mapper = new ObjectMapper();
Review Comment:
Instantiating an ObjectMapper for every invocation is expensive; consider
using a shared static final ObjectMapper to reuse its configuration and reduce
overhead.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java:
##########
@@ -332,6 +332,55 @@ private static void setValuesToMap(String keyColumnName,
String valueColumnName,
}
}
+ /**
+ * Returns all key paths in a JSON object up to the specified depth.
+ * Each key path is dot-separated for nested keys.
+ * @param jsonObj JSON object or string
+ * @param maxDepth Maximum depth to recurse (inclusive)
+ * @return Array of key paths (dot notation)
+ */
+ @ScalarFunction(nullableParameters = true)
+ public static List jsonKeys(@Nullable Object jsonObj, int maxDepth) {
Review Comment:
Declare the return type as List<String> instead of raw List to improve type
safety and avoid unchecked warnings.
```suggestion
public static List<String> jsonKeys(@Nullable Object jsonObj, int
maxDepth) {
```
--
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]