Member since
04-23-2021
2
Posts
0
Kudos Received
0
Solutions
09-06-2022
01:33 PM
I am trying to understand simple jolt transformations My original json { "name" : "john", "Address2" : "123 Street 1", "Address1" : "Apt 101", "custId" : "ZY-1234", "zip" : "67834" } I would like to change the sequence of columns and get comma separated values with default tags added to it, like below The last column value should be defaulted to current datetime { "Rows" : [ { "values" : [ "ZY-1234" , "john" , "123 Street 1","Apt 101","67834","2022-09-01 10:10:09" ] } ], "operationType" : "Insert", "Source" : "Dev" } here is the Spec I got to [ { "operation": "default", "spec": { "ChangedBy": "NIFI", "ChangedOn": "${now()}" } }, { "operation": "shift", "spec": { "*": { "@": "Rows[#1].Value" } } }, { "operation": "default", "spec": { "*": { "*": "&" }, "operationType": "Insert", "Source": "Dev" } } ] The Result of this { "Rows" : [ { "Values" : [ "john", "123 Street 1", "Apt 101", "ZY-1234", "67834", "NIFI", "${now()}" ] } ], "operationType" : "Insert", "Source" : "Dev" } Issues : 1. How to change the column sequence in Values array 2. How to get current datetime
... View more
Labels:
- Labels:
-
Apache NiFi
08-30-2022
08:44 AM
I am trying to create a jolt transformation in NIFI , I have a JSON message with header, detail and line details as an array with line detail object. Can we Transform Header/Detail JSON into Detail JSON One separate JSON for each Detail with New Tag having flattened array of Detail Attribute values of "TRADETYP" and "TRANSPORT_CODE" "TRADETYP_CODE_ALL" : [ "GR-BARGE", "EXP-AR", "CR-LCL" ] Sample JSON { "TRADE_HEADER": { "IDOC": { "EDI_DC40": { "DOCNUM": "0000012890", "TABNAME": "EDI_DC40", "CREDT": "20220126", "CRETM": "041400" }, "TRADEDETAIL": { "SEGMENT": "1", "TRADE_NUM": "NA-152", "PACKAGE_GUID": "ASDER3785$%SDF", "TRADEDETAILLINE": [ { "DOC_QTY": "19956.930", "ACT_NOM_CONSUMED_QTY": "0.000", "REM_MAX_QTY_TE": "0.000", "XMDOCNR": "5025087976", "DOCITM": "0000012001", "COMMODITY": "RB", "TRADING_COMPANY": "3862", "PERIODICITY": "PRAGUE", "POSTING_DATE": "20211117", "MARKET": "CME", "TRADETYP": "GR", "MAX_DOC_QTY": "19956.930", "TRANSPORT_CODE": "BARGE", "DOCNR": "4700253115" }, { "DOC_QTY": "12256.230", "ACT_NOM_CONSUMED_QTY": "0.000", "REM_MAX_QTY_TE": "0.000", "XMDOCNR": "5025092776", "DOCITM": "0000014021", "COMMODITY": "RB", "TRADING_COMPANY": "3862", "PERIODICITY": "PRAGUE", "POSTING_DATE": "20211117", "MARKET": "CME", "TRADETYP": "EXP", "MAX_DOC_QTY": "12256.230", "TRANSPORT_CODE": "ES", "DOCNR": "4700234521" }, { "DOC_QTY": "14256.210", "ACT_NOM_CONSUMED_QTY": "0.000", "REM_MAX_QTY_TE": "0.000", "XMDOCNR": "5025023562", "DOCITM": "0000012041", "COMMODITY": "RB", "TRADING_COMPANY": "3862", "PERIODICITY": "PRAGUE", "POSTING_DATE": "20211117", "MARKET": "CME", "TRADETYP": "SE", "MAX_DOC_QTY": "14256.230", "TRANSPORT_CODE": "AR", "DOCNR": "4700278453" } ], "PACKAGE_SEQ_NBR": "1", "PACKAGE_SEQ_MAX_NBR": "1" } } } } DESIRED JSON [{ "TRADERECORD": { "DOC_QTY": "19956.930", "ACT_NOM_CONSUMED_QTY": "0.000", "REM_MAX_QTY_TE": "0.000", "XMDOCNR": "5025087976", "DOCITM": "0000012001", "COMMODITY": "RB", "TRADING_COMPANY": "3862", "PERIODICITY": "PRAGUE", "POSTING_DATE": "20211117", "MARKET": "CME", "TRADETYP": "GR", "MAX_DOC_QTY": "19956.930", "TRANSPORT_CODE": "BARGE", "DOCNR": "4700253115", "SEGMENTH": "1", "TRADE_NUM": "NA-152", "PACKAGE_GUID": "ASDER3785$%SDF", "TRADETYP_TCODE_ALL": ["GR-BARGE", "EXP-AR", "CR-LCL"] } }, { "TRADERECORD": { "DOC_QTY": "12256.230", "ACT_NOM_CONSUMED_QTY": "0.000", "REM_MAX_QTY_TE": "0.000", "XMDOCNR": "5025092776", "DOCITM": "0000014021", "COMMODITY": "RB", "TRADING_COMPANY": "3862", "PERIODICITY": "PRAGUE", "POSTING_DATE": "20211117", "MARKET": "CME", "TRADETYP": "EXP", "MAX_DOC_QTY": "12256.230", "TRANSPORT_CODE": "AR", "DOCNR": "4700234521", "SEGMENTH": "1", "TRADE_NUM": "NA-152", "PACKAGE_GUID": "ASDER3785$%SDF", "TRADETYP_TCODE_ALL": ["GR-BARGE", "EXP-AR", "CR-LCL"] } }, { "TRADERECORD": { "DOC_QTY": "14256.210", "ACT_NOM_CONSUMED_QTY": "0.000", "REM_MAX_QTY_TE": "0.000", "XMDOCNR": "5025023562", "DOCITM": "0000012041", "COMMODITY": "RB", "TRADING_COMPANY": "3862", "PERIODICITY": "PRAGUE", "POSTING_DATE": "20211117", "MARKET": "CME", "TRADETYP": "CR", "MAX_DOC_QTY": "14256.230", "TRANSPORT_CODE": "LCL", "DOCNR": "4700278453", "SEGMENTH": "1", "TRADE_NUM": "NA-152", "PACKAGE_GUID": "ASDER3785$%SDF", "TRADETYP_TCODE_ALL": ["GR-BARGE", "EXP-AR", "CR-LCL"] } } ] The Jolt Spec I am working on : [ { "operation": "shift", "spec": { "TRADE_HEADER": { "TRADEDETAIL": { "TRADEDETAILLINE": { "*": { "@": "[&1]", "@(2,SEGMENT)": "[&1].SEGMENTH", "@(2,TRADE_NUM)": "[&1].TRADE_NUM", "@(2,PACKAGE_GUID)": "[&1].PACKAGE_GUID", "@(0,TRADETYP)": "[#1].TRADETYP_ALL", "@(0,TRANSPORT_CODE)": "[#1].TRANSPORT_CODE_ALL" } } } } } }, { "operation": "shift", "spec": { "*": { "@": "TRADERECORD" } } } ] The Result of this Jolt spec { "TRADERECORD" : [ { "DOC_QTY" : "19956.930", "ACT_NOM_CONSUMED_QTY" : "0.000", "REM_MAX_QTY_TE" : "0.000", "XMDOCNR" : "5025087976", "DOCITM" : "0000012001", "COMMODITY" : "RB", "TRADING_COMPANY" : "3862", "PERIODICITY" : "PRAGUE", "POSTING_DATE" : "20211117", "MARKET" : "CME", "TRADETYP" : "GR", "MAX_DOC_QTY" : "19956.930", "TRANSPORT_CODE" : "BARGE", "DOCNR" : "4700253115", "SEGMENTH" : "1", "TRADE_NUM" : "NA-152", "PACKAGE_GUID" : "ASDER3785$%SDF", "TRADETYP_ALL" : [ "GR", "EXP", "CR" ], "TRANSPORT_CODE_ALL" : [ "BARGE", "AR", "LCL" ] }, { "DOC_QTY" : "12256.230", "ACT_NOM_CONSUMED_QTY" : "0.000", "REM_MAX_QTY_TE" : "0.000", "XMDOCNR" : "5025092776", "DOCITM" : "0000014021", "COMMODITY" : "RB", "TRADING_COMPANY" : "3862", "PERIODICITY" : "PRAGUE", "POSTING_DATE" : "20211117", "MARKET" : "CME", "TRADETYP" : "EXP", "MAX_DOC_QTY" : "12256.230", "TRANSPORT_CODE" : "AR", "DOCNR" : "4700234521", "SEGMENTH" : "1", "TRADE_NUM" : "NA-152", "PACKAGE_GUID" : "ASDER3785$%SDF" }, { "DOC_QTY" : "14256.210", "ACT_NOM_CONSUMED_QTY" : "0.000", "REM_MAX_QTY_TE" : "0.000", "XMDOCNR" : "5025023562", "DOCITM" : "0000012041", "COMMODITY" : "RB", "TRADING_COMPANY" : "3862", "PERIODICITY" : "PRAGUE", "POSTING_DATE" : "20211117", "MARKET" : "CME", "TRADETYP" : "CR", "MAX_DOC_QTY" : "14256.230", "TRANSPORT_CODE" : "LCL", "DOCNR" : "4700278453", "SEGMENTH" : "1", "TRADE_NUM" : "NA-152", "PACKAGE_GUID" : "ASDER3785$%SDF" } ] } Please help me combining the attributes and get to the final desired JSON output
... View more
Labels:
- Labels:
-
Apache NiFi