Azure. Kusto. 解析具有日期类型字段的 Json

huangapple go评论56阅读模式
英文:

Azure. Kusto. Parse Json with date type field

问题

I struggle with some strange behavior kusto query.

我遇到了一个奇怪的 Kusto 查询行为。

I logged json with field named date and ill try to get value from this field.

我记录了一个包含名为 date 的字段的 JSON,我尝试从这个字段中获取值。

I made a little POC and got two diferent behavior.

我创建了一个小的 POC(Proof of Concept)并获得了两种不同的行为。

When i called field as Date then the query executes fine. If I just rename it to date unfortunately I am not able to run the query.

当我将字段称为 Date 时,查询执行正常。但是,如果我只是将其重命名为 date,遗憾的是我无法运行查询。

Scenario 1.

场景 1.

Scenario 2.

场景 2.

How to handle with this query where fieldName equal date ?

如何处理这个字段名为 date 的查询?

Please see detailed descriptions.

请查看详细说明。

英文:

I struggle with some strange behavior kusto query.

I logged json with field named date and ill try to get value from this field.
I made a little POC and got two diferent behavior.
When i called field as Date then the query executes fine. If I just rename it to date unfortunately I am not able to run the query.

Scenario 1.

let T = datatable(MyString:string)
[
'{"Date":"2023-03-05T00:00:00.0000000Z","hour_start":"10:00","hour_end":"21:00","option":"recent"}'
];
T 
| project MyJson = parse_json(MyString)
| extend Date_ = tostring(MyJson.Date)

Scenario 2.

let T = datatable(MyString:string)
[
'{"date":"2023-03-05T00:00:00.0000000Z","hour_start":"10:00","hour_end":"21:00","option":"recent"}'
];
T 
| project MyJson = parse_json(MyString)
| extend Date_ = tostring(MyJson.date)

How to handle with this query where fieldName equal date ?

Please see detailed descriptions

答案1

得分: 0

看起来你触发了一个保留字。

使用 MyJson["date"](对于带有空格和/或特殊字符的标识符也是如此)。

请参阅[标识符引用][1]。

let T = datatable(MyString:string) [ '{"date":"2023-03-05T00:00:00.0000000Z","hour_start":"10:00","hour_end":"21:00","option":"recent"}' ];
T 
| project MyJson = parse_json(MyString) 
| extend Date_ = tostring(MyJson["date"])
MyJson Date_
{"date":"2023-03-05T00:00:00.0000000Z","hour_start":"10:00","hour_end":"21:00","option":"recent"} 2023-03-05T00:00:00.0000000Z

[Fiddle][2]


  [1]: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/schema-entities/entity-names#identifier-quoting
  [2]: https://dataexplorer.azure.com/clusters/help/databases/Samples?query=H4sIAAAAAAAAAz2OwQqCQBCG74LvMOxFhYrV6GJ06xR4ylMiYjqUIruyO0FSvXujS80MDPPPP8M3IEEOB2hr4rwOGGbTmUynbqldWgQFBC/BexSpSGSyXUuuXS5lutRGuriIlbjrh6ks1YbYG8/bn4iqnc9jM%20ROq1YMNigIvEJoNz7Xg6%2094bR6B4bgmw6Wa2YbayNxarn4Q8XLU58Ev%20FI7NV7CPtkEN3WTjoMvoCd%20UG2OQAAAA=


<details>
<summary>英文:</summary>

It seems you hit a reserved word.  

use `MyJson[&quot;date&quot;]` (same goes for identifiers with spaces and/or special characters).

See [Identifier quoting][1]

let T = datatable(MyString:string) [ '{"date":"2023-03-05T00:00:00.0000000Z","hour_start":"10:00","hour_end":"21:00","option":"recent"}' ];
T
| project MyJson = parse_json(MyString)
| extend Date_ = tostring(MyJson["date"])



|                                              MyJson                                               |            Date_             |
|---------------------------------------------------------------------------------------------------|------------------------------|
| {&quot;date&quot;:&quot;2023-03-05T00:00:00.0000000Z&quot;,&quot;hour_start&quot;:&quot;10:00&quot;,&quot;hour_end&quot;:&quot;21:00&quot;,&quot;option&quot;:&quot;recent&quot;} | 2023-03-05T00:00:00.0000000Z |



[Fiddle][2]


  [1]: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/schema-entities/entity-names#identifier-quoting
  [2]: https://dataexplorer.azure.com/clusters/help/databases/Samples?query=H4sIAAAAAAAAAz2OwQqCQBCG74LvMOxFhYrV6GJ06xR4ylMiYjqUIruyO0FSvXujS80MDPPPP8M3IEEOB2hr4rwOGGbTmUynbqldWgQFBC/BexSpSGSyXUuuXS5lutRGuriIlbjrh6ks1YbYG8/bn4iqnc9jJ%20mROq1YMNigIvEJoNz7Xg6%2094bR6B4bgmw6Wa2YbayNxarn4Q8XLU58Ev%20FI7NV7CPtkEN3WTjoMvoCd%20UG2OQAAAA=

</details>



huangapple
  • 本文由 发表于 2023年2月24日 16:06:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553992.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定