1
votes

I have a database query that returns data like this:

"LABEL","CONTAINER_ID","STATUS"
"14.JW24","1006063116","F"
"14.JW25","1006063116","F"
"1.JW2M","9999997","R"
"8.282","9999999","R"
"4.135","9999999","F"
"6.43","9999999","F"
"11.12","9999999","R"
"14.JW12","1006063073","R"
"14.JW13","1006063073","R"
"14.JW10","1006063068","F"

I'm using Dataweave to create a list of the distinct container_id values that have a status of "F". Something like:

["1006063116", "9999999", "1006063068"]

Here is my dataweave script:

%dw 1.0
%output application/java
---
payload filter $.STATUS == "F" groupBy $.CONTAINER_ID pluck $$

This works fine except that I get a list of com.mulesoft.weave.model.structure.QualifiedName objects instead of a list of strings.

How can I modify the dataweave script so I get strings, or alternatively, how can I get the string value from the QualifiedName object? I've tried calling toString() and getName() on the object. The former doesn't give the value I need and the latter doesn't work.

1

1 Answers

0
votes

just cast the resulting elements to string like this:

%dw 1.0
%output application/java
---
payload filter $.STATUS == "F" groupBy $.CONTAINER_ID pluck $$ as :string

the important part is the as :string

alternative solution: you could use the distinctBy keyword to achieve a similar result and get rid of groupBy+pluck:

%dw 1.0
%output application/java
---
(payload filter $.status == "F").container_id distinctBy $