日常数据需求讲解2-json内容改造

背景

目前有这样一张表ods_cs_json表(算法模型返回客服舆情数据)有2个字段user_id、message,后续会将数据传输到后端kafka,message消息如下:

[
    {
        "criteriaOfJudgment": "该用户在客诉工单中有1条语兴好物圈需净化内容",
        "matchingDegree": "100%",
        "profilingTag": "语兴好物客诉舆情用户",
        "tagType": "modelTag",
        "datasource":"社区"
    },
    {
        "criteriaOfJudgment": "该用户在客诉工单中有1条语兴好物圈需净化内容",
        "matchingDegree": "100%",
        "profilingTag": "语兴好物客诉舆情用户",
        "tagType": "modelTag",
        "datasource":"电商"
    },
    {
        "criteriaOfJudgment": "该用户在客诉工单中有1条语兴好物圈需净化内容",
        "matchingDegree": "100%",
        "profilingTag": "语兴好物客诉舆情用户",
        "tagType": "modelTag",
        "datasource":"金融"
    }
]

内容属于list套json,可能多个json在list中,目前需求是接入一个新的数据源,动态舆情,看下有客诉的用户他动态舆情多少(通过user_id关联),并把原来客诉工单号也给带上,动态舆情对应数据表样式:

CREATE TABLE IF NOT EXISTS ods_trend_intelligence_di(
         user_id STRING COMMENT 'user_id',
         trend_id STRING COMMENT '动态id',
         url STRING COMMENT '备注',
) 

最终实现样式为,就是把动态舆情数据与算法推送topic数据合并一起

[
    {
        "criteriaOfJudgment": "该用户在客诉工单中有1条疑似被骗内容",
        "matchingDegree": "100%",
        "profilingTag": "疑似被骗用户",
        "tagType": "modelTag",
        "ticketList":"xxx",
        "datasource":"社区"
    },
    {
        "criteriaOfJudgment": "该用户共发布动态数1条",
        "matchingDegree": "0%",
        "profilingTag": "动态舆情用户",
        "tagType": "bizTag",
        "ticketList":"xxx,xxx,xx",
        "datasource":"社区"
    }
]

思路

思路1:首先拿到这个需求先要明确2个json的内容映射,需要找产品和后端对齐

json中字段

映射字段

备注

criteriaOfJudgment

计算好的动态数

matchingDegree

0%

由于是业务打标所以这里算法识别度为0%

profilingTag

动态舆情用户(文本)

tagType

bizTag(文本)

datasource

社区

思路2:由于原来list数据中是多json的,因此需要对list去炸裂,并解析出每个元素

思路3:对动态舆情数据进行指标计算,并且封装json

思路4:将动态舆情数据和算法推送客诉数据合并到一个list中

操作

insert overwrite table xxx.dwd_xxx_di partition(pt='${bizdate}')

select t0.user_id
      ,t1.message
from ods_cs_json t0

left join 
(

select concat('[',CONCAT_WS(',',message),coalesce(if(t1_1.content_json is not null ,concat(',',t1_1.content_json),null),''),']') as message
      ,user_id
from (
SELECT collect_list(to_json(map(
                    'criteriaOfJudgment',criteriaOfJudgment,
                    'matchingDegree',matchingDegree,
                    'profilingTag',profilingTag,
                    'tagType',tagType,
                    'datasource',datasource,
                    'ticketList',concat_ws(',',t1_0_1.ticket_list) 
                  )
            )
        ) as message
        ,user_id
from (
SELECT GET_JSON_OBJECT(message3,'$.criteriaOfJudgment')  as criteriaOfJudgment
      ,GET_JSON_OBJECT(message3,'$.matchingDegree')  as matchingDegree 
      ,GET_JSON_OBJECT(message3,'$.profilingTag')  as profilingTag --取出元素
      ,GET_JSON_OBJECT(message3,'$.datasource')  as datasource --取出元素      
      ,'modelTag' as tagType

      ,user_id

from (
select concat(replace(replace(message2,'[{','{'),',{','{'),'}') as message3 
      ,user_id
from (
select  user_id
       ,message
       ,datasource
from ods_cs_json
where pt='${bizdate_0}' --由于是实时返回数据,需要取t-0分区
)
lateral view explode(split(message,'}')) t as message2--炸裂
) 
where message3<>']}'
) t1_0_0

left join (
select collect_list(ticket_id) as ticket_list
      ,user_id
      ,datasource
from 
dwd_cs_json_di
where pt>='${bizdate_30}'
group by user_id
        ,datasource
) t1_0_1
on t1_0_0.user_id=t1_0_1.user_id
AND t1_0_0.datasource=t1_0_1.datasource


group by user_id   

) t1_0 


left join 

(
select user_id
      ,concat('{"criteriaOfJudgment":"',criteriaOfJudgment,'",',
                '"matchingDegree":"','0%','",',
                '"profilingTag":"','动态舆情用户','",',
                '"datasource":"','社区','",',
                '"ticketList":"',ticketList,'",',   
                '"tagType":"','bizTag','"}',
               
      ) as content_json
from (
select concat('该用户共发布动态数',trend_cnt,'条') as criteriaOfJudgment
       concat_ws(',',trend_list)) as ticketList
      ,user_id
from (
SELECT collect_list(concat(trend_id,'-',url)) as trend_list
      ,count(1) as trend_cnt
      ,user_id
FROM ods_trend_intelligence_di
WHERE pt >= '${bizdate_30}'--t-1
group by user_id
)
)
) t1_1 
ON cast(t1_0.user_id as string)=cast(t1_1.user_id as string)
) t1
on t0.user_id = t1.user_id
#数据人offer决赛圈怎么选##数据人的面试交流地##牛客创作赏金赛##聊聊我眼中的AI##Java#
全部评论

相关推荐

04-07 15:42
已编辑
香港中文大学 Java
4.7更新,收到offer了发出来求个好运,求求团子收留我吧,你知道的我外卖一直都是用美团的,至于饿了么,我祝他好运。部门业务研发,好像是到店的部门,base上海总时长约1h1.自我介绍2.拷打实习(20-30min)实习基本上是以交流的方式问答,唯一一个没答出来完全卡壳的是根据实习业务重新分库分表会怎么设计,问得比较细,分多少个库,为什么这么分,分库分表有什么维度可以考虑。这个是真没想过也不太会,请教一下大伙分库分表的思路。3.问AI(30-40min)我不太确定这个ai到底是问我项目呢还是说就是在问对ai的使用和了解(我在学校跟了一个做RAG的项目,没写在简历上在自我介绍的时候提了一下)回忆了一下大概有这么些问题讲一下17年以来大模型的发展(我说我不是专职做这个的,我主要是后来才跟的去做rag的)那你说一下你对rag的理解你说你们做的是graphrag,那graphrag和其他的rag最主要的区别你认为是什么你在其中主要负责跑benchmark和evaluation,那有什么具体的评判指标吗?(说了两个比较常见的metric,其实这个问题一面的时候也问了我)平常怎么用AI学习的你认为怎么样能写好一个prompt4.手撕两道hot100,k个一组反转链表+三数之和,直接秒了(还好都是hot100,我听他说要手撕两道的时候心都凉了)5.杂问老家在哪base地有想法吗深圳和上海你更喜欢哪里(主要是我和他说我在深圳住)什么时候能入职+能实习多久你自己的优缺点是什么,有没有觉得自己需要提高的地方?反问:部门业务为什么美团现在这么爱问AI什么时候知道结果许愿一下oc,求求了美团,我什么都会做的,收留一下我吧
查看29道真题和解析
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务