summaryrefslogtreecommitdiff
path: root/groot-common
diff options
context:
space:
mode:
authorwangkuan <[email protected]>2024-08-15 11:50:18 +0800
committerwangkuan <[email protected]>2024-08-15 11:50:18 +0800
commitf7927f9ce7e651f925db8fed2cb4e89f5b5e10c8 (patch)
tree83f20d6909704a21d37ac7d7bd15434608011ecb /groot-common
parent184940fea67a14fb4cf5313a78ee5e705f13680b (diff)
[feature][core]新增JsonUnroll函数,优化Unroll函数feature/table
Diffstat (limited to 'groot-common')
-rw-r--r--groot-common/src/main/java/com/geedgenetworks/common/utils/JsonPathUtil.java33
-rw-r--r--groot-common/src/main/resources/udf.plugins1
2 files changed, 34 insertions, 0 deletions
diff --git a/groot-common/src/main/java/com/geedgenetworks/common/utils/JsonPathUtil.java b/groot-common/src/main/java/com/geedgenetworks/common/utils/JsonPathUtil.java
index dcba58c..0823ddc 100644
--- a/groot-common/src/main/java/com/geedgenetworks/common/utils/JsonPathUtil.java
+++ b/groot-common/src/main/java/com/geedgenetworks/common/utils/JsonPathUtil.java
@@ -2,6 +2,8 @@ package com.geedgenetworks.common.utils;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONPath;
import com.alibaba.fastjson2.JSONReader;
@@ -42,4 +44,35 @@ public class JsonPathUtil {
}
return flattenResult;
}
+ public static Object get(JSONObject jsonObject, String expr) {
+ Object Result = "";
+ try {
+ Result = jsonObject.getByPath(expr);
+ } catch (Exception e) {
+ logger.error(
+ "The label resolution exception or [expr] analytic expression error"
+ + e.getMessage());
+ }
+ return Result;
+ }
+ public static JSONObject set(JSONObject jsonObject, String expr,Object value) {
+ try {
+ JSONPath.set(jsonObject, expr, value);
+ } catch (Exception e) {
+ logger.error(
+ "JSONObject set value exception or [expr] expression error"
+ + e.getMessage());
+ }
+ return jsonObject;
+ }
+ public static JSONObject remove(JSONObject jsonObject, String expr) {
+ try {
+ JSONPath.remove(jsonObject, expr);
+ } catch (Exception e) {
+ logger.error(
+ "JSONObject remove value exception or [expr] expression error"
+ + e.getMessage());
+ }
+ return jsonObject;
+ }
}
diff --git a/groot-common/src/main/resources/udf.plugins b/groot-common/src/main/resources/udf.plugins
index ca0a7ac..18446c9 100644
--- a/groot-common/src/main/resources/udf.plugins
+++ b/groot-common/src/main/resources/udf.plugins
@@ -21,4 +21,5 @@ com.geedgenetworks.core.udf.udaf.LongCount
com.geedgenetworks.core.udf.udaf.Mean
com.geedgenetworks.core.udf.udaf.LastValue
com.geedgenetworks.core.udf.udaf.FirstValue
+com.geedgenetworks.core.udf.udtf.JsonUnroll
com.geedgenetworks.core.udf.udtf.Unroll \ No newline at end of file