2017-05-29 75 views
3

我有以下數據的csv文件檢查的DateField刪除重複記錄:Mulesoft:使用dataweave

Id,Name,Type,date 
1,name1,employee,25/04/2017 
2,name2,contrator,26/04/2017 
3,name3,employee,25/04/2017 
4,name4,contrator,26/04/2017 
5,name5,employee,24/04/2017 
6,name6,contrator,24/04/2017 
7,name7,employee,25/04/2017 
8,name8,contrator,24/04/2017 
9,name9,employee,24/04/2017 
10,name10,contrator,26/04/2017 
6,name6,employee,27/04/2017 
11,name11,employee,27/04/2017 
12,name12,contrator,27/04/2017 

如果它有兩排相同的ID號。應通過檢查最新日期來刪除其中一行。具有較舊日期的行應該被刪除。 例如,上面的輸入有兩行數據,ID爲6,應刪除日期爲24/04/2017的行。輸出應該是這樣的

Id,Name,Type,date 
1,name1,employee,25/04/2017 
2,name2,contrator,26/04/2017 
3,name3,employee,25/04/2017 
4,name4,contrator,26/04/2017 
5,name5,employee,24/04/2017 
6,name6,employee,27/04/2017 
7,name7,employee,25/04/2017 
8,name8,contrator,24/04/2017 
9,name9,employee,24/04/2017 
10,name10,contrator,26/04/2017 
11,name11,employee,27/04/2017 
12,name12,contrator,27/04/2017 

我需要使用Dataweave來實現這一點。請給我一個解決方案或建議

回答

4

這裏是你正在尋找的dataweave:

%dw 1.0 
%output application/csv 
%var toDate = (str) -> str as :date { format: "dd/MM/yyyy" } 
%var maxDate = (a, b) -> a when toDate(a.date) > toDate(b.date) otherwise b 
--- 
payload groupBy $.Id 
    pluck $ map ($ reduce ((val, acc) -> maxDate(val, acc))) 

enter image description here

+0

非常感謝,它的工作。 –

+0

@Prudhvi歡迎您 – Yevgeniy