待解析数据字段与样例:
样例1:
request: TmPromiseReParam [calcMode=A, queryType=0, srcCode=662AA02P, destCode=752BK, consignTime=Fri Sep 24 11:21:00 CST 2021, weight=1.0, productType=T6, monthCard=null, srcAoi=662AA000832, destAoi=752BK000208, serviceCode=null, waybillNo=null, maps=null]
reponse: {"finalTm_T6":"2D1200","T6":"2021-09-25 12:00","standTm_T6":"2D1200","aoiFinalTm_T6":"2D1200","costTm":"12","planFlag":"0","aoiStandTm_T6":"2D1200"}
样例2:
request: TmPromiseReParam [calcMode=A, queryType=0, srcCode=023SN02P, destCode=512GC, consignTime=Fri Sep 24 10:01:00 CST 2021, weight=1.0, productType=T4, monthCard=null, srcAoi=023SN000116, destAoi=512GC000150, serviceCode=null, waybillNo=null, maps={operationTime=2021-09-24 10:08:44}]
reponse: {"finalTm_T4":"2D1200","T4":"2021-09-25 12:00","standTm_T4":"2D1200"}
需要获取reponse字段中finalTm_T6/finalTm_T4/。。与aoiFinalTm_T6/aoiFinalTm_T4/。。对应的数据,得到两列字段名为finalTm与aoiFinalTm 的数据。第二行中没有aoiFinalTm属性,即为空。
finaltm | aoifinalfm | times |
---|---|---|
2D1200 | 2D1200 | 2021-09-24 11:21:00 |
2D1200 | 2021-09-24 10:01:00 |
reponse字段是典型的json 格式,可以使用get_json_object 进行读取,但是get_json_object的参数,第一个参数为操作对应的列,第二个参数为想要提取的属性,如get_json_object(data, ‘$.owner’);然本数据中的属性随着字段request 里的productType变化而变化,因此该数据分两步走:
第一步:将request字段中的productType对应的数据提取出来;
第二步:再提取reponse中的字段数据。
--第二步
select
get_json_object(reponse, concat('$.',concat('finalTm_',limit_type_code))) as finalTm
,get_json_object(reponse, concat('$.',concat('aoiFinalTm_',limit_type_code))) as aoiFinalTm
,from_unixtime(unix_timestamp(consigned, 'EEE MMM dd HH:mm:ss zzz yyyy'),'yyyy-MM-dd HH:mm:ss') as times
--时间的转换
from
(
--第一步
select *,split(split(request,',')[6],'=')[1] as limit_type_code,split(split(request,',')[4],'=')[1] as consigned from temple
)a
这样就完成目标解析了。