Dataweave:根据一个记录集字段值删除重复的记录集
Data weave : Remove duplicate record set based on one record set field's value
我需要过滤关于 DSUltimateId 的响应。以下是我在测试时遇到的错误。
ERROR 2017-08-28 16:34:13,669 [[esb-domain].HTTPS_EIP_Listener_Configuration.worker.01] org.mule.exception.CatchMessagingExceptionStrategy:
********************************************************************************
Message : Exception while executing:
(ns0#DSUltimateId: $.ns01#stringValue ) when $.ns01#name == "IU_ROWID" distinctBy $ ,
^
Cannot coerce a :array to a :boolean
Type : com.mulesoft.weave.mule.exception.WeaveExecutionException
Code : MULE_ERROR--2
这是我的数据编织代码:我试图根据 "DSUltimateID" ** 过滤掉重复的记录,这可能会多次发生。
%dw 1.0
%output application/xml
%output application/xml inlineCloseOn = "empty"
%output application/xml skipNullOn="attributes"
%namespace ns0 http://www.example.org/IUGetMasterOrganizationRecordByIdOrName
%namespace ns01 urn:siperian.api
---
ns0#CustomerMasterDataDSUltimateResponse: {
ns0#DSUltimate: {
(payload.ns01#searchQueryReturn.*ns01#record.*ns01#field map
{
(ns0#ElectronicAddressTypeCd: $.ns01#stringValue ) when $.ns01#name == "EADDR_TYPE_CD" and ($.ns0#stringValue != ("" and null)),
(ns0#ElectronicAddressTxt: $.ns01#stringValue ) when $.ns01#name == "EADDR_TXT" and $.ns0#stringValue != ("" or null),
(ns0#DSUltimateId: $.ns01#stringValue ) when $.ns01#name == "IU_ROWID" distinctBy $ ,
(ns0#DSUltimateNm : $.ns01#stringValue) when $.ns01#name == "IU_NM",
(ns0#DSUltimateClassificationCd : $.ns01#stringValue) when $.ns01#name == "IU_CLASS_CODE",
(ns0#ApprovalStatusDSUltimateRequesterId : $.ns01#stringValue) when $.ns01#name == "APRV_STS_IU_RQSTR_ID",
(ns0#DSUltimateCreateReasonCd : $.ns01#stringValue) when $.ns01#name == "IU_CRE_RSN_CD",
(ns0#DSUltimateApprovalStatusCd : $.ns01#stringValue) when $.ns01#name == "IU_APRV_STS_CD",
(ns0#DSUltimateEffectiveStartDtm : $.ns01#dateValue) when $.ns01#name == "EFF_STRT_DTM",
(ns0#DSUltimateEffectiveEndDtm : $.ns01#dateValue !=null) when $.ns01#name == "EFF_END_DTM"
}
)
}
}
这是我的样本输入
您在映射时正在使用distinctBy
,但应在映射后使用。请参考answer here
%dw 1.0
%output application/xml inlineCloseOn = "empty" ,skipNullOn="attributes"
%namespace ns0 http://www.example.org/IUGetMasterOrganizationRecordByIdOrName
%namespace ns01 urn:siperian.api
---
{CustomerMasterDataDSUltimateResponse : {((payload.ns01#searchQueryReturn.*ns01#record map
DSUltimate: {
( $.*field map {
(ElectronicAddressTypeCd: $.ns01#stringValue ) when $.ns01#name == "EADDR_TYPE_CD" and $.ns01#stringValue != null and $.ns01#stringValue != "",
(ElectronicAddressTxt: $.ns01#stringValue ) when $.ns01#name == "EADDR_TXT" and $.ns01#stringValue != null and $.ns01#stringValue != "",
(DSUltimateId: trim $.ns01#stringValue) when $.ns01#name == "IU_ROWID",
(DSUltimateNm : $.ns01#stringValue) when $.ns01#name == "IU_NM",
(DSUltimateClassificationCd : $.ns01#stringValue) when $.ns01#name == "IU_CLASS_CODE",
(ApprovalStatusDSUltimateRequesterId : $.ns01#stringValue) when $.ns01#name == "APRV_STS_IU_RQSTR_ID",
(DSUltimateCreateReasonCd : $.ns01#stringValue) when $.ns01#name == "IU_CRE_RSN_CD",
(DSUltimateApprovalStatusCd : $.ns01#stringValue) when $.ns01#name == "IU_APRV_STS_CD",
(DSUltimateEffectiveStartDtm : $.ns01#dateValue) when $.ns01#name == "EFF_STRT_DTM",
(DSUltimateEffectiveEndDtm : $.ns01#dateValue) when $.ns01#name == "EFF_END_DTM" and $.ns01#stringValue != null and $.ns01#stringValue != ""
}
)
}
) distinctBy $.DSUltimate.DSUltimateId )}}
我需要过滤关于 DSUltimateId 的响应。以下是我在测试时遇到的错误。
ERROR 2017-08-28 16:34:13,669 [[esb-domain].HTTPS_EIP_Listener_Configuration.worker.01] org.mule.exception.CatchMessagingExceptionStrategy:
********************************************************************************
Message : Exception while executing:
(ns0#DSUltimateId: $.ns01#stringValue ) when $.ns01#name == "IU_ROWID" distinctBy $ ,
^
Cannot coerce a :array to a :boolean
Type : com.mulesoft.weave.mule.exception.WeaveExecutionException
Code : MULE_ERROR--2
这是我的数据编织代码:我试图根据 "DSUltimateID" ** 过滤掉重复的记录,这可能会多次发生。
%dw 1.0
%output application/xml
%output application/xml inlineCloseOn = "empty"
%output application/xml skipNullOn="attributes"
%namespace ns0 http://www.example.org/IUGetMasterOrganizationRecordByIdOrName
%namespace ns01 urn:siperian.api
---
ns0#CustomerMasterDataDSUltimateResponse: {
ns0#DSUltimate: {
(payload.ns01#searchQueryReturn.*ns01#record.*ns01#field map
{
(ns0#ElectronicAddressTypeCd: $.ns01#stringValue ) when $.ns01#name == "EADDR_TYPE_CD" and ($.ns0#stringValue != ("" and null)),
(ns0#ElectronicAddressTxt: $.ns01#stringValue ) when $.ns01#name == "EADDR_TXT" and $.ns0#stringValue != ("" or null),
(ns0#DSUltimateId: $.ns01#stringValue ) when $.ns01#name == "IU_ROWID" distinctBy $ ,
(ns0#DSUltimateNm : $.ns01#stringValue) when $.ns01#name == "IU_NM",
(ns0#DSUltimateClassificationCd : $.ns01#stringValue) when $.ns01#name == "IU_CLASS_CODE",
(ns0#ApprovalStatusDSUltimateRequesterId : $.ns01#stringValue) when $.ns01#name == "APRV_STS_IU_RQSTR_ID",
(ns0#DSUltimateCreateReasonCd : $.ns01#stringValue) when $.ns01#name == "IU_CRE_RSN_CD",
(ns0#DSUltimateApprovalStatusCd : $.ns01#stringValue) when $.ns01#name == "IU_APRV_STS_CD",
(ns0#DSUltimateEffectiveStartDtm : $.ns01#dateValue) when $.ns01#name == "EFF_STRT_DTM",
(ns0#DSUltimateEffectiveEndDtm : $.ns01#dateValue !=null) when $.ns01#name == "EFF_END_DTM"
}
)
}
}
这是我的样本输入
您在映射时正在使用distinctBy
,但应在映射后使用。请参考answer here
%dw 1.0
%output application/xml inlineCloseOn = "empty" ,skipNullOn="attributes"
%namespace ns0 http://www.example.org/IUGetMasterOrganizationRecordByIdOrName
%namespace ns01 urn:siperian.api
---
{CustomerMasterDataDSUltimateResponse : {((payload.ns01#searchQueryReturn.*ns01#record map
DSUltimate: {
( $.*field map {
(ElectronicAddressTypeCd: $.ns01#stringValue ) when $.ns01#name == "EADDR_TYPE_CD" and $.ns01#stringValue != null and $.ns01#stringValue != "",
(ElectronicAddressTxt: $.ns01#stringValue ) when $.ns01#name == "EADDR_TXT" and $.ns01#stringValue != null and $.ns01#stringValue != "",
(DSUltimateId: trim $.ns01#stringValue) when $.ns01#name == "IU_ROWID",
(DSUltimateNm : $.ns01#stringValue) when $.ns01#name == "IU_NM",
(DSUltimateClassificationCd : $.ns01#stringValue) when $.ns01#name == "IU_CLASS_CODE",
(ApprovalStatusDSUltimateRequesterId : $.ns01#stringValue) when $.ns01#name == "APRV_STS_IU_RQSTR_ID",
(DSUltimateCreateReasonCd : $.ns01#stringValue) when $.ns01#name == "IU_CRE_RSN_CD",
(DSUltimateApprovalStatusCd : $.ns01#stringValue) when $.ns01#name == "IU_APRV_STS_CD",
(DSUltimateEffectiveStartDtm : $.ns01#dateValue) when $.ns01#name == "EFF_STRT_DTM",
(DSUltimateEffectiveEndDtm : $.ns01#dateValue) when $.ns01#name == "EFF_END_DTM" and $.ns01#stringValue != null and $.ns01#stringValue != ""
}
)
}
) distinctBy $.DSUltimate.DSUltimateId )}}