jolt - 使用 Jolt 变换聚合某些数组元素
问题描述
我有以下数据,我正在尝试 Jolt Transform
[
{
"header": {
"messageId": "cpr_20200220090757_sbdld9sp054_20374_1_000000001",
"businessId": "Collateral Reuse",
"batchId": "cpr_20200220090757_sbdld9sp054_20374_1",
"sourceSystem": "cpr",
"secondarySourceSystem": null,
"sourceSystemCreationTimestamp": "2020-02-20T14:08:00.769Z",
"sentBy": "Collateral Reuse",
"sentTo": "SA",
"messageType": "NativeMessage",
"schemaVersion": "1.9",
"processing": "EOD"
},
"content": {
"IM_SubmitterID": "TESTBANK01",
"IM_ParticipantID": "TESTBANK01",
"LN_EventDate": 1582174800000,
"IM_AsOfDateTime": 1582207677133,
"IM_RepCpCodeType": "LEI",
"CP_RepCp": "D3I9ZG2KFGXZ61BMYR86",
"CP_EntResponsibleForRep": "",
"CO_TypeOfCollComponent": "SECU",
"CO_IdOfASecUsedAsColl": "IT0003535157",
"IM_CollAssetIdentifierTypes": "",
"IM_CollAssetIdentifierCodes": "",
"IM_CollSecDescr": "",
"RU_ValueOfReusedColl": "",
"RU_EstimatedReuseOfColl": 0,
"RU_ReusedCollCcy": "EUR",
"CO_ActionType": "Normal"
}
},
{
"header": {
"messageId": "cpr_20200220090757_sbdld9sp054_20374_1_000000003",
"businessId": "Collateral Reuse",
"batchId": "cpr_20200220090757_sbdld9sp054_20374_1",
"sourceSystem": "cpr",
"secondarySourceSystem": null,
"sourceSystemCreationTimestamp": "2020-02-20T14:08:00.901Z",
"sentBy": "Collateral Reuse",
"sentTo": "SA",
"messageType": "NativeMessage",
"schemaVersion": "1.9",
"processing": "EOD"
},
"content": {
"IM_SubmitterID": "TESTBANK01",
"IM_ParticipantID": "TESTBANK01",
"LN_EventDate": 1582174800000,
"IM_AsOfDateTime": 1582207677134,
"IM_RepCpCodeType": "LEI",
"CP_RepCp": "D3I9ZG2KFGXZ61BMYR86",
"CP_EntResponsibleForRep": "",
"CO_TypeOfCollComponent": "SECU",
"CO_IdOfASecUsedAsColl": "DE0001102408",
"IM_CollAssetIdentifierTypes": "",
"IM_CollAssetIdentifierCodes": "",
"IM_CollSecDescr": "",
"RU_ValueOfReusedColl": "",
"RU_EstimatedReuseOfColl": 0,
"RU_ReusedCollCcy": "EUR",
"CO_ActionType": "Normal"
}
},
{
"header": {
"messageId": "cpr_20200220090757_sbdld9sp054_20374_1_000000002",
"businessId": "Collateral Reuse",
"batchId": "cpr_20200220090757_sbdld9sp054_20374_1",
"sourceSystem": "cpr",
"secondarySourceSystem": null,
"sourceSystemCreationTimestamp": "2020-02-20T14:08:00.897Z",
"sentBy": "Collateral Reuse",
"sentTo": "SA",
"messageType": "NativeMessage",
"schemaVersion": "1.9",
"processing": "EOD"
},
"content": {
"IM_SubmitterID": "TESTBANK01",
"IM_ParticipantID": "TESTBANK01",
"LN_EventDate": 1582174800000,
"IM_AsOfDateTime": 1582207677134,
"IM_RepCpCodeType": "LEI",
"CP_RepCp": "D3I9ZG2KFGXZ61BMYR86",
"CP_EntResponsibleForRep": "",
"CO_TypeOfCollComponent": "SECU",
"CO_IdOfASecUsedAsColl": "ES00000123U9",
"IM_CollAssetIdentifierTypes": "",
"IM_CollAssetIdentifierCodes": "",
"IM_CollSecDescr": "",
"RU_ValueOfReusedColl": "",
"RU_EstimatedReuseOfColl": 0,
"RU_ReusedCollCcy": "EUR",
"CO_ActionType": "Normal"
}
},
{
"header": {
"messageId": "cpr_20200220090757_sbdld9sp054_20374_1_000000006",
"businessId": "Collateral Reuse",
"batchId": "cpr_20200220090757_sbdld9sp054_20374_1",
"sourceSystem": "cpr",
"secondarySourceSystem": null,
"sourceSystemCreationTimestamp": "2020-02-20T14:08:00.909Z",
"sentBy": "Collateral Reuse",
"sentTo": "SA",
"messageType": "NativeMessage",
"schemaVersion": "1.9",
"processing": "EOD"
},
"content": {
"IM_SubmitterID": "TESTBANK01",
"IM_ParticipantID": "TESTBANK01",
"LN_EventDate": 1582174800000,
"IM_AsOfDateTime": 1582207677134,
"IM_RepCpCodeType": "LEI",
"CP_RepCp": "D3I9ZG2KFGXZ61BMYR86",
"CP_EntResponsibleForRep": "",
"CO_TypeOfCollComponent": "SECU",
"CO_IdOfASecUsedAsColl": "DE0001104750",
"IM_CollAssetIdentifierTypes": "",
"IM_CollAssetIdentifierCodes": "",
"IM_CollSecDescr": "",
"RU_ValueOfReusedColl": "",
"RU_EstimatedReuseOfColl": 0,
"RU_ReusedCollCcy": "EUR",
"CO_ActionType": "Normal"
}
},
{
"header": {
"messageId": "cpr_20200220090757_sbdld9sp054_20374_1_000000005",
"businessId": "Collateral Reuse",
"batchId": "cpr_20200220090757_sbdld9sp054_20374_1",
"sourceSystem": "cpr",
"secondarySourceSystem": null,
"sourceSystemCreationTimestamp": "2020-02-20T14:08:00.907Z",
"sentBy": "Collateral Reuse",
"sentTo": "SA",
"messageType": "NativeMessage",
"schemaVersion": "1.9",
"processing": "EOD"
},
"content": {
"IM_SubmitterID": "TESTBANK01",
"IM_ParticipantID": "TESTBANK01",
"LN_EventDate": 1582174800000,
"IM_AsOfDateTime": 1582207677134,
"IM_RepCpCodeType": "LEI",
"CP_RepCp": "D3I9ZG2KFGXZ61BMYR86",
"CP_EntResponsibleForRep": "",
"CO_TypeOfCollComponent": "SECU",
"CO_IdOfASecUsedAsColl": "US45818WCM64",
"IM_CollAssetIdentifierTypes": "",
"IM_CollAssetIdentifierCodes": "",
"IM_CollSecDescr": "",
"RU_ValueOfReusedColl": "",
"RU_EstimatedReuseOfColl": 0,
"RU_ReusedCollCcy": "EUR",
"CO_ActionType": "Normal"
}
},
{
"header": {
"messageId": "cpr_20200220090757_sbdld9sp054_20374_1_000000004",
"businessId": "Collateral Reuse",
"batchId": "cpr_20200220090757_sbdld9sp054_20374_1",
"sourceSystem": "cpr",
"secondarySourceSystem": null,
"sourceSystemCreationTimestamp": "2020-02-20T14:08:00.904Z",
"sentBy": "Collateral Reuse",
"sentTo": "SA",
"messageType": "NativeMessage",
"schemaVersion": "1.9",
"processing": "EOD"
},
"content": {
"IM_SubmitterID": "TESTBANK01",
"IM_ParticipantID": "TESTBANK01",
"LN_EventDate": 1582174800000,
"IM_AsOfDateTime": 1582207677134,
"IM_RepCpCodeType": "LEI",
"CP_RepCp": "D3I9ZG2KFGXZ61BMYR86",
"CP_EntResponsibleForRep": "",
"CO_TypeOfCollComponent": "SECU",
"CO_IdOfASecUsedAsColl": "NL0010060257",
"IM_CollAssetIdentifierTypes": "",
"IM_CollAssetIdentifierCodes": "",
"IM_CollSecDescr": "",
"RU_ValueOfReusedColl": "",
"RU_EstimatedReuseOfColl": 0,
"RU_ReusedCollCcy": "EUR",
"CO_ActionType": "Normal"
}
}
]
这是我目前写的 Jolt Specs
[
{
"operation": "shift",
"spec": {
"*": {
"content": {
"CO_TypeOfCollComponent": "&",
"CO_IdOfASecUsedAsColl": "&",
"IM_CollAssetIdentifierTypes": "&",
"IM_CollAssetIdentifierCodes": "&",
"RU_ValueOfReusedColl": "&",
"RU_EstimatedReuseOfColl": "&",
"RU_ReusedCollCcy": "&",
"IM_CollSecDescr": "&"
}
},
"0": {
"content": {
"IM_SubmitterID": "&",
"IM_ParticipantID": "&",
"CO_ActionType": "&",
"CP_EntResponsibleForRep": "&",
"CP_RepCp": "&",
"IM_AsOfDateTime": "&",
"IM_RepCpCodeType": "&",
"LN_EventDate": "&"
}
}
}
}
]
这给了我结果
{
"IM_SubmitterID" : "TESTBANK01",
"IM_ParticipantID" : "TESTBANK01",
"CO_ActionType" : "Normal",
"CP_EntResponsibleForRep" : "",
"CP_RepCp" : "D3I9ZG2KFGXZ61BMYR86",
"IM_AsOfDateTime" : 1582207677133,
"IM_RepCpCodeType" : "LEI",
"LN_EventDate" : 1582174800000,
"CO_TypeOfCollComponent" : [ "SECU", "SECU", "SECU", "SECU", "SECU" ],
"CO_IdOfASecUsedAsColl" : [ "DE0001102408", "ES00000123U9", "DE0001104750", "US45818WCM64", "NL0010060257" ],
"IM_CollAssetIdentifierTypes" : [ "", "", "", "", "" ],
"IM_CollAssetIdentifierCodes" : [ "", "", "", "", "" ],
"RU_ValueOfReusedColl" : [ "", "", "", "", "" ],
"RU_EstimatedReuseOfColl" : [ 0, 0, 0, 0, 0 ],
"RU_ReusedCollCcy" : [ "EUR", "EUR", "EUR", "EUR", "EUR" ],
"IM_CollSecDescr" : [ "", "", "", "", "" ]
}
这几乎是我需要的输出。但是,如果您注意到最终输出中缺少第一个数组中的值。For example, "CO_IdOfASecUsedAsColl": "IT0003535157" is missing from the output
(we only have "CO_IdOfASecUsedAsColl" : [ "DE0001102408", "ES00000123U9", "DE0001104750", "US45818WCM64", "NL0010060257" ])`.
有人可以帮我修改我的 Jolt Specs 以达到预期的结果吗
解决方案
我设法使用以下规格解决了它
[
{
"operation": "shift",
"spec": {
"*": {
"content": {
"CO_TypeOfCollComponent": "&",
"CO_IdOfASecUsedAsColl": "&",
"IM_CollAssetIdentifierTypes": "&",
"IM_CollAssetIdentifierCodes": "&",
"RU_ValueOfReusedColl": "&",
"RU_EstimatedReuseOfColl": "&",
"RU_ReusedCollCcy": "&",
"IM_CollSecDescr": "&"
}
},
"0": {
"content": {
"IM_SubmitterID": "&",
"IM_ParticipantID": "&",
"CO_ActionType": "&",
"CP_EntResponsibleForRep": "&",
"CP_RepCp": "&",
"IM_AsOfDateTime": "&",
"IM_RepCpCodeType": "&",
"LN_EventDate": "&",
"CO_TypeOfCollComponent": "&",
"CO_IdOfASecUsedAsColl": "&",
"IM_CollAssetIdentifierTypes": "&",
"IM_CollAssetIdentifierCodes": "&",
"RU_ValueOfReusedColl": "&",
"RU_EstimatedReuseOfColl": "&",
"RU_ReusedCollCcy": "&",
"IM_CollSecDescr": "&"
}
}
}
}
]
如果有人想出更优雅的解决方案,请告诉我
推荐阅读
- c++ - 基于值从向量中移除元素的时间复杂度
- javascript - 如何使用javascript根据输入文本检测语言代码?
- mongodb - 如何在 Spring MongoDB 中使用 $dateFromString?
- python - Django:如何使用外键字段集编辑页面(无法编辑和发布到模型)
- python - 我的 9 行 Python 代码正在使用我的 CPU 的 100%
- genetic-algorithm - 一步大小的不相关突变
- tensorflow - 在 tf.layers.conv2d 中将 kernel_regularizer 设置为 l2_regularizer 是什么意思?
- java - Webservice 客户端在 weblogic 12.2.1.2.0 (12cR2) 上显示错误 - soapfault
- amazon-web-services - EC2 实例的 Amazon Cloud Front 返回 403 Access Denied
- python - 3D坐标系之间的回归旋转+平移