是否可以使用 Azure 数据资源管理器修改引入映射中的数据?

Die*_*rez 5 azure kql azure-data-explorer

我正在尝试从 json 文件中获取数据并使用转换后的数据生成新列。

\n

我试图这样做,但找不到解决它的方法。

\n
.create table example ingestion json mapping "example_mapping" \n\n    '['\n        '{   "column":"timestamp", "Properties": {"Path":"$.timestamp"}},'\n        '{   "column":"rawValue", "Properties":{"Path":"$.rawValue"}},'\n        '{   "column":"Name", "Properties":{"Path":"$.Name"}},'\n        '{   "column":"Name1", "Properties":{"ConstantValue":"$.split(Name, "_")[1]"}},'\n        '{   "column":"Name2", "Properties":{"Path":"$[\\' split(Name, "_")[1]\\']"}},'\n        '{   "column":"Name3", "Properties":{"Path":"$[\\' split(Name, "_")[2]\\']"}},'\n        '{   "column":"Name4", "Properties":{"Path":"$[\\' split(Name, "_")[3]\\']"}},'\n        '{   "column":"Name5", "Properties":{"Path":"$[\\' split(Name, "_")[4]\\']"}},'\n        '{   "column":"Name6", "Properties":{"Path":"$[\\' split(Name, "_")[5]\\']"}},'\n        '{   "column":"Name7", "Properties":{"Path":"$[\\' split(Name, "_")[6]\\']"}},'\n        '{   "column":"Name8", "Properties":{"Path":"$[\\' split(Name, "_")[7]\\']"}},'\n        '{   "column":"RelevantData", "Properties":{"Path":"$[\\'RelevantData\\']"}}'\n    ']'\n
Run Code Online (Sandbox Code Playgroud)\n

Name1、2、3、4...是新列,我正在尝试执行splitsplit(Name, "_")[0]\n 操作以便在摄取映射中进行转换。

\n

\xc2\xbf有人知道这是否可能吗?欢迎提出建议。谢谢

\n

Dav*_*itz 1

简短回答:

不支持作为数据映射的一部分

详细解答:

JSONPath 表达式支持$.['property']or["property"][n]
映射转换围绕源文件信息(路径和行号)、 unix 时间(转换为日期时间)以及JSON 属性数组到字典的转换添加了一些附加功能。

解决方案:

这个逻辑可以通过更新策略来实现

聚苯乙烯

请注意数组的索引从0开始

演示:

创建临时表

.create table exampleStg (timestamp:datetime, rawValue:string, Name:string)
Run Code Online (Sandbox Code Playgroud)
// This will keep the staging table empty
.alter-merge table exampleStg policy retention softdelete = 0s
Run Code Online (Sandbox Code Playgroud)

创建决赛桌

.create table example (timestamp:datetime, rawValue:string, Name:string, Name1:string, Name2:string, Name3:string, Name4:string, Name5:string, Name6:string, Name7:string, Name8:string)
Run Code Online (Sandbox Code Playgroud)

创建一个函数来执行从临时表到最终表的数据转换。
请注意,在更新策略的上下文中,临时表名称代表一批新摄取的数据,而不是整个数据。

.create-or-alter function transform_exampleStg_to_example()
{
    exampleStg
    | extend Name_array = split(Name, "_")
    | extend Name1 = tostring(Name_array[0]), Name2 = tostring(Name_array[1]), Name3 = tostring(Name_array[2]), Name4 = tostring(Name_array[3])
    | extend Name5 = tostring(Name_array[4]), Name6 = tostring(Name_array[5]), Name7 = tostring(Name_array[6]), Name8 = tostring(Name_array[7])
    | project-away Name_array
}
Run Code Online (Sandbox Code Playgroud)

定义更新策略

.alter-merge table example policy update @'[{"IsEnabled": true, "Source": "exampleStg", "Query": "transform_exampleStg_to_example()", "IsTransactional": true, "PropagateIngestionProperties": true}]'
Run Code Online (Sandbox Code Playgroud)
.ingest inline into table exampleStg with (format="JSON") <|
{"timestamp":"2022-07-13 13:33:33","rawValue":"Hello","Name":"aaa_bbb_ccc_ddd_eee_fff_ggg_hhh"}
{"timestamp":"2022-07-14 14:44:44","rawValue":"world","Name":"aa_bb_cc_dd_ee_ff_gg_hh"}
Run Code Online (Sandbox Code Playgroud)
.ingest inline into table exampleStg with (format="JSON") <|
{"timestamp":"2022-07-15 15:55:55","rawValue":"!","Name":"a_b_c_d_e_f_g_h"}
Run Code Online (Sandbox Code Playgroud)
exampleStg
Run Code Online (Sandbox Code Playgroud)
时间戳 原始值 姓名

example
Run Code Online (Sandbox Code Playgroud)
时间戳 原始值 姓名 姓名1 姓名2 姓名3 姓名4 姓名5 姓名6 姓名7 姓名8
2022-07-13T13:33:33Z 你好 aaa_bbb_ccc_ddd_eee_fff_ggg_hhh 啊啊 bbb ccc 滴滴 伊伊 FF 格格 呵呵
2022-07-14T14:44:44Z 世界 aa_bb_cc_dd_ee_ff_gg_hh BB 抄送 DD FF gg 呵呵
2022-07-15T15:55:55Z a_b_c_d_e_f_g_h A C d e F G H