The two Mule runtime engine releases in 2021 also included new releases of the DataWeave language. These releases have introduced powerful (or, if you prefer, "Way Cool") functionality to the language, ranging from the convenient update() operator to the esoteric levenshteinDistance() function (calculates the Levenshtein Distance for 2 strings).
While those two new features may be helpful, you may have other requirements that you were able to implement in prior versions of DataWeave, but perhaps not as cleanly or efficiently as you wish. Or you might not have known that a new DataWeave function exists to greatly simplify your code. Well, this session is for you!
One of Big Compass' Lead MuleSoft Consultants, Ben Stone, will deliver a session focusing on new DataWeave 2.3 and 2.4 features, along with other DataWeave tips and tricks he has learned in his MuleSoft implementations.
He will have numerous examples and demos to reinforce the concepts he will present.
After this presentation, you will understand how to best use the new features in DataWeave to more rapidly implement your MuleSoft solutions.
2. 2
● 6:00 - 6:10 - Networking
● 6:10 - 6:15 - Introductions
● 6:15 - 7:20 - Cool New Features in DataWeave 2.3 and 2.4
● 7:20 - 7:30 - Wrap up and CY 2022 plans
● 7:30 - Meetup concludes
Agenda
3. 3
Stephanie Lawrence
Event & Marketing Coordinator
Big Compass
Denver Meetup Introductions
Use Chat - tell us where you are joining us from
Brian Statkevicus
MuleSoft Practice Manager
Big Compass
Aaron Lieberman
Senior Engineering Manager
Science 37
4. 4
● Use Chat
● One answer per person per question
○ If you answer more than 1x per question, you are ineligible for that question
● If you’ve already won during today’s Meetup, you cannot win again
● Big Compass makes the final decision on the trivia winners that will be submitted to MuleSoft
(see next slide)
Trivia Questions - “House Rules”
More important Trivia guidelines on next slide
5. 5
● Big Compass emails trivia winners a link to a Google Form for the trivia winners to complete
● Once you complete this form, MuleSoft will verify:
○ You haven’t already won this month
○ You’re not trying other means to circumvent the 1x/month rule
● MuleSoft will send you the voucher
○ The voucher is a training voucher, not a standalone exam voucher. If you select an exam on the
Google Form as opposed to selecting a course, you will not receive a voucher.
○ MuleSoft retains the final decision on determining your eligibility to receive a training voucher
● If you have trouble redeeming a voucher or have not received a voucher, open a ticket at
training.mulesoft.com/question. DO NOT CONTACT US!
Trivia Questions - MuleSoft Guidelines
7. 7
● Developer at Big Compass for the last year and a half
● MuleSoft developer for two years
● Avid board gamer and rock climber
● Third time presenting for MuleSoft Meetups
About Me
11. 11
● What to do if you want to update a single field in a large object?
○ Create a transformation that copies every field, changing one
○ Use mapObject
Previously
12. 12
● Specify a field and a replacement value
● Import from Values module
● Value can be dynamic
Update Operator
13. 13
● Use an expression to determine the values to update
● Uses a similar case structure to the match operator
Conditional Update
14. 14
● Use the “!” operator with the case expression
Upserting
15. What is the output of the following DataWeave?
Trivia Question #1
A:
{
"id": 16,
"assignee": "Alice"
}
B:
{
"id": 17,
"assignee": "Alice"
}
C:
{
"id": 16,
"assignee": "Bob"
}
D:
{
"id": 17,
"assignee": "Bob"
}
17. Generic Accessors
● valuesOf - array of values from an
object
● namesOf - retrieve array of key
names from an object
○ Useful especially with groupBy
○ Be careful of difference to keysOf
18. String Manipulation
● Substring selection
○ substring, substringBy, and substringEvery
○ Many people were confused by the original
substring notation
● Words - even more convenient
19. Distance Metrics
● hammingDistance - count of positions
where two strings differ
● levenshteinDistance - edit distance
between two strings
20. Which pair of strings has the smallest Levenshtein Distance?
Trivia Question #2
A. Kitten - Sitting
A. Start - Tarts
C. Mantra - Manta
D. Alert - Advert
22. Properties
● DW reader - ‘privileges’ - restrict access to resources or properties
● XLSX reader - ‘tableLimit’ - limit columns read in from the sheet
○ <Column>, ‘HeaderSize’, or ‘unbounded’
● YAML writer - ‘writeDeclaration’ - allows you to remove the header declaration
23. XML Writer
● ‘defaultNamespace’ - sets the default namespace
● ‘writeDeclaredNamespaces’ - chooses namespaces to add to the root element
○ ‘All’ - every namespace
○ ‘ids:<id1>,<id2>’ - comma separated list
○ ‘regex:<regex>’ - all matching namespaces
25. Math
● Trigonometric functions
● Logarithms - limited to base 10 or natural logarithm
○ Use the change of base formula if you need anything else
● Degree/Radian conversion
● Constants - E and PI
26. Coercions
● Assorted functions to attempt to coerce one value to a different type
● If you need to do this sort of coercion, best to do it explicitly
● Remember the ‘~=’ operator, for comparison with attempted coercion
27. Which of these snippets of DataWeave does NOT produce the same output as the others?
Trivia Question #3
A:
B:
C:
29. 29
● Share:
○ Tweet using the hashtag #MuleSoftMeetups
○ Invite your network to join: https://meetups.mulesoft.com/denver
● Feedback:
○ Complete the Meetup survey, provide feedback, and suggest topics for upcoming events
○ Contact MuleSoft at meetups@mulesoft.com for ways to improve the program
What’s next?
30. 30
● This is our last Meetup in 2021
● Future (tentative) Meetup schedule:
○ Feb 16 - MuleSoft Composer
○ Mar 31
○ May 18
○ Aug 3
○ Sep 21
○ Nov 9
● CY 2022 Meetups will be in person!!!
■ Subject to local and CDC guidance
● We are looking for topic suggestions and speakers!
Denver Meetups 2022