替换 Hive table 中的数字列表

Replace a list of numbers from Hive table

我有一个配置单元 table,其中的数据是这样的 -

其中 key 只是一个唯一的列,ph1、ph2.. 是 phone 个数字。 Objective 是用空格代替流行的 phone 数字。 我已经有一个 table,其中包含流行的 phone 号码。 为此,例如让我们假设 100 和 50 是流行的 phone 数字。 因此输出应该是这样的 -

我试过这个查询,但配置单元不支持这个 -

        select 
        case when ph1 in (select phone_no from popular_phone_number)
        then "" end as ph1_masked,
        case when ph2 in (select phone_no from popular_phone_number)
        then "" end as ph2_masked
        from base_table;

您需要使用 left join 和一些 case 逻辑:

select bt.key,
       (case when ppn1.phone_no is not null then null else ph1 end) as ph1,
       (case when ppn2.phone_no is not null then null else ph2 end) as ph2,
       (case when ppn3.phone_no is not null then null else ph3 end) as ph3,
       (case when ppn4.phone_no is not null then null else ph4 end) as ph4
from base_table bt left join
     popular_phone_number ppn1
     on ppn1.phone_no = bt.ph1 left join
     popular_phone_number ppn2
     on ppn2.phone_no = bt.ph2 left join
     popular_phone_number ppn3
     on ppn3.phone_no = bt.ph3 left join
     popular_phone_number ppn4
     on ppn4.phone_no = bt.ph4;