我有这样的桌子:
let tbl = datatable (metric:string, ct:int, details:dynamic)
[
"Some1",5, dynamic([
{
"Key": "NO",
"Value": 4
},
{
"Key": "CA",
"Value": 1
}
]),
"Some2",10, dynamic([
{
"Key": "GB",
"Value": 10
}])
];
以下数据:
metric | ct | details
-------------------------------------------------------------------------
Some1 | 5 | [{"Key":"NO","Value":4},{"Key":"CA","Value":1}]
Some2 | 10 | [{"Key":"GB","Value":10}]
我想把它缩减到决赛桌 (*):
metric | ct
----------------
Some1-NO | 4
Some1-CA | 1
Some1 | 5
Some2-BG | 10
Some2 | 10
我扩展了 k-v 对的集合,但我不知道如何取得进展以实现 (*.
metric | details | ct
-----------------------------------------
Some1 | 5 | {"Key":"NO","Value":4}
Some1 | 5 | {"Key":"CA","Value":1}
Some2 | 10 | {"Key":"GB","Value":10}
下一步/运营商可能是什么?
tbl
| mv-expand details
| ??
let tbl = datatable (metric:string, ct:int, details:dynamic)
[
"Some1" ,5 ,dynamic([{"Key": "NO", "Value": 4},{"Key": "CA", "Value": 1}])
,"Some2" ,10 ,dynamic([{"Key": "GB", "Value": 10}])
];
tbl
| mv-expand details = array_concat(details, pack_array(bag_pack("Value", ct)))
| project metric = strcat(metric, iff(isnull(details.Key), "", "-"), tostring(details.Key))
,ct = toint(details.Value)
公制 | ct |
---|---|
Some1-NO | 4 |
Some1-CA | 1 |
一些1 | 5 |
Some2-GB | 10 |
有些2 | 10 |
let tbl = datatable (metric:string, ct:int, details:dynamic)
[
"Some1" ,5 ,dynamic([{"Key": "NO", "Value": 4},{"Key": "CA", "Value": 1}])
,"Some2" ,10 ,dynamic([{"Key": "GB", "Value": 10}])
];
union
(tbl
| project metric, ct
)
,(tbl
| mv-expand details
| project metric = strcat(metric, "-", tostring(details.Key))
,ct = toint(details.Value)
)
公制 | ct |
---|---|
一些1 | 5 |
有些2 | 10 |
Some1-NO | 4 |
Some1-CA | 1 |
Some2-GB | 10 |