Member since
06-14-2022
60
Posts
2
Kudos Received
0
Solutions
12-13-2022
03:02 AM
Can someone please help
... View more
12-13-2022
03:01 AM
Hi Team,
I am calling store procedure in Nifi using groovy script. The store procedure contains output parameter which is returning huge CLOB which is in array of json format. I am using below groovy script to call the store procedure
import org.apache.commons.io.IOUtils import org.apache.nifi.controller.ControllerService import org.apache.nifi.processor.io.StreamCallback import java.nio.charset.* import groovy.sql.OutParameter import groovy.sql.Sql import java.sql.ResultSet import java.sql.Clob import static java.sql.Types.CLOB import java.nio.charset.StandardCharsets import groovy.json.*
def flowFile = session.get() if(!flowFile) return def lookup = context.controllerServiceLookup def dbServiceName = ConncationPool.value def dbcpServiceId = lookup.getControllerServiceIdentifiers(ControllerService).find { cs -> lookup.getControllerServiceName(cs) == dbServiceName }
try {
flowFile = session.write(flowFile, { inputStream, outputStream -> def conn = lookup.getControllerService(dbcpServiceId).getConnection(); sql = Sql.newInstance(conn); String sqlString ="""{call MY_STORE_PROC(?)}"""; def out_param
def parametersList = [Sql.CLOB];
sql.call(sqlString, parametersList) {out_json_response -> out_param = out_json_response }; def json = JsonOutput.toJson(out_param) def parser = new JsonSlurper() outputStream.write(parser.parseText(json).getBytes(StandardCharsets.UTF_8)) } as StreamCallback) session.transfer(flowFile, REL_SUCCESS) } catch(Exception e) { log.error('Error during JSON operations', e) session.transfer(flowFile, REL_FAILURE) }
But I am getting below error:
failed to process due to org.apache.nifi.processor.exception.ProcessException: java.lang.StackOverflowError
Processing failed: org.apache.nifi.processor.exception.ProcessException: java.lang.StackOverflowError - Caused by: java.lang.StackOverflowError
Can you please help, I am not getting the CLOB datatype issue.
... View more
Labels:
- Labels:
-
Apache NiFi
12-11-2022
09:26 PM
Hi Team, Need help. I have below two part. 1. merge the original Response with the API Response Original response [{ "code": "100016", "Date": "2022-09-22" }, { "code": "100017", "Date": "2022-09-02" }, { "code": "100018", "Date": "2022-09-02" }, { "code": "100019", "Date": "2022-09-02" } ] API Response: [{ "Record": "Record 3", "Description": "Processing failed due Internal Server Error." }, { "Record": "Record 4", "Description": "Processing failed due to error in record: 3" }] Required output: { "RequestPayload": [{ "code": "100016", "Date": "2022-09-22" }, { "code": "100017", "Date": "2022-09-02" }, { "code": "100018", "Date": "2022-09-02" }, { "code": "100019", "Date": "2022-09-02" } ], "ApiResponse": [{ "Record": "Record 3", "Description": "Processing failed due Internal Server Error." }, { "Record": "Record 4", "Description": "Processing failed due to error in record: 3" }] } After getting the above output I need to mapped the json objects as below input: { "RequestPayload": [{ "code": "100016", "Date": "2022-09-22" }, { "code": "100017", "Date": "2022-09-02" }, { "code": "100018", "Date": "2022-09-02" }, { "code": "100019", "Date": "2022-09-02" } ], "ApiResponse": [{ "Record": "Record 3", "Description": "Processing failed due Internal Server Error." }, { "Record": "Record 4", "Description": "Processing failed due to error in record: 3" }] } I am getting below output: [ "{\"code\":\"100018\",\"Date\":\"2022-09-22\"}", "{\"code\":\"100019\",\"Date\":\"2022-09-02\"}" ] Expected Output: [{ "code": "100018", "Date": "2022-09-22", "Record": "Record 3", "Description": "Processing failed due Internal Server Error."." }, { "code": "100019", "Date": "2022-09-02", "Record": "Record 4", "Description": "Processing failed due to error in record: 3" } ] For that I am using below groovy Script: import org.apache.commons.io.IOUtils import java.nio.charset.StandardCharsets import groovy.json.* import java.util.ArrayList def flowFile = session.get() if(!flowFile) return try { flowFile = session.write(flowFile, { inputStream, outputStream -> def text = IOUtils.toString(inputStream, StandardCharsets.UTF_8) def obj = new JsonSlurper().parseText(text) def final1 = [] int j = obj.RequestPayload.size() for (int i=0;i<j;i++){ index = i+1 def rec = 'Record ' + index if (rec in obj.ApiResponse.Record){ final1.add(JsonOutput.toJson(obj.RequestPayload[i])) } } def response1 = JsonOutput.toJson(final1) outputStream.write(JsonOutput.prettyPrint(response1).getBytes(StandardCharsets.UTF_8)) } as StreamCallback) session.transfer(flowFile, REL_SUCCESS) } catch(Exception e) { log.error('Error during JSON operations', e) session.transfer(flowFile, REL_FAILURE) } Can you please help. I am not familiar with groovy but i want to get the desired output with groovy script. Thanks in Advance
... View more
Labels:
- Labels:
-
Apache NiFi
12-10-2022
06:51 AM
Hi @MattWho , I did lot of investigation on the same but was not sure merge record can do that. Thanks a lot for your help.
... View more
12-10-2022
06:46 AM
Hi @Faerballert , Thank you so much. I tried it earlier the same but not sure why it were not working. some of my fields contains null values. But instead of null I want the empty string in the same jolt. Can we do that? is there any option to do the same.
... View more
12-06-2022
04:10 AM
Thank you so much @Faerballert
... View more
11-28-2022
08:51 PM
@SAMSAL Thank you for your help.
... View more
11-28-2022
08:50 PM
Hi @Faerballert , Its working as expected. Thank you so much.
... View more
11-24-2022
05:56 AM
Hi @gkp_shakeel , Can you please help me with the CURSOR data type object and the INTERFACE_DATA%ROWTYPE; Parameters. How can I call such store procedure
... View more
11-23-2022
02:51 AM
@Faerballert , It's working fine as expected. Thank you so much for the quick response.
... View more
- « Previous
-
- 1
- 2
- Next »