Partition bulk records into accepted and rejected lists
Problem My DataWeave script threw an unresolved reference error when calling partition without an explicit import. The Arrays module must be imported to your DataWeave code by adding the line import * from dw::core::Arrays to the header of your DataWeave script docs . Input { "records" : [ { "id" : "ORD-1001" , "email" : "ana@example.com" }, { "id" : "ORD-1002" , "email" : "bad-address" }, { "id"…
In order to avoid an unresolved reference error when using the partition function in DataWeave, it is necessary to import the Arrays module from dw::core::Arrays at the beginning of the script. The input data consists of a list of records, each containing an ID and an email address.
The working configuration involves importing the Arrays module and then using the partition function to divide the records into two groups: those with valid email addresses and those with invalid or missing email addresses. The accepted array contains the IDs of records with valid emails, while the rejected array includes objects with the ID and a reason for rejection (missing or invalid email). Additionally, the script calculates a retryCount field, which is the size of the failure partition.
The accepted array in the output contains the IDs from records with valid email addresses: ORD-1001, ORD-1003, and ORD-1005. The rejected array holds objects for records with missing or invalid email addresses, such as ORD-1002 and ORD-1004, along with the reason "missing or invalid email". The retryCount field is set to 2, indicating the number of records that failed the partition test.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.