|
@@ -0,0 +1,42 @@
|
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author: π
|
|
|
|
+ * 2021/8/30 16:57
|
|
|
|
+ */
|
|
|
|
+public class lawyer_list extends UDF {
|
|
|
|
+ public List<String> evaluate(String json) {
|
|
|
|
+ if (StringUtils.isBlank(json) || "[]".equals(json)) return null;
|
|
|
|
+ List<Map> list1 = JSON.parseArray(json, Map.class);
|
|
|
|
+ Set<String> set = list1.stream().map(x -> {
|
|
|
|
+ String lawyer_name = (String) x.getOrDefault("lawyer_name", "");
|
|
|
|
+ String lawfirm_name = (String) x.getOrDefault("lawfirm_name", "");
|
|
|
|
+ if (StringUtils.isNotBlank(lawyer_name) && StringUtils.isNotBlank(lawfirm_name)) {
|
|
|
|
+ return lawyer_name + "@@" + lawfirm_name;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
|
|
|
|
+ if (set.isEmpty()) return null;
|
|
|
|
+ return new ArrayList<>(set);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ lawyer_list j = new lawyer_list();
|
|
|
|
+ String js = "[{\"lawyer_name\": \"柴昕\", \"lawfirm_name\": \"湖南人和(东莞)律师事务所\"}, {\"lawyer_name\": \"王丹\", \"lawfirm_name\": \"湖南人和(东莞)律师事务所\"}]";
|
|
|
|
+ //String js = "";
|
|
|
|
+ List<String> evaluate = j.evaluate(js);
|
|
|
|
+ System.out.println(evaluate);
|
|
|
|
+ evaluate.stream().forEach(x->{
|
|
|
|
+ String[] arr = x.split("@@");
|
|
|
|
+ System.out.println(Arrays.toString(arr));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|