[ 
https://issues.apache.org/jira/browse/NIFI-14664?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17984977#comment-17984977
 ] 

Daniel Stieglitz edited comment on NIFI-14664 at 6/20/25 4:25 PM:
------------------------------------------------------------------

[~zhongwei.long] You are welcome. Glad to help!

I believe although I cannot conclusively say that it is a special case in Jolt 
specification parsing. I have been running the code in a debugger and the 
problems start at line 185 in JoltTransformJSON.
{code:java}
final Object transformedJson = TransformUtils.transform(transform, 
inputJson);{code}
When stepping in to this code until where the actual Jolt API  is called 
(com.bazaarvoice.jolt.Chainr in the for loop on lines 95-97) I see where 
"suggestedMax" is shifted but for some reason on subsequent calls  
"suggestedMax" has been copied already to the c.options.scales.xAxes[0].ticks 
section even before the last rule hence the result of getting multiple values 
for "suggestedMax". It would seem that the "modify-define-beta" somehow is 
filling that section already. I am still unsure why it does this.

You certainly made the right move simplifying your transformations. If you want 
to look at this further run the following Google query
{code:java}
Jolt modify-define-beta copying more than expected" and see the suggestions 
given{code}
there it gives possible reasons for this operation copying more than expected.


was (Author: JIRAUSER294662):
[~zhongwei.long] You are welcome. Glad to help!

I believe although I cannot conclusively say that it is a special case in Jolt 
specification parsing. I have been running the code in a debugger and the 
problems start at line 185 in JoltTransformJSON.
{code:java}
final Object transformedJson = TransformUtils.transform(transform, 
inputJson);{code}
When stepping in to this code until where the actual Jolt API  is called 
(com.bazaarvoice.jolt.Chainr in the for loop on lines 95-97) I see where 
"suggestedMax" is shifted but for some reason on subsequent calls  
"suggestedMax" has been copied already to the c.options.scales.xAxes[0].ticks 
section even before the last rule hence the result of getting multiple values 
for "suggestedMax". It would seem that the "modify-define-beta" somehow is 
filling that section already. I am still unsure why it does this.

> JoltTransformJSON repeatedly appends values to fields on re-execution
> ---------------------------------------------------------------------
>
>                 Key: NIFI-14664
>                 URL: https://issues.apache.org/jira/browse/NIFI-14664
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Examples
>    Affects Versions: 2.4.0
>            Reporter: le.zw
>            Priority: Major
>              Labels: jolt
>         Attachments: JOLT_Test.json, image-2025-06-16-16-15-40-471.png, 
> image-2025-06-16-16-25-51-932.png, image-2025-06-16-16-29-05-004.png
>
>
> input JSON
> {code:java}
> [
>   {
>     "category":  "05-01",
>      "value":  218
>   },
>   {
>     "category":  "05-02",
>      "value":  219
>   },
>   {
>     "category":  "05-03",
>      "value":  170
>   }
> ]
> {code}
> JOLT spec:
> {code:java}
> [
>   {
>     "operation": "shift",
>     "spec": {
>       "*": {
>         "category": "c.data.labels.[&1]",
>         "value": "c.data.datasets[0].data"
>       }
>     }
>   },
>   {
>     "operation": "modify-overwrite-beta",
>     "spec": {
>       "max": "=max(@(1,c.data.datasets[0].data))"
>     }
>   },
>   {
>     "operation": "modify-overwrite-beta",
>     "spec": {
>       "suggestedMax": "=intSum(@(1,max),20)"
>     }
>   },
>   {
>     "operation": "modify-define-beta",
>     "spec": {
>       "c": {
>         "type": "horizontalBar",
>         "data": {
>           "datasets": {
>             "*": {
>               "label": "Orders",
>               "backgroundColor": "gold"
>             }
>           }
>         },
>         "options": {
>           "scales": {
>             "xAxes": [
>               {
>                 "gridLines": {
>                   "display": true,
>                   "drawOnChartArea": false,
>                   "tickMarkLength": 8,
>                   "zeroLineWidth": 1,
>                   "zeroLineColor": "black",
>                   "color": "black"
>                 },
>                 "ticks": {
>                   "fontColor": "black",
>                   "beginAtZero": true
>                 }
>               }
>             ],
>             "yAxes": [
>               {
>                 "display": true,
>                 "position": "left",
>                 "gridLines": {
>                   "display": true,
>                   "drawOnChartArea": false,
>                   "tickMarkLength": 8,
>                   "color": "black"
>                 },
>                 "ticks": {
>                   "fontColor": "black",
>                   "fontSize": "8"
>                 }
>               }
>             ]
>           },
>           "legend": {
>             "display": false
>           },
>           "plugins": {
>             "datalabels": {
>               "anchor": "end",
>               "align": "end",
>               "color": "black",
>               "font": {
>                 "size": 10,
>                 "weight": "bold"
>               }
>             }
>           }
>         }
>       }
>     }
>   },
>   {
>     "operation": "shift",
>     "spec": {
>       "c": {
>         "options": {
>           "scales": {
>             "xAxes": {
>               "*": "c.options.scales.xAxes[#2].&"
>             },
>             "yAxes": {
>               "*": "c.options.scales.yAxes[#3].&"
>             }
>           },
>           "*": {
>             "@": "c.options.&0"
>           }
>         },
>         "*": {
>           "@": "c.&0"
>         }
>       },
>       "suggestedMax": "c.options.scales.xAxes[0].ticks.suggestedMax"
>     }
>   }
> ]
> {code}
> On repeated executions, the suggestedMax field is transformed into an array 
> whose number of elements increases over time.
> *After the first execution, {{suggestedMax}} is a single value:*
> *!image-2025-06-16-16-25-51-932.png!*
> *After the second execution, the {{suggestedMax}} field is transformed into 
> an array containing two values:*
> *!image-2025-06-16-16-29-05-004.png!*



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to