【发布时间】:2021-12-23 04:11:18
【问题描述】:
我正在尝试使用 Dataweave 2.0 转换 .CSV 的结构
这是我的输入 csv 示例:
gaID,gender,age,city,state
GA1.3.332,male,20-30,,
GA1.3.1041d,female,30-40,Sao Paulo,Sao Paulo
GA1.3.1041d,,,Sao Paulo
我需要创建这个输出:
GA1.3.332^gender:male;age:20-30
GA1.3.1041d^gender:female;age:30-40;city:Sao Paulo;state:Sao Paulo
GA1.3.1041d^state:Sao Paulo
请注意,当输入属性为 null 时,它们不应出现在输出中,这就是我遇到的问题。
到目前为止,我有这段代码,但不完全符合我的需要,因为它编写了所有属性,即使是否为空。
%dw 2.0
output application/csv header=false, separator=';'
---
payload map {
c1: $.gaID ++ "^" ++ "gender:" ++ $.gender,
c2: "age:" ++ $.age,
c3: "city:" ++ $.city,
c4: "state:" ++ $.state,
c5: "maritalStatus:" ++ $.martitalStatus,
c6: "householdIncome:" ++ $.householdIncome,
c7: "bradSegCustomer:" ++ $.bradSegCustomer,
c8: "bradCustomer:" ++ $.bradCustomer,
c9: "BankClientSegment:" ++ $.BankClientSegment,
c10: "main_account:" ++ $.main_account,
c11: "occupation:" ++ $.occupation,
c12: "presenceofChildren:" ++ $.presenceofChildren,
}
我的代码输出:
GA1.3.332^gender:male;age:20-30;city:;state:
GA1.3.1041d^gender:female;age:30-40;city:Sao Paulo;state:Sao Paulo
【问题讨论】: