有一次a表中一个字段A string
但是存的是 {"orderid":745005721,"dealtype":[23,311,226]}
要将a表的A字段导入到b表的B字段
但是B字段的类型是map
会报错 Cannot convert column 1 from string to map<string,string>.
那么想到用udf函数来解决
写了自定义函数返回map类型
public Map<String,String> evaluate(String json) throws JSONException{
Map map = new HashMap();
if(!json.equals("")&&json!=null&&!json.equals("null")){
map= getMap4Json(json);
}
return map;
}
public static Map<String,String> getMap4Json(String jsonString) throws JSONException{
JSONObject dataJson=new JSONObject(jsonString);
Iterator keyIter = dataJson.keys();
String key;
Object value;
Map valueMap = new HashMap();
但是存的是 {"orderid":745005721,"dealtype":[23,311,226]}
要将a表的A字段导入到b表的B字段
但是B字段的类型是map
会报错 Cannot convert column 1 from string to map<string,string>.
那么想到用udf函数来解决
写了自定义函数返回map类型
public Map<String,String> evaluate(String json) throws JSONException{
Map map = new HashMap();
if(!json.equals("")&&json!=null&&!json.equals("null")){
map= getMap4Json(json);
}
return map;
}
public static Map<String,String> getMap4Json(String jsonString) throws JSONException{
JSONObject dataJson=new JSONObject(jsonString);
Iterator keyIter = dataJson.keys();
String key;
Object value;
Map valueMap = new HashMap();