|
@@ -0,0 +1,53 @@
|
|
|
+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.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: π
|
|
|
+ * 2021/8/30 16:57
|
|
|
+ */
|
|
|
+public class trans_tel_info extends UDF {
|
|
|
+ private static List<String> cols = Arrays.asList("amomon", "paymet", "time");
|
|
|
+
|
|
|
+ public String evaluate(String json) {
|
|
|
+ if (StringUtils.isBlank(json) || "[]".equalsIgnoreCase(json)) return null;
|
|
|
+ try {
|
|
|
+ List<Map> list1 = JSON.parseArray(json, Map.class);
|
|
|
+ List<Map> m1 = list1.stream().map(m -> {
|
|
|
+ String public_time = toStringV2(m.getOrDefault("public_time", null));
|
|
|
+ if(org.apache.commons.lang.StringUtils.isNotBlank(public_time) && public_time.length() == 18){
|
|
|
+ public_time = public_time.substring(0,10)+" "+ public_time.substring(10);
|
|
|
+ }
|
|
|
+ m.put("public_time",public_time);
|
|
|
+ return m;
|
|
|
+ }).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (m1.isEmpty()) return null;
|
|
|
+ return JSON.toJSONString(m1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String toStringV2(Object o) {
|
|
|
+ if (null == o) return null;
|
|
|
+ return o.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ trans_tel_info j = new trans_tel_info();
|
|
|
+ String json = "[{\"deleted\":\"0\",\"is_phone\":2,\"public_time\":\"2020-01-0100:00:00\",\"source\":\"2020年报\",\"tel\":\"021-32278500\"},{\"deleted\":\"0\",\"is_phone\":2,\"public_time\":\"2014-01-0100:00:00\",\"source\":\"2014年报\",\"tel\":\"021-51118422\"},{\"deleted\":\"0\",\"is_phone\":2,\"public_time\":\"2018-01-0100:00:00\",\"source\":\"2018年报\",\"tel\":\"021-51118500\"}]";
|
|
|
+ String evaluate = j.evaluate(json);
|
|
|
+ System.out.println(evaluate);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|