使用 replace() 时无法将参数 2 转换为标量常量

Failed to cast argument 2 to scalar constant when using replace()

当函数的第二个参数是列字段时,我正在尝试使用 replace

replace("bla", column1Field, orignalString)

但我收到以下错误:

replace(): failed to cast argument 2 to scalar constant

为什么我会收到此错误以及如何将列字段与这些函数一起使用?

2021 年 7 月更新:

replace() 函数已替换为 replace_regex()(请注意参数的顺序已更改)。 replace_regex() 需要一个正则表达式查找,它必须是一个常量,因为 Kusto 会“编译”它,并且 performance-wise 每条记录都这样做是不好的。

还有一个新的 replace_string() 函数可以让您完全按照自己的意愿行事:将一个字符串替换为另一个字符串(两者都可以是 non-const)。所以在你的情况下,你应该使用 replace_string(orignalString, "bla", column1Field)

旧答案:

replace() 的第二个参数必须是一个常量,因为 Kusto 会“编译”它,并且 performance-wise 每条记录都这样做是不好的。

一个例子(来自doc):

range x from 1 to 5 step 1
| extend str=strcat('Number is ', tostring(x))
| extend replaced=replace(@'is (\d+)', @'was: ', str)

如您所见,第二个参数包含 </code>,它将采用 str 中的值,匹配第一个参数正则表达式中 <code>()s 中的内容。