开发者社区 > 大数据与机器学习 > 实时计算 Flink > 正文

Flink这样子的行转列的数据 我一条id为445的过来 但是其余的字段 不想变成空 有什么办法吗?

Flink这样子的行转列的数据 我一条id为445的过来 但是其余的字段 不想变成空 有什么办法吗 ?除了每个字段分开写入 ,STRING_AGG(distinct case when t3.id = 413 then t2.name end )
,STRING_AGG(distinct case when t3.id = 418 then t2.name end )
,STRING_AGG(distinct case when t3.id = 421 then t2.name end )
,STRING_AGG(distinct case when t3.id = 423 then t2.name end )
,STRING_AGG(distinct case when t3.id = 425 then t2.name end )
,STRING_AGG(distinct case when t3.id = 428 then t2.name end )
,STRING_AGG(distinct case when t3.id = 438 then t2.name end )
,STRING_AGG(distinct case when t3.id = 440 then t2.name end )
,STRING_AGG(distinct case when t3.id = 443 then t2.name end )
,STRING_AGG(distinct case when t3.id = 445 then t2.name end )

展开
收起
cuicuicuic 2024-01-04 14:31:46 33 0
2 条回答
写回答
取消 提交回答
  • 可以使用COALESCE函数来处理这个问题。COALESCE函数会返回第一个非空值,如果所有值都为空,则返回NULL。这样,当某个字段的值为空时,COALESCE函数会返回其他字段的值,而不是NULL。

    修改后的代码如下:

    ,STRING_AGG(COALESCE(case when t3.id = 413 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 418 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 421 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 423 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 425 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 428 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 438 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 440 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 443 then t2.name end, ''))
    ,STRING_AGG(COALESCE(case when t3.id = 445 then t2.name end, ''))
    

    这样,当某个字段的值为空时,COALESCE函数会返回空字符串,而不是NULL。

    2024-01-05 14:51:17
    赞同 展开评论 打赏
  • 面对过去,不要迷离;面对未来,不必彷徨;活在今天,你只要把自己完全展示给别人看。

    你可以使用coalesce函数将空值替换为其他值,例如空字符串。这样,当某个字段没有匹配到时,它将被替换为空字符串,而不是NULL。以下是修改后的代码:

    ,STRING_AGG(distinct coalesce(case when t3.id = 413 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 418 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 421 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 423 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 425 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 428 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 438 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 440 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 443 then t2.name end, ''))
    ,STRING_AGG(distinct coalesce(case when t3.id = 445 then t2.name end, ''))
    

    这样,当某个字段没有匹配到时,它将被替换为空字符串,而不是NULL。

    2024-01-04 15:55:25
    赞同 展开评论 打赏

实时计算Flink版是阿里云提供的全托管Serverless Flink云服务,基于 Apache Flink 构建的企业级、高性能实时大数据处理系统。提供全托管版 Flink 集群和引擎,提高作业开发运维效率。

相关产品

  • 实时计算 Flink版
  • 相关电子书

    更多
    Flink CDC Meetup PPT - 龚中强 立即下载
    Flink CDC Meetup PPT - 王赫 立即下载
    Flink CDC Meetup PPT - 覃立辉 立即下载