你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
reduce 运算符
根据值相似性分组一系列字符串。
对于每个此类组,运算符将返回 pattern
、count
和 representative
。
pattern
最好地描述组,其中的 *
字符表示通配符。
count
是组中值的数量,representative
是组中的原始值之一。
T|
reduce
[kind
=
ReduceKind] by
Expr [with
[threshold
=
Threshold] [,
characters
=
Characters]]
详细了解语法约定。
客户 | 类型 | 必需 | 说明 |
---|---|---|---|
Expr | string |
✔️ | 作为减小量的值。 |
阈值 | real |
一个介于 0 到 1 之间的值,用于确定与分组条件匹配以触发缩减操作所需的最小行数。 默认值为 0.1。 建议为大型输入设置较小的阈值。 使用较小的阈值,可以将更多类似的值组合在一起,从而生成更少但更相似的组。 较大的阈值需要较少的相似性,导致更多的组不太相似。 请参阅示例。 |
|
字符 | string |
在字词之间进行分隔的字符的列表。 默认值为每个非 ascii 数字字符。 有关示例,请参阅 Characters 参数的行为。 | |
ReduceKind | string |
唯一有效的值是 source 。 如果指定了 source ,则运算符会将 Pattern 列追加到表中的现有行,而不是通过 Pattern 进行聚合。 |
一个表,其行数与标题为 pattern
、count
和 representative
的组数和列数相同。
pattern
最好地描述组,其中的 *
字符表示通配符,或任意插入字符串的占位符。
count
是组中值的数量,representative
是组中的原始值之一。
例如,reduce by city
的结果可能包括:
模式 | 计数 | Representative |
---|---|---|
San * | 5182 | San Bernard |
Saint * | 2846 | Saint Lucy |
Moscow | 3726 | Moscow |
* -on- * | 2730 | One -on- One |
Paris | 2716 | Paris |
本节中的示例演示如何使用语法帮助你入门。
本文中的示例使用 帮助群集中的公开可用表,例如 示例 数据库中的
StormEvents
表。
本文中的示例使用公开可用的表,例如天气分析中的
StormEvents
表 示例数据。
此查询将生成一系列数字,创建一个包含串联字符串和随机整数的新列,然后使用特定的缩减参数按新列对行进行分组。
range x from 1 to 1000 step 1
| project MyText = strcat("MachineLearningX", tostring(toint(rand(10))))
| reduce by MyText with threshold=0.001 , characters = "X"
输出
模式 | 计数 | Representative |
---|---|---|
MachineLearning* | 1000 | MachineLearningX4 |
此查询将生成一系列数字,创建一个包含串联字符串和随机整数的新列,然后使用特定的缩减参数按新列对行进行分组。
range x from 1 to 1000 step 1
| project MyText = strcat("MachineLearningX", tostring(toint(rand(10))))
| reduce by MyText with threshold=0.9 , characters = "X"
输出
结果仅包含 MyText 值至少出现在行的 90% 的组。
模式 | 计数 | Representative |
---|---|---|
MachineLearning* | 177 | MachineLearningX9 |
MachineLearning* | 102 | MachineLearningX0 |
MachineLearning* | 106 | MachineLearningX1 |
MachineLearning* | 96 | MachineLearningX6 |
MachineLearning* | 110 | MachineLearningX4 |
MachineLearning* | 100 | MachineLearningX3 |
MachineLearning* | 99 | MachineLearningX8 |
MachineLearning* | 104 | MachineLearningX7 |
MachineLearning* | 106 | MachineLearningX2 |
如果未指定 Characters 参数,则每个非 ascii 数字字符都成为字词分隔符。
range x from 1 to 10 step 1 | project str = strcat("foo", "Z", tostring(x)) | reduce by str
输出
模式 | 计数 | Representative |
---|---|---|
others | 10 |
但是,如果指定“Z”是分隔符,则好像 str
中的每个值都是两个术语:foo
和 tostring(x)
:
range x from 1 to 10 step 1 | project str = strcat("foo", "Z", tostring(x)) | reduce by str with characters="Z"
输出
模式 | 计数 | Representative |
---|---|---|
foo* | 10 | fooZ1 |
以下示例演示如何将 reduce
运算符应用于“清理”输入,其中要减少的列中的 GUID 在减少之前将被替换:
从跟踪表中的一些记录开始。 然后减少包含随机 GUID 的文本列。 当随机 GUID 干扰化简作时,将它们全部替换为字符串“GUID”。 现在执行化简作。 如果存在嵌入的“-”或“_”字符的其他“准随机”标识符,请将字符视为非分词符。
Trace
| take 10000
| extend Text = replace(@"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", "GUID", Text)
| reduce by Text with characters="-_"
备注
reduce
运算符的实现很大程度上基于 Risto Vaarandi 所著论文用于从事件日志中挖掘模式的数据聚类分析算法。