hive字段拼接json格式

hive用named_struct(‘字段1’,字段1,‘字段2’,字段2) 可以拼接json,并且特别方便

用最原始的方法拼接json:

startdate=`date -d '-1 days' +%Y-%m-%d`
date=`date '+%Y-%m-%d %H:%M:%S'`

sql="
select concat('{\"date\":\"','$date','\",\"actions\":[',concat('{\"itemId\":\"',itemId,
'\",\"actionTime\":',actionTime,
',\"action\":\"',action,
'\",\"sceneId\":\"',sceneId,
'\",\"userId\":\"',userId,
'\",\"blogId\":\"',nvl(blogId, '-'),
'\",\"uuid_tt_dd\":\"',uuid_tt_dd,
'\"}'),']}') as value
from(
select split(regexp_replace(curl,'\\\\?','/'),'/')[4] itemId,
cast(concat(unix_timestamp(concat(pv_dt,' ',pv_time)),'000') as bigint) actionTime,
'csdnStatistics' action,
case when split(curl,'=')[1]='blogt0' then '420' else '34' end sceneId,
uid userId,
split(regexp_replace(ref,'\\\\?','/'),'/')[6] blogId,
cid uuid_tt_dd
from csdnbi.fact_pv_data
where (curl = 'https://www.baidu.com/topic/python115?utm_source=blogt0'
or curl = 'https://www.baidu.com/topic/ai20?utm_source=blogt3'
or curl = 'https://www.baidu.com/topic/blockchain10?utm_source=blogt3')
and pdate = '$startdate') t
"

hive -e "set mapred.job.name=zoujcTask;set mapred.job.queue.name=super;$sql" > logdata.txt
cat logdata.txt | while read line
do
curl -X POST 'https://www.baidu.com/action/api/log?clientToken=1difushafhsiufh88888' -H 'Content-Type: application/json' -d "$line"
done



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值