|
@@ -0,0 +1,58 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: π
|
|
|
+ * 2021/8/30 16:57
|
|
|
+ */
|
|
|
+public class get_legal extends UDF {
|
|
|
+ private static List<String> cols = Arrays.asList("amomon", "paymet", "time");
|
|
|
+
|
|
|
+ public List<String> evaluate(String json) {
|
|
|
+ if (StringUtils.isBlank(json) || "[]".equalsIgnoreCase(json)) return Arrays.asList(null, null);
|
|
|
+ try {
|
|
|
+ List<Map> list1 = JSON.parseArray(json, Map.class);
|
|
|
+ HashMap<String, String> m1 = list1.stream().map(m -> {
|
|
|
+ HashMap<String, String> tm = new HashMap<>();
|
|
|
+ tm.put("human_name", toStringV2(m.getOrDefault("name", "")));
|
|
|
+ tm.put("human_pid", toStringV2(m.getOrDefault("id", "")));
|
|
|
+ tm.put("deleted", toStringV2(m.getOrDefault("deleted", "")));
|
|
|
+ return tm;
|
|
|
+ }).filter(m -> m.get("deleted").toString().equalsIgnoreCase("0"))
|
|
|
+ .findFirst().orElse(new HashMap<String, String>());
|
|
|
+ if(m1.isEmpty()) return Arrays.asList(null, null);
|
|
|
+ m1.remove("deleted");
|
|
|
+ return Arrays.asList(m1.get("human_name"), m1.get("human_pid"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return Arrays.asList(null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String toStringV2(Object o) {
|
|
|
+ if (null == o) return null;
|
|
|
+ return o.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ get_legal j = new get_legal();
|
|
|
+ //String json = "[{\"name\":\"冯金元\",\"id\":\"pbc6c4f933e85850d1c401509877671b0\",\"type\":1,\"deleted\":0}]";
|
|
|
+ //String json = "[{\"name\":\"冯金元\",\"id\":\"pbc6c4f933e85850d1c401509877671b0\",\"type\":1,\"deleted\":1}]";
|
|
|
+ String json = "[{\"name\":\"冯金元\",\"id\":\"pbc6c4f933e85850d1c401509877671b0\",\"type\":1,\"deleted\":1},{\"name\":\"冯金元2\",\"id\":\"pbc6c4f933e85850d1c401509877671b0\",\"type\":1,\"deleted\":0}]";
|
|
|
+ List<String> evaluate = j.evaluate(json);
|
|
|
+ System.out.println(evaluate);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|