通过在 KQL/Kusto/Data Explorer 中添加字符串来重命名所有列名称

Rename all column names by adding a string in KQL/Kusto/Data Explorer

我加入了 2 个 table,它们都有数百个名称相似的列。我想更改每个 table 中的所有列名称以包含 table 名称。为了使查询简单,我不想 明确指出每个列名。有没有办法将 table 名称附加到所有列名称而不显式调用每一列?

例如:

let T1 = datatable (Key:string , Col2:string , Col3:string )[
"1", "b", "c",
"2", "e", "f",
"3", "h", "i"];
let T2 = datatable (Key:string , Col2:string , Col3:string )[
"1", "B", "C",
"2", "E", "F",
"4", "H", "I"];
T1 | join T2 on Key

结果:

Key Col2 Col3 Key1 Col21 Col31
1   b    c    1    B     C
2   e    f    2    E     F

想要的结果:

T1.Key T1.Col2 T1.Col3 T2.Key T2.Col2 T2.Col3
1      b       c       1      B       C
2      e       f       2      E       F

如果列的顺序对您不重要,那么这是一种方法:

let T1 = datatable (Key:string , Col2:string , Col3:string )
[
  "1", "b", "c",
  "2", "e", "f",
  "3", "h", "i"
] 
| project PackedRecord = todynamic(replace_regex(tostring(pack_all()), '"([a-zA-Z0-9_]*)":"', @'"T1_":"'))
| evaluate bag_unpack(PackedRecord);
let T2 = datatable (Key:string , Col2:string , Col3:string )
[
  "1", "B", "C",
  "2", "E", "F",
  "4", "H", "I"
] 
| project PackedRecord = todynamic(replace_regex(tostring(pack_all()), '"([a-zA-Z0-9_]*)":"', @'"T2_":"'))
| evaluate bag_unpack(PackedRecord);
let JoinTable = T1 | join kind=inner T2 on $left.T1_Key == $right.T2_Key;
JoinTable

结果:

T1_Col2 T1_Col3 T1_Key T2_Col2 T2_Col3 T2_Key
b c 1 B C 1
e f 2 E F 2

如果要对列重新排序,可以使用project-reorder