Transformations
Transformations process the result of the inner sources before it is passed to the dataset or to the next transformation.
1
"dataset": {
2
"type": "transformation-1",
3
// Transformations always take a list of sources
4
// Even if only one is used
5
"sources": [
6
{
7
// Transformations can be chained
8
"type": "transformation-2"
9
"sources": [
10
{
11
// End the end we have one more
12
// query data sources
13
"type": "OTQL"
14
...
15
}
16
]
17
}
18
]
19
}
Copied!

to-list

This puts multiple numbers from multiple queries into a key / value dataset. It is important to set the key of each number with the series_title property. It takes from one to any number of sources.
1
"dataset": {
2
"type": "to-list",
3
"sources": [
4
{
5
"type": "OTQL",
6
"query_id": "666", // SELECT @count{} FROM UserPoint WHERE...
7
"series_title": "Unknown"
8
},
9
{
10
"type": "OTQL",
11
"query_id": "777", // SELECT @count{} FROM UserPoint WHERE...
12
"series_title": "With online account"
13
},
14
{
15
"type": "OTQL",
16
"query_id": "888", // SELECT @count{} FROM UserPoint WHERE...
17
"series_title": "With fidelity program"
18
}
19
]
20
}
Copied!

join

This joins two key / value datasets into a key / values dataset. It is important to set the name of each series with the series_title property. It takes from one to any number of sources.
1
"dataset": {
2
"type": "join",
3
"sources": [
4
{
5
"type": "OTQL",
6
"query_id": 666, // Select {interests @map} FROM UserPoint WHERE...
7
"series_title": "Unkwnown"
8
},
9
{
10
"type": "OTQL",
11
"query_id": 777, // Select {interests @map} FROM UserPoint WHERE...
12
"series_title": "With fidelity program"
13
}
14
]
15
}
Copied!

to-percentages

This calculates the representation of each value in the complete dataset. Only one sources is accepted.
You usually want to use the format: percentage option of the associated data visualisation to automatically change the labels and tooltips and formats to display percentage% (count)
1
"type": "Radar",
2
"dataset": {
3
"type": "to-percentages",
4
"sources": [{
5
"type": "OTQL",
6
"query_id": 666 // Select {interests @map} FROM UserPoint WHERE...
7
}]
8
},
9
"options": {
10
"format": "percentage"
11
}
Copied!

ratio

This calculates the ratio between two numbers (source 1 / source 2 * 100). It only accepts two sources that should each return numbers.
1
"dataset": {
2
"type": "ratio",
3
"sources": [
4
{
5
"type": "OTQL",
6
"query_id": "666" // SELECT @count{} FROM UserPoint WHERE...
7
}, // Returns 100k
8
{
9
"type": "OTQL",
10
"query_id": "777" // SELECT @count{} FROM UserPoint
11
} // Returns 200k
12
]
13
}
14
// Result is 100k/200k*100 = 50
Copied!

index

This calculates the representation of values from a key / value dataset in comparison to an other key / value dataset.
For example, if 10% of the users in a segment viewed content associated with tag 1, while 5% of the users in the whole datamart viewed content associated with this same tag, the index of tag 1 in segment in comparison to the whole datamart is 10 / 5 * 100 = 200.
This is typically used to see which values are more/less represented in the first data source compared to the second one. An index above 100 means the value is more represented in the first data source than in the second, a value under 100 means the value is less represented in the first data source than in the second.
This is usually represented in a Bars chart with a plot_line_value of 100 and an index format :
For each value in the first dataset, it automatically calculates its percentage representation in the first and the second source, then does the formula source value (in percentages) / comparison value (in percentages) * 100 .
1
"type": "Bars",
2
"dataset": {
3
"type": "index",
4
// Use limits like "limit:20" wisely
5
// as the index will be calculated for each return value, then ordered.
6
// If you only do a @map with a limit of 10 elements returned and you are asking
7
// to show the top 10 indexes, you will have the top 10 indexes from the top 10 values
8
// A value could be in position 20 by numbers, but in position 2 by index
9
"sources": [
10
{
11
// This query adapts to the current segment
12
"type": "OTQL",
13
"query_id": 666, // SELECT {interests @map} FROM UserPoint
14
"series_title": "Segment"
15
},
16
{
17
// Same query without adapting to the current segment
18
// and always returns data for the whole datamart
19
"type": "OTQL",
20
"query_id": 666,
21
"series_title": "Datamart"
22
"adapt_to_scope": false
23
}
24
],
25
"options": {
26
"limit": 10 // Number of elements to display. 10 by default
27
"order": "Ascending" | "Descending" // Descending by default
28
// This means that indexes will only be calculated for values
29
// representing 0.65% of values in source 1.
30
"minimum_percentage" : 0.65 // 0 by default. Values between 0 and 100
31
}
32
},
33
"options": {
34
"type": "bar",
35
"plotLineValue": 100,
36
"format": "index" // So that the index is correctly displayed in tooltips
37
}
Copied!

format-dates

This formats timestamps and date fields to the specified date format. Available date formats are Moment.js date formats.
Use this transformation to allow the display of friendly dates to the user or to allow joining multiple data sources into the same dataset by putting returning dates in the same format.
1
"dataset": {
2
"type": "format-dates",
3
"sources": [ // Only one source allowed
4
{
5
"type": "OTQL",
6
"query_id": "666" // SELECT {date @date_histogram} FROM UserEvent WHERE...
7
},
8
],
9
"date_options": {
10
"format": "YYYY-MM-DD"
11
}
12
}
Copied!
Dates must be in the 2021-11-05T00:00:00.000Z format or in timestamp to be formatted. Typical compatible queries are :

reduce

This transforms a key / value or key / values dataset into a single number to be displayed in Metric charts.
  • avg calculates the average of values
  • count calculates the number of values
  • first returns the first value
  • last returns the last value
  • max returns the maximum value
  • min returns the minimum value
  • sum returns the sum of all values
1
"type": "Metric",
2
"dataset": {
3
"type": "reduce",
4
"sources": [{
5
"type": "OTQL",
6
"query_id": 666 // Select {interests @map} FROM UserPoint WHERE...
7
}],
8
"reduce_options": {
9
// avg || count || first || last || max || min || sum
10
"type": "count"
11
}
12
},
Copied!

get-decorators

This transforms identifiers such as channel IDs, compartment IDs and segment IDs into the corresponding channel names, compartment names and segment names.
1
// This returns channel IDs associated with the value
2
"dataset":
3
{
4
"type": "OTQL",
5
"query_id": "666" // SELECT {channel_id @map} FROM UserEvent WHERE...
6
}
7
}
8
9
// This returns channel names associated with the value
10
"dataset": {
11
"type": "get-decorators",
12
"sources": [ // Only one source allowed
13
{
14
"type": "OTQL",
15
"query_id": "666" // SELECT {channel_id @map} FROM UserEvent WHERE...
16
},
17
],
18
"decorators_options": {
19
"model_type": "CHANNELS", // CHANNELS || COMPARTMENTS || SEGMENTS
20
// Optional if the data source returns sub buckets,
21
// to define the transformation for those sub buckets
22
"buckets": {
23
// Recursive
24
"buckets": {
25
"model_type": "SEGMENTS"
26
}
27
}
28
}
29
}
Copied!