Использование преобразования Джолта для агрегирования определенных элементов массива - PullRequest
0 голосов
/ 24 февраля 2020

У меня есть следующие данные, которые я пытаюсь выполнить 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, которые я написал до сих пор

[
  {
    "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 для достижения желаемого результата

1 Ответ

0 голосов
/ 24 февраля 2020

Мне удалось решить эту проблему, используя спецификации ниже

[
  {
    "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": "&"
        }
      }
    }
    }
]

Дайте мне знать, если кто-нибудь придумает более элегантное решение

...