1

Kusto 中是否有任何方法可以用来替换 Kusto 中动态值中特定键的值?如果需要,替换值甚至删除整个键值对?

更新

假设我们在表格中有以下动态值:-

   { 
      "SectionA":{ 
                 "Prop1":"abcd",
                 "Prop2":"efgh",
                 "Prop3":"ahd32",
                 "category":"main"
                 },
      "Num1":1.33,
      "Num2":33.8,
      "City":"New York"
    }

现在我想摆脱键的键值对,Num1以便生成的输出如下:-

   { 
      "SectionA":{ 
                 "Prop1":"abcd",
                 "Prop2":"efgh",
                 "Prop3":"ahd32",
                 "category":"main"
                 },
      "Num2":33.8,
      "City":"New York"
    }

如果这是不可能的,即使以下屏蔽也可以作为解决方案,通过屏蔽我的意思是每当键 Num1 出现在动态值中时,它将为所有行分配一个固定值(在本例中为 0):-

  { 
      "SectionA":{ 
                 "Prop1":"abcd",
                 "Prop2":"efgh",
                 "Prop3":"ahd32",
                 "category":"main"
                 },
      "Num1":0,
      "Num2":33.8,
      "City":"New York"
    }

该值可以是任何字符串或数字,在此示例中我使用了数字,但这可以是任何值。

4

3 回答 3

2

更新:

let t = datatable(mystring:string)
[
'
{     "SectionA":{ 
                 "Prop1":"abcd",
                 "Prop2":"efgh",
                 "Prop3":"ahd32",
                 "category":"main"
                 },
      "Num1":180,           
      "Num2":33.8,
      "City":"New York"
}
'
];
t
| project myjson = parse_json(mystring)
| project Num2=tostring(myjson.Num2), City=tostring(myjson.City), SectionA=tostring(myjson.SectionA)
| extend newColumn=strcat("\"City\":","\"",City,"\", \"Num2\":","", Num2,", \"SectionA\":","", SectionA) 

结果:

在此处输入图像描述


请尝试下面的代码,看看它是否可以解决问题:

let t = datatable(mystring:string)
[
'
{     "SectionA":{ 
                 "Prop1":"abcd",
                 "Prop2":"efgh",
                 "Prop3":"ahd32",
                 "category":"main"
                 },
      "Num1":180,           
      "Num2":33.8,
      "City":"New York"
}
'
];
t
| project myjson = parse_json(mystring)
| project Num2=tostring(myjson.Num2), City=tostring(myjson.City), SectionA=tostring(myjson.SectionA)

结果:

在此处输入图像描述

于 2020-01-10T06:31:04.283 回答
2

在 Kusto 动态字典 \ bag 中使用未知键(或在查询中列出的键太多)设置值的另一种方法是使用新bag_merge函数:

let t = dynamic({ 
      "SectionA":{ 
                 "Prop1":"abcd",
                 "Prop2":"efgh",
                 "Prop3":"ahd32",
                 "category":"main"
                 },
      "Num1":1.33,
      "Num2":33.8,
      "City":"New York"
    });

print bag_merge(dynamic({"Num1":0}), t)

在此处输入图像描述

于 2020-06-11T07:55:30.237 回答
0

bag_remove_keys ()函数从动态属性包中删除键和相关值。唯一的限制是不支持嵌套级别上的键。

datatable(input:dynamic) [
    dynamic({ 
        "SectionA":{ 
                    "Prop1":"abcd",
                    "Prop2":"efgh",
                    "Prop3":"ahd32",
                    "category":"main"
                    },
        "Num1":1.33,
        "Num2":33.8,
        "City":"New York"
    }) ] | extend result=bag_remove_keys(input, dynamic(['Num1']))
于 2020-12-07T15:58:28.840 回答