Azure Data Factory数据流中空值检查与活跃重复行验证咨询
Azure Data Factory 数据流实现方案:检查非活跃行的活跃重复项
现有源数据
| id | county | city | adress | price | datefrom | dateto | iscurrent |
|---|---|---|---|---|---|---|---|
| 3 | PT | Lisbon | jack | 10000 | 2012-1-1 | 2022-1-10 | 0 |
| 3 | PT | Lisbon | jack | 10000 | 2012-8-1 | null | 1 |
| 4 | ES | Madrid | ola str | 23000 | 2022-3-1 | 2022-3-10 | 0 |
| 4 | ES | Madrid | ola str | 23000 | 2022-10-1 | 2023-1-01 | 0 |
方案一:聚合+关联实现(匹配你的尝试方向)
步骤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转换完成:
- 添加Window转换,分区键设置为
id, county, city, adress, price - 新增窗口列
havenulls,表达式:
max(iff(iscurrent == 1, 1, 0)) over (partition by id, county, city, adress, price)
- 添加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
相关产品推荐
相关产品推荐

