[英]Need help in Dataweave Transformation
I have the oracle database table CASH which contains below columns: 我有oracle数据库表CASH ,其中包含以下各列:
REGISTER DATE CASE BAG TYPE
1234 24-SEP-18 1123 112 A
1234 24-SEP-18 1124 113 S
1234 24-SEP-18 1123 116 S
1234 24-SEP-18 1124 117 A
7895 24-SEP-18 2568 119 A
7895 24-SEP-18 2568 118 S
Where the register number are the cash registers which can have multiple CASE linked to it and each CASE can have more than one BAG and Type attached to it. 其中收银机号码是可以链接多个CASE的收银机,每个CASE可以附加一个以上的BAG和Type。 I want to transform it into below XML in Dataweave: 我想将其转换为Dataweave中的以下XML:
<ROOT>
<REGISTERS>
<REGISTER>1234</REGISTER>
<DATE>24-SEP-2018</DATE>
<DETAILS>
<BAG>1123</BAG>
<DETAIl>
<BAG>112</BAG>
<TYPE>A</TYPE>
</DETAIl>
<DETAIl>
<BAG>116</BAG>
<TYPE>S</TYPE>
</DETAIl>
</DETAILS>
<DETAILS>
<BAG>1124</BAG>
<DETAIl>
<BAG>113</BAG>
<TYPE>S</TYPE>
</DETAIl>
<DETAIl>
<BAG>117</BAG>
<TYPE>A</TYPE>
</DETAIl>
</DETAILS>
</REGISTERS>
<REGISTERS>
<REGISTER>7895</REGISTER>
<DATE>24-SEP-2018</DATE>
<DETAILS>
<BAG>2568</BAG>
<DETAIl>
<BAG>119</BAG>
<TYPE>A</TYPE>
</DETAIl>
<DETAIl>
<BAG>118</BAG>
<TYPE>S</TYPE>
</DETAIl>
</DETAILS>
</REGISTERS>
</ROOT>
Could you please give some pointers how can I achieve this in dataweave. 您能给我一些指示,如何在dataweave中实现这一点。
Thanks !! 谢谢 !!
Assuming you've already read the data from the database, you can use the following: 假设您已经从数据库中读取了数据,则可以使用以下命令:
%dw 1.0
%output application/xml
---
ROOT: payload groupBy (($.REGISTER as :string) ++ ($.DATE as :string)) mapObject ((entries, number) -> {
REGISTERS: {
REGISTER: entries[0].REGISTER,
DATE: entries[0].DATE as :string {format: "yyyy-MM-dd"},
(entries groupBy $.CASE map DETAILS: {
CASE: $.CASE[0],
($ map DETAIL: {
BAG: $.BAG,
TYPE: $.TYPE
})
})
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.