我希望我能够正确地表达这个问题,因为我对 kusto 很陌生。基本上我正在尝试编写一个 kusto 查询,该查询返回满足某些要求的字典。我有一个包含几列(名称、外部、父级)的表,目标是返回一个字典,其中键:名称,值:父级。然而,在某些情况下,“Parent”列为空,此时该值需要为:value:External。目前,我有一个查询在不同的行中返回两个字典,但我想知道是否可以将它们全部放在一个字典中。我希望我解释得很好,代码如下:
let Query1 = view () {
cluster('mycluster').database('my_database').Sizes
|distinct Name, Size, External
|where isempty( Size)| extend p = pack(Name, External)
|summarize dict=make_bag(p)};
let Query2 = view (){
cluster('mycluster').database('my_database').Sizes
|distinct Name, Size, External
|where not(isempty( Size))| extend o = pack(Name, Parent)
|summarize dict=make_bag(o)};
union withsource="TempTableName" Query1, Query2
代码返回:
TempTableName |
dict |
Query1 |
{B0:Standard,B12:Standard1,B13:Standard5 |
Query2 |
{B1:Basic0,B5:Basic09,B19:Basic12} |
I hope that I'm able to phrase this question properly as I am very new to kusto. Basically I am trying to write a kusto query that returns a dictionary where certain requirements are met. I have a table with several columns(Name, External, Parent) the goal is to return a dictioanary where key: Name , value: Parent. However there are some instances where the "Parent" column is blank, when this is true the value instead needs to be: value:External. Currently I have a query that returns two dictionaries in seperate rows, but I wanted to know if it is possible to have them all in one dictionary. I hope I explained this well, code is below:
let Query1 = view () {
cluster('mycluster').database('my_database').Sizes
|distinct Name, Size, External
|where isempty( Size)| extend p = pack(Name, External)
|summarize dict=make_bag(p)};
let Query2 = view (){
cluster('mycluster').database('my_database').Sizes
|distinct Name, Size, External
|where not(isempty( Size))| extend o = pack(Name, Parent)
|summarize dict=make_bag(o)};
union withsource="TempTableName" Query1, Query2
code returns:
TempTableName |
dict |
Query1 |
{B0: Standard, B12: Standard1, B13: Standard5 |
Query2 |
{B1:Basic0, B5: Basic09, B19: Basic12} |
发布评论
评论(1)
您可以使用
bag_merge()
函数:https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/bag-merge-function"B0": "标准",
"B12": "标准1",
"B13": "标准5",
"B1": "Basic0",
"B5": "Basic09 ",
"B19": "Basic12"
}
或者,使用您的查询:
you can use the
bag_merge()
function: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/bag-merge-function"B0": "Standard",
"B12": "Standard1",
"B13": "Standard5",
"B1": "Basic0",
"B5": "Basic09",
"B19": "Basic12"
}
or, with your query: