11_DataWeave Flashcards

1
Q

By default, where is the dataweave code?

A

inline in the Mule configuration file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where is sample data used for live preview stored?

A

src/test/resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where are the dwl files stored?

A

src/main/resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

dwl stand for?

A

data weave language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Where in the Transform Message component can you reference to use an external DWL file?

A

resource attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where in an element that has an expression property (e.g. choice router), can you use reference to an external DWL file?

A

using syntax ${file::filename}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can you create modules (libraries) of reusable Dataweave functions?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you create multiple transformations with one Transform Message Component?

A
  1. Add new target button (lines and a plus sign), 2. Set where to store result (Variables or Attributes or…) 3. Switch between multiple transformation (click on the dropdown.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The data model of the produced output of the dataweave expression could consist of what 3 data types?

A

Object. Array. Simple literals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an object?

A

Key : value pairs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an Array?

A

A sequence of comma separated values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is a dataweave expression separated into header and body?

A

Delimiter to separate header and body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the header of a dwl file contain?

A

directives that apply to the body expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the body of a dwl file contain?

A

DataWeave expression that generates the output structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give some example mime type (formats) that the script will output

A

application/json, application/java, application/xml, text/plain, application/dw, application/csv, application/xlsx, …

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the 2 types of DataWeave errors?

A

Scripting errors (syntax problems) and Formatting errors (a problem with how the transformation takes one format to another, there could be an issue if you are outputting an XML but the structure does no have a single root node))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

If you get an error what can you do to check what type of error it is?

A

transform the input to application/dw, then if the transformation is successful it’s likely to be a formatting error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Dataweave syntax for a applcation/json output, fname: payload.firstname and {fname: payload.firstname} produce what outputs (if the firstname in the payload is “RayJones”?

A

{fname: “RayJones”} and {fname: “RayJones”}

same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does an XML file need?

A

A root level (and only one).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Will this dwl code with an application/xml output write? — fname: payload.first, lname: payload.last

A

No, as it doesn’t have a one top-level value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do you specify an attribute for an XML output? (you can have multiple attributes within the brackets).

A

@(attName: attValue)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Are attributes written to XML output as default?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

XML input has an attribute ? Output application/json. What is the dataweave syntax to access the attribute?

A

payload.name.@initials
(which would give you
“ww”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

When using the map function what can the input array be?

A

JSON or Java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does a map function do to an array?

A

IT takes each element in the array and applies the transformation function (or lambda function)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does the map function return?

A

An array. (just think, if you are inputting an array and taking every value and transforming each value, it puts it back in the array).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Where is the transformation function used?

A

In the map function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Within the transformation function what does the $ refer to?

A

value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Within the transformation function what does the $$ refer to?

A

Index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

In dwl where can you find the syntax $.firstname

A

Within the transformation function (therefore, in the map function)

31
Q

What does the $$ in the transformation function start from?

A

0 (index starts at 0, think it’s handling arrays - so makes sense)

32
Q

What is payload map (object, index) -> { num: index, fname:object.fname} the same syntax as?

A

payload map (num: $$, fname: $.firstname)

33
Q

What does wrapping Java/JSON array elements with {()} do?

A

If the output is application/xml, then it will convert the array to an XML object

34
Q

How do you change a Java/JSON array to application/xml?

A

You have to wrap the map operation in the {()}. If you do not do so, the array will error ‘Cannot coerce an array object’).

35
Q

You can wrap the elements either around the map function or around the map operation, true or false?

A

true

36
Q

What do you use the .* selector for?

A

To reference repeated elements.

37
Q

How do you reference repeated elements?

A

Use the .* selector.

38
Q

If you are converting XML to JSON and dwl has the payload.lname whilst there are repeated tags of the lname, what is the JSON output?

A

lname (and only the first value. If you want to have all the repeated references you need to include the .*

39
Q

XML -> JSON: What is the output if the input is (

Mule

Jennet

). DWL code: payload.users.*user map (obj,index) -> {
fname: obj.@firstname,
lname: obj.lastname
}

A

[
{“fname”: “Max”, “lname”: “Mule” },
{“fname”: “Molly”, “lname”: “Jennet” }
]

40
Q

Where can global variables can be referenced?

A

anywhere in the body

41
Q

Where should you use the var directive in the dwl code?

A

In the header.

42
Q

What does the dwl code (var name) = “the” do?

A

states the global variable name to the, which can be used throughout the body of the code (acts as functional programming language).

43
Q

What does the code (var name = () -> “wow”) ?

A

When you call the variable name, with the name() it will replace it with “wow”.

44
Q
What does the dwl code produce, if the input is {"lname": "plants"} and the dwl has (output application/xml
var mname = "the"
var mname2 = () -> "other"
var lname = (aString) -> upper(aString)
---
name: {
first: payload.firstname,
middle1: mname, middle2: mname2(),
last: lname(payload.lastname)
})?
A

plants
the
other
PLANTS

45
Q

What are the 2 different types of syntax for accessing lambda expressions within dataweave?

A

I think it’s referring to the var and fun. ??? check

46
Q

What is the 2 alternative syntaxs to access lambda expressions?

A
var functionName = (aString) -> function(aString)
OR 
fun functionName(aString) = function(aString)
47
Q

Where can you use the keyword using?

A

in the body of the dwl code

48
Q

Where can local variables be referenced?

A

In the scope of the expression where they are initialized

49
Q

json -> json
What does this dwl code output? using (fname = payload.firstname, lname = payload.lastname) { person: using (user = fname, color = “gray”) { name1: user, color: color }, name2: lname, color: color }

A

Unable to resolve reference of color.

50
Q

Explain using ( = )

A

It is a local variable that can only be referenced within the scope that it is initialized. e.g. using (fname = “I’m” ++ payload.firstname) { You can use it here } You can’t use it here.

51
Q

How do you format data?

A

{format: “”} (and in between the quotation marks you add in the format you’d like to output)

52
Q

If you want to change the data type, what operation do you use?

A

as (e.g. as Number, as String)

53
Q

How do you define a custom data type?

A

using the type header directive (name has to be all lower case, no special chars, or numbers)

54
Q

What is this dwl code doing? (type = ourdateformat = DateTime {format: “yyyyMMddHHmm”})

A

This is setting a custom data type named ‘ourdateformat’, which is a DateTime with the format ‘yyyyMMddHHmm’.

55
Q

You’ve created a custom data type called sweetpotato, you want to use it in the body of the dwl code, how do you use it?

A

payload.normalPotato as sweetpotato

56
Q

What does POJO stand for?

A

Plain old java object

57
Q

2 ways to transform an oject to a POJO?

A
  1. specify inline

2. define a custom data type and use that instead

58
Q

Define a custom data type to transform an object to a POJO

A

type custompojo = Object {class: “”}

customer: payload.blah as custompojo

(the type is defining the custom data type, the custompojo is the name of the custom data type, Object is datatype with the class stating what java class it should be) —-(the last statement is changing the field blah from the payload to a pojo)

59
Q

Define how to transorm an object to a POJO by specifying inline.

A

customer: payload.blah as Object {class: “”}

think POJO - java - class, as it will need a class… think think think

60
Q

What are dw functions packaged into?

A

modules

61
Q

What functions are automatically imported into dataweave scipts?

A

core modules

62
Q

Functions that have 2 params, have 2 alternative syntax, what are they?

A

[contains (payload, max)] OR #[payload contains “max”]

the function here being the contains
e.g. #[function(param1, param2)] OR #[param1 function “param2”]

63
Q

When using a series of functions, how are they executed?

A

From the right to the left (the last function in the chain is executed first)

64
Q

How do you get something that is an expression using the map function to be evaluated first if it’s at the beginning of a series of functions

A

You can use the ‘using’ to define it as a local variable.

65
Q

How do you import a function in a module?

A

import functionName from dw::core::module

66
Q

How do you import a module

A

import dw::core:module

basically import module name

67
Q

What does the dasherize(String) function do?

A

replaces spaces, underscores and camel-casing in a string with dashes (hyphens).

68
Q

How do you call a flow in dwl?

A

Use the lookup function

lookup(“flowName”, payload)

69
Q

Can you call sub flows in dwl using the lookup?

A

No.

70
Q

What does the lookup function return?

A

Whatever the payload the flow returns is what the expression returns

71
Q

What is a lambda?

A

An anonymous function not bound to an identifier.

72
Q

What is at the top of the precendence order before binary functions?

A

using() function

73
Q

What header is used to import functions?

A

import

74
Q

What does the as Object {class: “”} syntax denote?

A

transforming objects to POJOs