将定制量分为3个JSON,然后使用Kusto查询进行项目

发布于 2025-02-07 00:50:54 字数 1387 浏览 3 评论 0原文

因此,我有一个kusto查询,

requests
| where customDimensions has'Scope' and customDimensions['Scope'] != 'Unauthenticated' and cloud_RoleName == 'cloud1'
| project x = tostring(customDimensions['x'], y = tostring(customDimensions['y'] ...

我希望将我的codedimensions值分为3个JSON。 然后将其投影,

| project json1 = json1, json2 = json2, json3 = json3

但我无法分组/拆分我尝试过的动态的定制量,但它们不将变量作为输入 对于Eg dynamic_to_json(dynamic({'x':customDimensions ['x']})))对数据表错误的错误抛出了

上述语句给出的错误应该以'结尾的错误。 }'显然我的语法是正确的。我觉得它某种程度上无法访问动态或数据表中的定制变量,

任何人都可以指导我。.

我希望输出,因为

| json1 | json2 | json3 |
|{...}  | {...} | {...} |

所有3个JSON都将从同一表的自定义限制或其他列创建;

关于定制范围 https://camerondwyer.com/2020/05/05/26/how-to-to-use-application-ingights-custom-custom-properties-in-azure-monitor-monitor-monitor-log-kusto---------------------------------- kusto-queries/

假设定制中有任何事情

customDimensions = {x:X, y:Y, a:A, ...}
json1 should have {x, y z}
json2 should have {r, t, p,}
json3 should have {w, m, n}

So, I have a Kusto query

requests
| where customDimensions has'Scope' and customDimensions['Scope'] != 'Unauthenticated' and cloud_RoleName == 'cloud1'
| project x = tostring(customDimensions['x'], y = tostring(customDimensions['y'] ...

i want the split my customDimensions values into 3 jsons.
then project it as

| project json1 = json1, json2 = json2, json3 = json3

but i not able to group/split the customDimensions i tried dynamic, datatable but they dont take variables as inputs
for e.g dynamic_to_json(dynamic({'x': customDimensions['x'] })) throws an error same for the data tables

Error that the above statement gives is it should end with '}' where clearly my syntax is correct. i feel it somehow does not accesses the customDimensions variable inside dynamic or datatable

could anyone please guide me on this..

I want the output as

| json1 | json2 | json3 |
|{...}  | {...} | {...} |

all the 3 json's will be created from customDimensions or other columns of the same table;

about customDimensions https://camerondwyer.com/2020/05/26/how-to-use-application-insights-custom-properties-in-azure-monitor-log-kusto-queries/

assume there is any thing in customDimensions like

customDimensions = {x:X, y:Y, a:A, ...}
json1 should have {x, y z}
json2 should have {r, t, p,}
json3 should have {w, m, n}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2025-02-14 00:50:54

在与@Sandeep Ranjan进行了对话之后:

这里的挑战是从存储为动态的JSON文档中提取字段,然后将它们包装到3个新的JSON文档中。

提取字段很简单,e,g。:

customDimensions.myfield

customDimensions["myfield"]

以后的字段名称具有空格和/或特殊字符的字段名称,例如:

customDimensions["my field"]
customDimensions["my-field!"]

包装字段可以使用3种不同的函数来完成彼此的同义词。
这些功能是 pack()& bag_pack(

) :

let requests = datatable(customDimensions:dynamic) [dynamic({"x":1, "y":2, "z":3, "a":"hello", "b":"world", "k1":"v1", "k2":"v2", "k3":"v3", "k4":"v4"})];
requests
| project-rename cd = customDimensions // just to make things a little bit shorter
| extend json_1 = pack_dictionary("x",cd .x, "y", cd.y, "z", cd.z)
| extend json_2 = pack_dictionary("a", cd.a, "b", cd.b)
| extend json_3 = pack_dictionary("k1", cd.k1, "k2", cd.k2, "k3", cd.k3, "k4", cd.k4)
cdjson_1json_2json_3
{“ x”:1,“ y”:2,“ z”:3,“ a”:“ hello”,“ b”:“ world”,“ k1”:“ v1”,“ k2 “:” v2“,“ k3”:“ v3”,“ k4”:“ v4”}{“ x”:1,“ y”:2,“ z”:3}{“ a”:“ hello”, “ b”:“ world”}{“ k1”:“ v1”,“ k2”:“ v2”,“ k3”:“ v3”,“ k4”:“ v4”}

小提琴

Following a conversation with @Sandeep Ranjan:

The challenge here was to extract fields from a JSON document stored as dynamic and then pack them together to 3 new separate JSON documents.

Extracting fields is straightforward, E,g.:

customDimensions.myfield

or

customDimensions["myfield"]

The later can be used for fields names with spaces and/or special characters, E.g.:

customDimensions["my field"]
customDimensions["my-field!"]

Packing the fields can be done with 3 different functions that are synonyms to each other.
Those functions are pack_dictionary(), pack() & bag_pack()

Here is a quick sample:

let requests = datatable(customDimensions:dynamic) [dynamic({"x":1, "y":2, "z":3, "a":"hello", "b":"world", "k1":"v1", "k2":"v2", "k3":"v3", "k4":"v4"})];
requests
| project-rename cd = customDimensions // just to make things a little bit shorter
| extend json_1 = pack_dictionary("x",cd .x, "y", cd.y, "z", cd.z)
| extend json_2 = pack_dictionary("a", cd.a, "b", cd.b)
| extend json_3 = pack_dictionary("k1", cd.k1, "k2", cd.k2, "k3", cd.k3, "k4", cd.k4)
cdjson_1json_2json_3
{"x":1,"y":2,"z":3,"a":"hello","b":"world","k1":"v1","k2":"v2","k3":"v3","k4":"v4"}{"x":1,"y":2,"z":3}{"a":"hello","b":"world"}{"k1":"v1","k2":"v2","k3":"v3","k4":"v4"}

Fiddle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文