如何根据 Azure 数据资源管理器/Kusto 中的子字符串匹配连接两个表?

How do you join two tables based on substring matches in Azure Data Explorer / Kusto?

我想根据 Fruit 中的单元格在 Things 中匹配的子字符串,通过连接这两个 table 来创建结果 table数据 table.

let Fruit = datatable(fruit:string) 
[
"apple", 
"banana" 
"orange" 
];
let Things = datatable(fruit:string) 
[
"anappletree",
"myoranges" 
];

我试过这样的事情:

Fruit
| join Things on $left.fruit contains $right.thing

但是得到这个错误:

Semantic Error 
join: only column entities or equality expressions are allowed in this context.

所以不能在这里使用contains

我要如何加入才能得到一个 table 包含

"apple" | "anappletree"
"banana" | ""
"orange" | "myoranges"

如果 join 的左侧(在您的情况下 - Fruit)足够小,您可以尝试使用 mv-apply:

let Fruit = datatable(fruit:string) 
[
    "apple", 
    "banana",
    "orange" 
];
let Things = datatable(thing:string) 
[
    "anappletree",
    "myoranges",
    "this is not a fruit"
];
let Fruit_list = toscalar(Fruit | summarize make_list(fruit));
Things
| mv-apply fruit = Fruit_list on (where thing contains fruit)
thing fruit
anappletree apple
myoranges orange

或者,由于 join 在撰写本文时仅支持相等性,您可以尝试使用交叉连接,然后使用 contains:

进行过滤
let Fruit = datatable(fruit:string) 
[
    "apple", 
    "banana",
    "orange" 
];
let Things = datatable(thing:string) 
[
    "anappletree",
    "myoranges",
    "this is not a fruit"
];
Fruit
| extend dummy = 1
| join kind=inner (Things | extend dummy = 1) on dummy
| where thing contains fruit
| project-away dummy*
fruit thing
apple anappletree
orange myoranges