Dataweave

 

How to enable streaming in Dataweave?

Dataweave doesn’t enable the streaming by default and we have to explicitly direct it to pass the data as stream. This enable faster processing of data where large amount of data need to be processed

Enable streaming while transforming and passing the data to next processor

%dw 2.0
output application/json deferred = true
---
payload

more info – https://docs.mulesoft.com/dataweave/latest/dataweave-streaming#stream_output

 

Reduce function and it’s usage in Dataweave?

The reduce function in DataWeave is used to apply a function to each element of an array, accumulating the results into a single value. Here the reduce function will loop on items in the item array and store the values in acc in each iteration. If acc intial value is not defined then it will take the first value of the item array.

%dw 2.0
output application/json
var numbers = [1, 2, 3, 4, 5]
---
numbers reduce ((item, acc) -> acc + item)

Output = 15

with intial value defined for acc

%dw 2.0
output application/json
var numbers = [1, 2, 3, 4, 5]
---
numbers reduce ((item, acc = 3) -> acc + item)

Output = 18

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments