You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Data Factory数据流中空值检查与活跃重复行验证咨询

Azure Data Factory 数据流实现方案:检查非活跃行的活跃重复项

现有源数据

idcountycityadresspricedatefromdatetoiscurrent
3PTLisbonjack100002012-1-12022-1-100
3PTLisbonjack100002012-8-1null1
4ESMadridola str230002022-3-12022-3-100
4ESMadridola str230002022-10-12023-1-010

方案一:聚合+关联实现(匹配你的尝试方向)

步骤1:拆分数据集

  • 添加Filter转换,过滤出活跃行:iscurrent == 1
  • 添加另一个Filter转换,过滤出非活跃行:iscurrent == 0

步骤2:聚合活跃行标记重复组

对活跃行添加Aggregate转换:

  • 分组键选择:id, county, city, adress, price(必须覆盖前五列,确保匹配完全相同的记录)
  • 新增聚合列has_active,表达式写:1(只要分组存在,就标记为1)

步骤3:关联非活跃行与聚合结果

添加Join转换,将非活跃行作为左表,活跃聚合结果作为右表,连接条件:

id == id && county == county && city == city && adress == adress && price == price

步骤4:生成havenulls列

添加Derived Column转换,创建havenulls列,表达式:

iff(isNull(has_active), 0, 1)

最后过滤掉不需要的列,即可得到目标输出。


方案二:Window转换一键实现

无需拆分数据集,直接用Window转换完成:

  1. 添加Window转换,分区键设置为id, county, city, adress, price
  2. 新增窗口列havenulls,表达式:
max(iff(iscurrent == 1, 1, 0)) over (partition by id, county, city, adress, price)
  1. 添加Filter转换,过滤出iscurrent == 0的行,即可得到目标结果。

方案三:源SQL直接预处理(性能更优)

如果源是SQL数据库,直接在ADF源的查询编辑器中写SQL语句,提前完成逻辑:

SELECT 
    t1.id, t1.county, t1.city, t1.adress, t1.price, t1.datefrom,
    CASE 
        WHEN EXISTS (
            SELECT 1 FROM your_table t2
            WHERE t2.id = t1.id 
              AND t2.county = t1.county 
              AND t2.city = t1.city 
              AND t2.adress = t1.adress 
              AND t2.price = t1.price 
              AND t2.iscurrent = 1
        ) THEN 1 
        ELSE 0 
    END AS havenulls
FROM your_table t1
WHERE t1.iscurrent = 0

这种方式无需在数据流中做复杂转换,执行效率更高。


内容的提问来源于stack exchange,提问作者Nunotrt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 19:47:53