|
@@ -2,6 +2,7 @@ package com.aliyun.odps.spark.examples.myUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.odps.Column;
|
|
|
import com.aliyun.odps.data.Record;
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
@@ -10,13 +11,13 @@ import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
|
|
|
public class ConvertUtils {
|
|
|
- public static JSONObject getFeature(Record record, List<Map<String, String>> videoSeq, int scale) {
|
|
|
+ public static JSONObject getFeature(Map<String, String> record, List<Map<String, String>> videoSeq, int scale) {
|
|
|
Map<String, Double> featMap = new HashMap<>();
|
|
|
|
|
|
// origin info
|
|
|
- String ts = record.getString("ts");
|
|
|
+ String ts = record.get("ts");
|
|
|
long currentMs = Long.parseLong(ts) * 1000;
|
|
|
- String vid = record.getString("vid");
|
|
|
+ String vid = record.get("vid");
|
|
|
Map<String, String> headInfo = getRecordCol(record, "v2_feature");
|
|
|
Map<String, String> rankInfo = getRecordCol(record, "v1_feature");
|
|
|
Map<String, Map<String, String>> userOriginInfo = getUserOriginInfo(record);
|
|
@@ -60,7 +61,7 @@ public class ConvertUtils {
|
|
|
return filterAndTruncate(featMap, scale);
|
|
|
}
|
|
|
|
|
|
- private static Map<String, Map<String, String>> getUserOriginInfo(Record record) {
|
|
|
+ private static Map<String, Map<String, String>> getUserOriginInfo(Map<String, String> record) {
|
|
|
Map<String, Map<String, String>> map = new HashMap<>();
|
|
|
map.put("mid_global_feature_20250212", getRecordCol(record, "c1_feature"));
|
|
|
map.put("mid_merge_cate1_feature_20250212", getRecordCol(record, "c2_feature"));
|
|
@@ -74,7 +75,7 @@ public class ConvertUtils {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- private static Map<String, Map<String, Map<String, String>>> getVideoOriginInfo(Record record) {
|
|
|
+ private static Map<String, Map<String, Map<String, String>>> getVideoOriginInfo(Map<String, String> record) {
|
|
|
Map<String, Map<String, String>> map = new HashMap<>();
|
|
|
map.put("alg_vid_global_feature_20250212", getRecordCol(record, "b1_feature"));
|
|
|
map.put("alg_vid_recommend_exp_feature_20250212", getRecordCol(record, "b2_feature"));
|
|
@@ -94,7 +95,7 @@ public class ConvertUtils {
|
|
|
map.put("alg_recsys_feature_cf_i2i_v2", getRecordCol(record, "d3_feature"));
|
|
|
|
|
|
Map<String, Map<String, Map<String, String>>> allMap = new HashMap<>();
|
|
|
- String vid = record.getString("vid");
|
|
|
+ String vid = record.get("vid");
|
|
|
allMap.put(vid, map);
|
|
|
return allMap;
|
|
|
}
|
|
@@ -137,6 +138,41 @@ public class ConvertUtils {
|
|
|
return colMap;
|
|
|
}
|
|
|
|
|
|
+ public static Map<String, String> getRecordCol(Map<String, String> record, String col) {
|
|
|
+ Map<String, String> colMap = new HashMap<>();
|
|
|
+ if (null != record && record.containsKey(col)) {
|
|
|
+ try {
|
|
|
+ JSONObject json = JSON.parseObject(record.get(col));
|
|
|
+ if (null != json) {
|
|
|
+ for (Map.Entry<String, Object> entry : json.entrySet()) {
|
|
|
+ Object obj = entry.getValue();
|
|
|
+ if (null != obj) {
|
|
|
+ colMap.put(entry.getKey(), obj.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return colMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<String, String> record2Map(Record record) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ if (null != record) {
|
|
|
+ Column[] columns = record.getColumns();
|
|
|
+ if (null != columns) {
|
|
|
+ for (Column column : columns) {
|
|
|
+ String name = column.getName();
|
|
|
+ if (!record.isNull(name)) {
|
|
|
+ map.put(name, record.getString(name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
public static Map<String, Map<String, String>> list2Map(List<Map<String, String>> videSeq) {
|
|
|
Map<String, Map<String, String>> map = new HashMap<>();
|
|
|
if (null != videSeq && !videSeq.isEmpty()) {
|