如何基于同名但不同数据类型的列连接两个Kusto表?
解决Kusto不同数据类型列的表连接问题
核心思路是将int64类型的列转换为string类型进行匹配,避免string转int时因数值溢出导致的数值改变问题(Kusto中int是32位整数,若string中的电话号码超过其范围,转换会丢失精度)。
修改后的查询语句
将table_2的phone_number(int64类型)通过tostring()函数转为string类型后再连接:
table_1 | project name, phone_number | join kind=fullouter ( table_2 | project name, phone_number = tostring(phone_number) ) on $left.name == $right.name and $left.phone_number == $right.phone_number
额外处理场景(可选)
如果table_1的string类型phone_number包含非数字字符(如(123) 456-7890这类格式),需要先清洗字符串,移除非数字字符后再匹配:
table_1 | project name, phone_number = replace_all(phone_number, @'[^\d]', '') // 移除所有非数字字符 | join kind=fullouter ( table_2 | project name, phone_number = tostring(phone_number) ) on $left.name == $right.name and $left.phone_number == $right.phone_number
内容的提问来源于stack exchange,提问作者mnm
相关产品推荐
相关产品推荐

