Created on 04-21-2024 01:24 PM - edited 04-21-2024 01:45 PM
Hello,
Can you assist me in retrieving the values stored in the "customfield_10161" field from JSON input? My expectation is to consistently receive the values and name it "DEFECT_ROOT_CAUSE" , whether they are stored as a list or as a single value."
How to write JOLT which will handle the both the case. let say If I will get list then extract last element of it, if not list then record as it is.?
Extracting List: (works fine when input is list)
when input is not list:
then DEFECT_ROOT_CAUSE column is missing My expectation to get the records in DEFECT_ROOT_CAUSE columns whether its list or not.
Created on 05-06-2024 02:21 PM - edited 05-06-2024 02:21 PM
Based on the provided new input and the expected output as I was able to understand where you always want to consider the last element of both DEFECT_ROOT_CAUSE & SPRINT_LIST which both may or may not be an array of values, I would take a different approach to the jolt spec which is much simpler as follows:
[
// First spec is convert everything into list regardless
{
"operation": "cardinality",
"spec": {
"*": {
"SPRINT_LIST": "MANY",
"DEFECT_ROOT_CAUSE": "MANY"
}
}
}
,
// From the generated list above return last element
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"SPRINT_LIST": "=lastElement",
"DEFECT_ROOT_CAUSE": "=lastElement"
}
}
}
]
Created on 04-21-2024 03:35 PM - edited 04-21-2024 03:36 PM
Hi @saquibsk ,
The below spec should put you on the right path if it doesnt completely solve your issue:
[
// Assign isArray flag field when there is an array (index starts at 0)
{
"operation": "shift",
"spec": {
"id": "INTEGRATION_ID",
"*": {
"*_*": {
"@": "&(1,1)",
"0": {
"#true": "isArray"
}
}
}
}
}
,
//If the input is not an array assign default isArray=false
{
"operation": "default",
"spec": {
"isArray": "false"
}
}
,
//Depending on with isArray true of false:
//Transpose values into DEFECT_ROOT_CAUSE_List array
{
"operation": "shift",
"spec": {
"customfield": null,
"*": "&",
"isArray": {
"true": {
"@(2,customfield)": {
"*": {
"value": {
"@": "DEFECT_ROOT_CAUSE_List[]"
}
}
}
},
"false": {
"@(2,customfield)": "DEFECT_ROOT_CAUSE_List[]"
}
}
}
}
,
// Finally, get the last element of the array
{
"operation": "modify-overwrite-beta",
"spec": {
"DEFECT_ROOT_CAUSE": "=lastElement(@(1,DEFECT_ROOT_CAUSE_List))"
}
}
]
If that helps please accept solution.
Thanks
Created 04-21-2024 10:17 PM
Hi @SAMSAL,
Thank you for the reply.
There are still no columns showing in the non-list scenario.
Created 04-22-2024 05:47 AM
In my jolt spec its expecting customfield_10616 , so in my spec if you notice in the first shift Im using the expression *_* basically to make more dynamic but at least you have to have an underscore but if you think otherwise you can change it to whatever works for your data, for example you can change it to "customfield" , "customfield_*" , "*" , etc.
Created 04-22-2024 11:33 PM
This customfield_ will not change because it is static. I'm handling this aspect in NiFi right now, however I get into trouble when I acquire more fields as lists and have to change the NIFI Flow.
Created 04-23-2024 03:58 AM
This is how I am currently handling the records. All I'm doing is flagging the rows and sending them to the appropriate process. However, suppose in the future that a new field or an existing one begins to capture List data; in that case, I would need to modify the flow and add more conditions. I just needed a single field, therefore let's say that if it captures the list, it will show up as the last record or as a single record.
Created on 04-23-2024 06:39 AM - edited 04-23-2024 06:40 AM
I think the issue here is stating what the problem is vs the actual problem. since you starting posting the issue, I noticed the json input has changed 3 times. Remember as someone said "Asking the right question is half way the path to finding the right solution".
Allow me give you some pointers:
1- Please specify the different json input for all possible scenarios and the expected output\s.
2- If you have compound problem then divide and conqueror. Break the big problem into smaller one where each is isolated to its own input, output and assertions..
3- Simplify if you can, for example if you have complex json input and you are only facing issue with particular field or nested object then you dont have to post the whole json , instead you isolate where the issue is and provide that part only or create new one that mimic the same structure.
4- If you have code or some formatted data please use the code block "</>" from the menu item for better visibility and readability. Dont post code\data as screenshot.
5- Use screenshots for when suitable , like showing nifi flow, processor configuration ..etc.
6- Refer to the community guidelines for more info: https://community.cloudera.com/t5/custom/page/page-id/Community_Guidelines
Hope that helps.
Created on 04-23-2024 09:57 AM - edited 04-23-2024 10:01 AM
Hi @SAMSAL ,
My requirement is very simple.
I anticipate receiving the single records in the output. That's DEFECT_ROOT_CAUSE, regardless of whether my input is a list or sinlge records.
(The primary source is JIRA; a bug ticket has been generated there, indicating that the issue may be in the front end or back end. However, occasionally a reporter will tag the back end before the front end, leading to the creation of a list. )
> my input is almost 200 line however I am only putting the required column only. I have posted two image one is for list records and one is single records with same column (only records is getting changes that's it.
Created 04-23-2024 03:59 PM
Based on my json spec above:
1- customfield_* with multiple records list
2- customfield_* with single records list:
3- customfield_* with no list:
The asterisk in customfield_* means anything as long there is a customfield , underscore (_) and whatever comes after.
Created 05-06-2024 05:12 AM
Hi @SAMSAL ,
Am I missing something on the JOLT?
Not getting output as expected. (DEFECT_ROOT_CUASE) columns is missing from output.
===========================================
--Input
===========================================
{
"id": "33414",
"fields": {
"customfield_10161": [
{
"value": "Backend"
},
{
"value": "Frontend"
}
]
}
}
===========================================
--JOLT Spec
===========================================
[
// Entries (where "flat" "data" when there is an array) (now starts at 8)
{
"operation": "shift",
"spec": {
"id": "INTEGRATION_ID",
"*": {
"*_*": {
"@": "&(1,1)",
"0": {
"#true": "isArray"
}
}
}
}
},
//If the input is not an array, assign default isArray=false
{
"operation": "default",
"spec": {
"isArray": "false"
}
},
//Depending on with isArray true for false
//Transpose values into DEFECT_ROOT_CAUSE_List_Array
{
"operation": "shift",
"spec": {
"customfield": null,
"*": "&",
"isArray": {
"true": {
"@(2,customfield)": {
"*": {
"value": {
"@": "DEFECT_ROOT_CAUSE_LIST[]"
}
}
}
},
"false": {
"@(2,customfield)": "DEFECT_ROOT_CAUSE_LIST[]"
}
}
}
},
// Finally, get the last element of the array
{
"operation": "modify-overwrite-beta",
"spec": {
"DEFECT_ROOT_CAUSE": "=lastElement(@(1,DIRECT_ROOT_CAUSE_LIST))"
}
}
]
===========================================
--Output
===========================================
{
"INTEGRATION_ID" : "33414",
"DEFECT_ROOT_CAUSE_LIST" : [ "Backend", "Frontend" ]
}