【发布时间】:2021-03-15 12:49:27
【问题描述】:
我有一个大文件 (csv),其中的数据看起来像
"Data Definition Catalog"|"Accounting Entry **;** sda Message Id"|"dsds"|"6/23/2016"|"Pdas"|"Paytrtr"|"faasd"|"Betalen & Sparen"|"CNA"|"8/1/2016"|"Data Attribute"|"Bok"|"Unsdfdsf"|""|"fdsfdfdsf"|"fdsfdsfsdggrrg"|""|"**hello semicolon ; kskdsldss.**"|"dsasa"|"Payment Engine"|"A35"|""|"Approved"|"No"|"No"|"N"|"N"|"N"|"N"|"N"|"ffrr"|""|"8/1/2016"|""|""|""|""|""|""|""|""|""
我正在使用转换消息组件将此列表转换为 csv 格式,但我收到一个错误,即 null 不能强制转换为字符串。 进一步查看输入我觉得; (以粗体标记的分号)正在产生问题并使所有进一步的元组为空。我有点困惑。谁能告诉我如何解决这个问题?
在提交日期转换消息失败(null 不能被强制转换为字符串),因为在分号后一切都变为 null/空我猜来自输入
%dw 1.0
%output application/csv separator=",",escape=";", quoteValues=true
%function getBoolean(aString) (
aString match {
:null -> null,
s is :string -> ((s contains "Yes") or (s contains "Y")),
default -> null
}
)
%function convertToBoolean(s) (
s match {
"Yes" -> "true",
"No" -> "false",
"Y" -> "true",
"N" -> "false"
}
)
---
payload map ((payload01 , indexOfPayload01) -> {
Name: payload01.Attribute_Name,
TechnicalName: payload01.Technical_Name,
SubmissionDate: (payload01.Submission_Date as :date{format:"M/d/yyyy"} as :string{format:"yyyy-MM-dd"}) when (payload01.Submission_Date as :string) contains "/" otherwise (payload01.Submission_Date as :date{format:"d-M-yyyy"} as :string{format:"yyyy-MM-dd"}),
DefinitionOwner: payload01.Definition_Owner,
DataSteward: payload01.Data_Steward,
SubmittedBy: payload01.Submitted_By,
SourceHub: payload01.Source_Hub,
SourceApplicationEntity: payload01.Source_Application_Entity,
PublicationDate: (payload01.Publication_Date as :date{format:"M/d/yyyy"} as :string{format:"yyyy-MM-dd"}) when (payload01.Publication_Date as :string) contains "/" otherwise (payload01.Publication_Date as :date{format:"d-M-yyyy"} as :string{format:"yyyy-MM-dd"}),
ObjectType: payload01.Object_Type,
Nameinnativelanguage: payload01.Name_in_native_language,
Descriptioninnativelanguage: payload01.Description_in_native_language,
BusinessRuleinnativelanguage: payload01.Business_Rule_in_native_language,
Notesinnativelanguage: payload01.Notes_in_native_language,
Description: payload01.Description,
BusinessRule: payload01.Business_Rule,
Notes: payload01.Notes,
PrimaryDomain: payload01.Primary_Domain,
Subdomain: payload01.Subdomain,
LogicalDataType: payload01.Technical_Data_Type,
ValueRange: payload01.Value_Range,
Status: "Legacy" when payload01.Status contains "Legacy" otherwise payload01.Status,
IsCritical: getBoolean(payload01.Is_Critical) as :string as :boolean,
IsPrivacySensitive: getBoolean(payload01.Is_Privacy_Sensitive) as :string as :boolean,
IndirectlyIdentifyingPersonalInformation: getBoolean(payload01.Indirectly_Identifying_Personal_Information) as :string as :boolean,
DirectlyIdentifyingPersonalInformation: getBoolean(payload01.Directly_Identifying_Personal_Information) as :string as :boolean,
SensitivePersonalInformation: getBoolean(payload01.Sensitive_Personal_Information) as :string as :boolean,
SensitiveFinancialInformation: getBoolean(payload01.Sensitive_Financial_Information) as :string as :boolean,
SensitiveSecurityInformation: getBoolean(payload01.Sensitive_Security_Information) as :string as :boolean,
PrivacyStatus: payload01.Privacy_Status,
PrivacyComment: payload01.Privacy_Comment,
LastUpdateDate: (payload01.Last_Update_Date as :date{format:"M/d/yyyy"} as :string{format:"yyyy-MM-dd"}) when (payload01.Last_Update_Date as :string) contains "/" otherwise (null when (payload01.Last_Update_Date as :string) == "" otherwise payload01.Last_Update_Date as :date{format:"d-M-yyyy"} as :string{format:"yyyy-MM-dd"}),
ReviewRemarks : payload01.Review_Remarks,
AssetType:p('asset.dataAttributes.type.id'),
Domain: p('domain.name'),
Community:p('community.name'),
DataModel:payload01.Name,
PhysicalcolumnName: payload01.Technical_Name,
DomainColumn:p('domain.name.PhysicalDataDictionary'),
CommunityColumn:"DIH",
DeepLink:p('powerdesigner.deeplink'),
ExampleValue:payload01.Example_Value
})
【问题讨论】: