SlideShare a Scribd company logo
1 of 35
Vancouver Canada
19th Nov 2020
Reviewing a Complex DataWeave Transformation
Use-case
Presenters,Organizers and You
Vishal Aggarwal Yashwant Palkar Alexandra Martinez
Alexandra Martinez
Reviewing a Complex DataWeave
Transformation Use-case
4
● Functions (fun)
○ Parameters using types
○ Calling functions with 2 parameters
● Variables (var)
● do statement to create scopes (local variables)
● Object manipulation using object destructor {( )}
● If/else
● Selectors:
○ Index (array[0])
○ Range (1 to 10)
● Setting default values
● Core functions/operators
○ isEmpty, reduce, map, groupBy, flatten
○ Remove (-), Sum (+), Concatenation (++), Prepend (>>)
Solution will make use of the following:
Requirement
6
Input JSON structure to Output JSON structure
Requirement
7
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
Requirement
7
8
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
Requirement
8
9
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
Requirement
9
10
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
4. If there are EndOfConnection fields
that are true and this is not the last
object inside the Connections array,
create a new output object
containing all the false Connection
objects before this, and using this
last object’s TaxCode.
Requirement
10
11
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
4. If there are EndOfConnection fields
that are true and this is not the last
object inside the Connections array,
create a new output object
containing all the false Connection
objects before this, and using this
last object’s TaxCode.
5. Each AppliedConnections object in
the output must have:
1. A hardcoded Type value
“Connection”.
Requirement
11
Building the Solution
13
● DW Playground: https://dwl.mule.club/
● Input payload:
{"FlightOptions":[{"Connections":[{"ReferenceID":111,"TaxCode":"ABC","EndOfConnection":false},{"ReferenceID":222,"TaxCode":"DEF","EndOfConnection":true}]},{"
Connections":[{"ReferenceID":333,"TaxCode":"GHI","EndOfConnection":true},{"ReferenceID":444,"TaxCode":"JKL","EndOfConnection":true}]},{"Connections":[{"Ref
erenceID":555,"TaxCode":"MNO","EndOfConnection":false},{"ReferenceID":666,"TaxCode":"PQR","EndOfConnection":false},{"ReferenceID":777,"TaxCode":"STU","
EndOfConnection":false}]},{"Connections":[{"ReferenceID":888,"TaxCode":"VWX","EndOfConnection":false}]},{"Connections":[{"ReferenceID":999,"TaxCode":"MNO"
,"EndOfConnection":false},{"ReferenceID":101,"TaxCode":"PQR","EndOfConnection":true},{"ReferenceID":102,"TaxCode":"STU","EndOfConnection":false}]}]}
● Expected output:
[{"AppliedTaxCode":"DEF","AppliedConnections":[{"Type":"Connection","IndexValue":1},{"Type":"Connection","IndexValue":2}]},{"AppliedTaxCode":"GHI","AppliedCo
nnections":[{"Type":"Connection","IndexValue":3}]},{"AppliedTaxCode":"JKL","AppliedConnections":[{"Type":"Connection","IndexValue":4}]},{"AppliedTaxCode":"STU
","AppliedConnections":[{"Type":"Connection","IndexValue":5},{"Type":"Connection","IndexValue":6},{"Type":"Connection","IndexValue":7}]},{"AppliedTaxCode":"VW
X","AppliedConnections":[{"Type":"Connection","IndexValue":8}]},{"AppliedTaxCode":"PQR","AppliedConnections":[{"Type":"Connection","IndexValue":9},{"Type":"C
onnection","IndexValue":10}]},{"AppliedTaxCode":"STU","AppliedConnections":[{"Type":"Connection","IndexValue":11}]}]
● Format JSONs:
https://jsonformatter.curiousconcept.com/
Building the Solution
14
1) Extract the Connections arrays.
Building the Solution
15
2) Change all the EndOfConnection to true for the last Connection object from the Connections
array.
Building the Solution
16
3) flatten the array of arrays to be just one array.
Building the Solution
17
4) Add a new field to keep track of the object’s index, basing on the EndOfConnection field.
(For each EndOfConnection=true, stop incrementing the index.)
Building the Solution
Index 1
Index 2
Index 1
Index 1
Index 1
Index 3
Index 2
18
5) Add a new field to keep track of the final AppliedConnections object’s (first) index where the
object in question will be added.
Note: This is calculated using the object’s index + 1 (to start at 1) and then minus the previously
added indexBasedOnEOC field.
Building the Solution
Index 0
Index 2
Index 3
Index 4
19
6) Separate the objects based on the EndOfConnection value (true or false).
Building the Solution
20
7) Take only the objects that are inside the “true” list.
Building the Solution
21
8) Create the final output.
Building the Solution
Playing with the indexes
23
Playing with the indexes
1
2
1
1
1
2
3
1
1
1
2
Index based on
EndOfConnection
24
Playing with the indexes
Index based on
EndOfConnection index + 1
1
3
4
5
2 6
7
8
9
10
11
1
2
1
1
1
2
3
1
1
1
2
25
Playing with the indexes
Index based on
EndOfConnection
1-1=0
3-1=2
4-1=3
5-1=4
2-2=0 6-2=4
7-3=4
8-1=7
9-1=8
10-2=8
11-1=10
1
2
1
1
1
2
3
1
1
1
2
AppliedConnections
Index
(index+1) - indexBasedOnEOC
26
Playing with the indexes
Index based on
EndOfConnection
0
2
3
4
0 4
4
7
8
8
10
1
2
1
1
1
2
3
1
1
1
2
1+0=1
2+0=2
1+2=3
1+3=4
1+4=5
2+4=6
3+4=7
1+7=8
1+8=9
2+8=10
1+10=11
AppliedConnections
Index
(index+1) - indexBasedOnEOC
IndexValue
indexBasedOnEOC (or actualIndex or
actualNum) +
indexAppliedConnections
Try it yourself!
Code
● GitHub repository: https://github.com/alexandramartinez/reviewing-a-complex-dw-
transformation-use-case/
References
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-functions
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-variables
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-flow-control
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-selectors
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-defaults
● https://docs.mulesoft.com/mule-runtime/3.9/dataweave-operators
● https://docs.mulesoft.com/mule-runtime/4.3/dw-operators
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-isempty
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-reduce
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-map
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-groupby
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-flatten
Questions?
Quiz…
Go to www.menti.com and use the code 5462238
MuleSoft News for November
• There is still time to register and submit a project for the MuleSoft Hackthon 2020! If you
are interested in participating the deadline for register and submit is Nov 29, 2020 at 11:59
pm PT. https://www.mulesoft.com/hackathon2020
• Register and complete the free training course offered by MuleSoft
Anypoint Platform Development: Fundamentals
• The course prepares students to take the MuleSoft Certified Developer - Level 1 (Mule
4) exam. Upon successful completion of the course, students automatically receive two
exam attempts. https://training.mulesoft.com/course/development-fundamentals-mule4
• Try out the new features of Anypoint Studio 7.7! https://docs.mulesoft.com/release-
notes/studio/anypoint-studio-7.7-with-4.3-runtime-release-notes
Take a Stand
Nominate yourself for the next meetup speaker and
suggest a topic as well.
What’s Next
• Share:
– Invite your network to join: https://meetups.mulesoft.com/vancouver/
• Feedback:
– Contact your organizers to suggest topics
– Contact MuleSoft at meetup@mulesoft.com for ways to improve the program
– Your feedback is fuel for us
• Our next meetup:
– Date: early Jan 2021
– Location: Virtual
– Topic: TBD
See you next time
Please send topic suggestions to the organizer

More Related Content

What's hot

81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programsAbhishek Jena
 
The Ring programming language version 1.8 book - Part 32 of 202
The Ring programming language version 1.8 book - Part 32 of 202The Ring programming language version 1.8 book - Part 32 of 202
The Ring programming language version 1.8 book - Part 32 of 202Mahmoud Samir Fayed
 
Flying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnightFlying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnightWiem Zine Elabidine
 
The Ring programming language version 1.6 book - Part 29 of 189
The Ring programming language version 1.6 book - Part 29 of 189The Ring programming language version 1.6 book - Part 29 of 189
The Ring programming language version 1.6 book - Part 29 of 189Mahmoud Samir Fayed
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaanwalia Shaan
 
Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)Ittay Dror
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to RAngshuman Saha
 
Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]Palak Sanghani
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 Mahmoud Samir Fayed
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212Mahmoud Samir Fayed
 
Transition graph using free monads and existentials
Transition graph using free monads and existentialsTransition graph using free monads and existentials
Transition graph using free monads and existentialsAlexander Granin
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++Bhavik Vashi
 
CIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comCIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comclaric130
 

What's hot (20)

81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
 
The Ring programming language version 1.8 book - Part 32 of 202
The Ring programming language version 1.8 book - Part 32 of 202The Ring programming language version 1.8 book - Part 32 of 202
The Ring programming language version 1.8 book - Part 32 of 202
 
C#
C#C#
C#
 
Flying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnightFlying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnight
 
The Ring programming language version 1.6 book - Part 29 of 189
The Ring programming language version 1.6 book - Part 29 of 189The Ring programming language version 1.6 book - Part 29 of 189
The Ring programming language version 1.6 book - Part 29 of 189
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
Sortings
SortingsSortings
Sortings
 
Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]
 
Javantura v6 - Kotlin-Java Interop - Matej Vidaković
Javantura v6 - Kotlin-Java Interop - Matej VidakovićJavantura v6 - Kotlin-Java Interop - Matej Vidaković
Javantura v6 - Kotlin-Java Interop - Matej Vidaković
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196
 
The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212
 
Transition graph using free monads and existentials
Transition graph using free monads and existentialsTransition graph using free monads and existentials
Transition graph using free monads and existentials
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
CIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comCIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.com
 

Similar to Review Complex DataWeave Transformations

Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...ikram_ahamed
 
Cis 115 Education Organization / snaptutorial.com
Cis 115 Education Organization / snaptutorial.comCis 115 Education Organization / snaptutorial.com
Cis 115 Education Organization / snaptutorial.comBaileya126
 
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseToronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseAlexandra N. Martinez
 
Cis 115 Education Organization -- snaptutorial.com
Cis 115   Education Organization -- snaptutorial.comCis 115   Education Organization -- snaptutorial.com
Cis 115 Education Organization -- snaptutorial.comDavisMurphyB99
 
CIS 115 Exceptional Education - snaptutorial.com
CIS 115   Exceptional Education - snaptutorial.comCIS 115   Exceptional Education - snaptutorial.com
CIS 115 Exceptional Education - snaptutorial.comDavisMurphyB33
 
Cis 115 Extraordinary Success/newtonhelp.com
Cis 115 Extraordinary Success/newtonhelp.com  Cis 115 Extraordinary Success/newtonhelp.com
Cis 115 Extraordinary Success/newtonhelp.com amaranthbeg143
 
Cis 115 Enhance teaching / snaptutorial.com
Cis 115  Enhance teaching / snaptutorial.comCis 115  Enhance teaching / snaptutorial.com
Cis 115 Enhance teaching / snaptutorial.comHarrisGeorg51
 
Introduction to-mongo db-execution-plan-optimizer-final
Introduction to-mongo db-execution-plan-optimizer-finalIntroduction to-mongo db-execution-plan-optimizer-final
Introduction to-mongo db-execution-plan-optimizer-finalM Malai
 
Introduction to Mongodb execution plan and optimizer
Introduction to Mongodb execution plan and optimizerIntroduction to Mongodb execution plan and optimizer
Introduction to Mongodb execution plan and optimizerMydbops
 
Cis 115 Effective Communication / snaptutorial.com
Cis 115  Effective Communication / snaptutorial.comCis 115  Effective Communication / snaptutorial.com
Cis 115 Effective Communication / snaptutorial.comBaileyao
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2ytoshima
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming languageLincoln Hannah
 
CIS 115 Education Specialist / snaptutorial.com
CIS 115  Education Specialist / snaptutorial.comCIS 115  Education Specialist / snaptutorial.com
CIS 115 Education Specialist / snaptutorial.comMcdonaldRyan138
 
CIS 115 Achievement Education--cis115.com
CIS 115 Achievement Education--cis115.comCIS 115 Achievement Education--cis115.com
CIS 115 Achievement Education--cis115.comagathachristie170
 
CIS 115 Education Counseling--cis115.com
CIS 115 Education Counseling--cis115.comCIS 115 Education Counseling--cis115.com
CIS 115 Education Counseling--cis115.comclaric59
 
CIS 115 Education in iCounseling ---cis115.com
CIS 115 Education in  iCounseling ---cis115.comCIS 115 Education in  iCounseling ---cis115.com
CIS 115 Education in iCounseling ---cis115.comclaric59
 
CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com  CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com williamwordsworth10
 
CIS 115 Redefined Education--cis115.com
CIS 115 Redefined Education--cis115.comCIS 115 Redefined Education--cis115.com
CIS 115 Redefined Education--cis115.comagathachristie208
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarkingAndrey Akinshin
 
The Ring programming language version 1.5.3 book - Part 27 of 184
The Ring programming language version 1.5.3 book - Part 27 of 184The Ring programming language version 1.5.3 book - Part 27 of 184
The Ring programming language version 1.5.3 book - Part 27 of 184Mahmoud Samir Fayed
 

Similar to Review Complex DataWeave Transformations (20)

Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
 
Cis 115 Education Organization / snaptutorial.com
Cis 115 Education Organization / snaptutorial.comCis 115 Education Organization / snaptutorial.com
Cis 115 Education Organization / snaptutorial.com
 
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseToronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
 
Cis 115 Education Organization -- snaptutorial.com
Cis 115   Education Organization -- snaptutorial.comCis 115   Education Organization -- snaptutorial.com
Cis 115 Education Organization -- snaptutorial.com
 
CIS 115 Exceptional Education - snaptutorial.com
CIS 115   Exceptional Education - snaptutorial.comCIS 115   Exceptional Education - snaptutorial.com
CIS 115 Exceptional Education - snaptutorial.com
 
Cis 115 Extraordinary Success/newtonhelp.com
Cis 115 Extraordinary Success/newtonhelp.com  Cis 115 Extraordinary Success/newtonhelp.com
Cis 115 Extraordinary Success/newtonhelp.com
 
Cis 115 Enhance teaching / snaptutorial.com
Cis 115  Enhance teaching / snaptutorial.comCis 115  Enhance teaching / snaptutorial.com
Cis 115 Enhance teaching / snaptutorial.com
 
Introduction to-mongo db-execution-plan-optimizer-final
Introduction to-mongo db-execution-plan-optimizer-finalIntroduction to-mongo db-execution-plan-optimizer-final
Introduction to-mongo db-execution-plan-optimizer-final
 
Introduction to Mongodb execution plan and optimizer
Introduction to Mongodb execution plan and optimizerIntroduction to Mongodb execution plan and optimizer
Introduction to Mongodb execution plan and optimizer
 
Cis 115 Effective Communication / snaptutorial.com
Cis 115  Effective Communication / snaptutorial.comCis 115  Effective Communication / snaptutorial.com
Cis 115 Effective Communication / snaptutorial.com
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
CIS 115 Education Specialist / snaptutorial.com
CIS 115  Education Specialist / snaptutorial.comCIS 115  Education Specialist / snaptutorial.com
CIS 115 Education Specialist / snaptutorial.com
 
CIS 115 Achievement Education--cis115.com
CIS 115 Achievement Education--cis115.comCIS 115 Achievement Education--cis115.com
CIS 115 Achievement Education--cis115.com
 
CIS 115 Education Counseling--cis115.com
CIS 115 Education Counseling--cis115.comCIS 115 Education Counseling--cis115.com
CIS 115 Education Counseling--cis115.com
 
CIS 115 Education in iCounseling ---cis115.com
CIS 115 Education in  iCounseling ---cis115.comCIS 115 Education in  iCounseling ---cis115.com
CIS 115 Education in iCounseling ---cis115.com
 
CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com  CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com
 
CIS 115 Redefined Education--cis115.com
CIS 115 Redefined Education--cis115.comCIS 115 Redefined Education--cis115.com
CIS 115 Redefined Education--cis115.com
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarking
 
The Ring programming language version 1.5.3 book - Part 27 of 184
The Ring programming language version 1.5.3 book - Part 27 of 184The Ring programming language version 1.5.3 book - Part 27 of 184
The Ring programming language version 1.5.3 book - Part 27 of 184
 

Recently uploaded

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Review Complex DataWeave Transformations

  • 1. Vancouver Canada 19th Nov 2020 Reviewing a Complex DataWeave Transformation Use-case
  • 2. Presenters,Organizers and You Vishal Aggarwal Yashwant Palkar Alexandra Martinez
  • 3. Alexandra Martinez Reviewing a Complex DataWeave Transformation Use-case
  • 4. 4 ● Functions (fun) ○ Parameters using types ○ Calling functions with 2 parameters ● Variables (var) ● do statement to create scopes (local variables) ● Object manipulation using object destructor {( )} ● If/else ● Selectors: ○ Index (array[0]) ○ Range (1 to 10) ● Setting default values ● Core functions/operators ○ isEmpty, reduce, map, groupBy, flatten ○ Remove (-), Sum (+), Concatenation (++), Prepend (>>) Solution will make use of the following:
  • 6. 6 Input JSON structure to Output JSON structure Requirement
  • 7. 7 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. Requirement 7
  • 8. 8 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. Requirement 8
  • 9. 9 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. 3. If the EndOfConnection field is true, create a separate output object. Requirement 9
  • 10. 10 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. 3. If the EndOfConnection field is true, create a separate output object. 4. If there are EndOfConnection fields that are true and this is not the last object inside the Connections array, create a new output object containing all the false Connection objects before this, and using this last object’s TaxCode. Requirement 10
  • 11. 11 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. 3. If the EndOfConnection field is true, create a separate output object. 4. If there are EndOfConnection fields that are true and this is not the last object inside the Connections array, create a new output object containing all the false Connection objects before this, and using this last object’s TaxCode. 5. Each AppliedConnections object in the output must have: 1. A hardcoded Type value “Connection”. Requirement 11
  • 13. 13 ● DW Playground: https://dwl.mule.club/ ● Input payload: {"FlightOptions":[{"Connections":[{"ReferenceID":111,"TaxCode":"ABC","EndOfConnection":false},{"ReferenceID":222,"TaxCode":"DEF","EndOfConnection":true}]},{" Connections":[{"ReferenceID":333,"TaxCode":"GHI","EndOfConnection":true},{"ReferenceID":444,"TaxCode":"JKL","EndOfConnection":true}]},{"Connections":[{"Ref erenceID":555,"TaxCode":"MNO","EndOfConnection":false},{"ReferenceID":666,"TaxCode":"PQR","EndOfConnection":false},{"ReferenceID":777,"TaxCode":"STU"," EndOfConnection":false}]},{"Connections":[{"ReferenceID":888,"TaxCode":"VWX","EndOfConnection":false}]},{"Connections":[{"ReferenceID":999,"TaxCode":"MNO" ,"EndOfConnection":false},{"ReferenceID":101,"TaxCode":"PQR","EndOfConnection":true},{"ReferenceID":102,"TaxCode":"STU","EndOfConnection":false}]}]} ● Expected output: [{"AppliedTaxCode":"DEF","AppliedConnections":[{"Type":"Connection","IndexValue":1},{"Type":"Connection","IndexValue":2}]},{"AppliedTaxCode":"GHI","AppliedCo nnections":[{"Type":"Connection","IndexValue":3}]},{"AppliedTaxCode":"JKL","AppliedConnections":[{"Type":"Connection","IndexValue":4}]},{"AppliedTaxCode":"STU ","AppliedConnections":[{"Type":"Connection","IndexValue":5},{"Type":"Connection","IndexValue":6},{"Type":"Connection","IndexValue":7}]},{"AppliedTaxCode":"VW X","AppliedConnections":[{"Type":"Connection","IndexValue":8}]},{"AppliedTaxCode":"PQR","AppliedConnections":[{"Type":"Connection","IndexValue":9},{"Type":"C onnection","IndexValue":10}]},{"AppliedTaxCode":"STU","AppliedConnections":[{"Type":"Connection","IndexValue":11}]}] ● Format JSONs: https://jsonformatter.curiousconcept.com/ Building the Solution
  • 14. 14 1) Extract the Connections arrays. Building the Solution
  • 15. 15 2) Change all the EndOfConnection to true for the last Connection object from the Connections array. Building the Solution
  • 16. 16 3) flatten the array of arrays to be just one array. Building the Solution
  • 17. 17 4) Add a new field to keep track of the object’s index, basing on the EndOfConnection field. (For each EndOfConnection=true, stop incrementing the index.) Building the Solution Index 1 Index 2 Index 1 Index 1 Index 1 Index 3 Index 2
  • 18. 18 5) Add a new field to keep track of the final AppliedConnections object’s (first) index where the object in question will be added. Note: This is calculated using the object’s index + 1 (to start at 1) and then minus the previously added indexBasedOnEOC field. Building the Solution Index 0 Index 2 Index 3 Index 4
  • 19. 19 6) Separate the objects based on the EndOfConnection value (true or false). Building the Solution
  • 20. 20 7) Take only the objects that are inside the “true” list. Building the Solution
  • 21. 21 8) Create the final output. Building the Solution
  • 22. Playing with the indexes
  • 23. 23 Playing with the indexes 1 2 1 1 1 2 3 1 1 1 2 Index based on EndOfConnection
  • 24. 24 Playing with the indexes Index based on EndOfConnection index + 1 1 3 4 5 2 6 7 8 9 10 11 1 2 1 1 1 2 3 1 1 1 2
  • 25. 25 Playing with the indexes Index based on EndOfConnection 1-1=0 3-1=2 4-1=3 5-1=4 2-2=0 6-2=4 7-3=4 8-1=7 9-1=8 10-2=8 11-1=10 1 2 1 1 1 2 3 1 1 1 2 AppliedConnections Index (index+1) - indexBasedOnEOC
  • 26. 26 Playing with the indexes Index based on EndOfConnection 0 2 3 4 0 4 4 7 8 8 10 1 2 1 1 1 2 3 1 1 1 2 1+0=1 2+0=2 1+2=3 1+3=4 1+4=5 2+4=6 3+4=7 1+7=8 1+8=9 2+8=10 1+10=11 AppliedConnections Index (index+1) - indexBasedOnEOC IndexValue indexBasedOnEOC (or actualIndex or actualNum) + indexAppliedConnections
  • 28. Code ● GitHub repository: https://github.com/alexandramartinez/reviewing-a-complex-dw- transformation-use-case/
  • 29. References ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-functions ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-variables ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-flow-control ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-selectors ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-defaults ● https://docs.mulesoft.com/mule-runtime/3.9/dataweave-operators ● https://docs.mulesoft.com/mule-runtime/4.3/dw-operators ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-isempty ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-reduce ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-map ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-groupby ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-flatten
  • 31. Quiz… Go to www.menti.com and use the code 5462238
  • 32. MuleSoft News for November • There is still time to register and submit a project for the MuleSoft Hackthon 2020! If you are interested in participating the deadline for register and submit is Nov 29, 2020 at 11:59 pm PT. https://www.mulesoft.com/hackathon2020 • Register and complete the free training course offered by MuleSoft Anypoint Platform Development: Fundamentals • The course prepares students to take the MuleSoft Certified Developer - Level 1 (Mule 4) exam. Upon successful completion of the course, students automatically receive two exam attempts. https://training.mulesoft.com/course/development-fundamentals-mule4 • Try out the new features of Anypoint Studio 7.7! https://docs.mulesoft.com/release- notes/studio/anypoint-studio-7.7-with-4.3-runtime-release-notes
  • 33. Take a Stand Nominate yourself for the next meetup speaker and suggest a topic as well.
  • 34. What’s Next • Share: – Invite your network to join: https://meetups.mulesoft.com/vancouver/ • Feedback: – Contact your organizers to suggest topics – Contact MuleSoft at meetup@mulesoft.com for ways to improve the program – Your feedback is fuel for us • Our next meetup: – Date: early Jan 2021 – Location: Virtual – Topic: TBD
  • 35. See you next time Please send topic suggestions to the organizer