'Projectig certain sub documents in Kusto
I have a timeseries data which looks like follows
"data": {
"a": {
"T": [
1652167964645,
1652168781684,
1652168781720,
1652169266156,
1652169267146,
1652169272796,
1652169299338
],
"V": [
1,
2,
3,
10,
6,
1252,
1555
]
},
"b": {
"T": [
1652167961657,
1652168781720,
1652168781818,
1652168787377,
1652168835734,
1652169266108,
1652169266125,
1652169272798,
1652169299328
],
"V": [
1,
3,
4,
6,
12,
15,
16,
17,
1
]
},
"c": {
"T": [
1652167960194,
1652168787377,
1652169266108,
1652169272798,
1652169299328
],
"V": [
1,
3,
17,
18,
1
]
}}
inside the sub documents there are time and values I can process the data in total. but if I want tp process only two sub document how can i do that ?
I can project like following
| project data["a"],data["b"] but then I can not process the time. how can i accomplish it ?
Expected output:
One column with time, and other column ( i.e a, b ) for the values
Time , A , B
0:55, 1,2
Solution 1:[1]
let requested_columns = dynamic(["a","b"]);
datatable(data:dynamic)
[
dynamic
(
{
"a": {
"T": [
1652167964645,
1652168781684,
1652168781720,
1652169266156,
1652169267146,
1652169272796,
1652169299338
],
"V": [
1,
2,
3,
10,
6,
1252,
1555
]
},
"b": {
"T": [
1652167961657,
1652168781720,
1652168781818,
1652168787377,
1652168835734,
1652169266108,
1652169266125,
1652169272798,
1652169299328
],
"V": [
1,
3,
4,
6,
12,
15,
16,
17,
1
]
},
"c": {
"T": [
1652167960194,
1652168787377,
1652169266108,
1652169272798,
1652169299328
],
"V": [
1,
3,
17,
18,
1
]
}
}
)
]
| mv-expand data
| extend key = tostring(bag_keys(data)[0])
| where key in (requested_columns)
| mv-expand T = data[key].T to typeof(long), V = data[key].V to typeof(long)
| evaluate pivot(key, take_any(V), T)
| order by T asc
| T | a | b |
|---|---|---|
| 1652167961657 | 1 | |
| 1652167964645 | 1 | |
| 1652168781684 | 2 | |
| 1652168781720 | 3 | 3 |
| 1652168781818 | 4 | |
| 1652168787377 | 6 | |
| 1652168835734 | 12 | |
| 1652169266108 | 15 | |
| 1652169266125 | 16 | |
| 1652169266156 | 10 | |
| 1652169267146 | 6 | |
| 1652169272796 | 1252 | |
| 1652169272798 | 17 | |
| 1652169299328 | 1 | |
| 1652169299338 | 1555 |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
