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
可能包括:
模式 | 計數 | 代表 |
---|---|---|
三* | 5,182 | 聖伯納德 |
聖人* | 2,846 | Saint Lucy |
Moscow | 3726 | Moscow |
*-上-* | 2730 | 一對一 |
巴黎 | 2716 | 巴黎 |
範例
本節中的範例示範如何使用 語法來協助您開始使用。
本文中的範例會使用 說明叢集中公開可用的數據表,例如 Samples 資料庫中的
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"
輸出
模式 | 計數 | 代表 |
---|---|---|
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 個數據列% 的群組。
模式 | 計數 | 代表 |
---|---|---|
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
參數的行為
如果未指定 Characters 參數,則每個非 ascii 數位字元都會變成字詞分隔符。
range x from 1 to 10 step 1 | project str = strcat("foo", "Z", tostring(x)) | reduce by str
輸出
模式 | 計數 | 代表 |
---|---|---|
其他 | 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"
輸出
模式 | 計數 | 代表 |
---|---|---|
foo* | 10 | fooZ1 |
套用 reduce
至清理輸入
下列範例示範如何將 reduce
運算子套用至「清理」輸入,其中,在減少數據行中的 GUID 會在減少之前加以取代:
從追蹤數據表的一些記錄開始。 然後減少包含隨機 GUID 的 Text 資料行。 當隨機 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 從事件記錄檔採礦模式的數據群集演算法檔為基礎。