如何:运行 用户为一系列(日期)值定义的函数
How to: Run a user defined function for a range of (date) values
假设我想测试一个函数,该函数可以发现过去数据中的异常值。我很想得到一个看起来像这样的 table:
Time Outliers_At_Time
<somedate> 0
<somedate + interval> 1
函数如下所示:
let OutliersAt = (TheDate:datetime) {
<… outputs zero or a positive integer>
}
我的直觉是做这样的事情:
let SomeDates = range AtTime from ago(10d) to now() step 10m;
SomeDates | extend NumOutliers = OutliersAt (AtTime)
…但这给了我这个错误信息:
Error Semantic error: '' has the following semantic error: Unresolved
reference binding: 'AtTime'. clientRequestId:
KustoWebV2;1ea28ba0-12f1-4a52-95e7-975db3310f59
建议?
如果您正在寻找异常值 - Kusto 中有一个内置函数可以执行此操作:
https://docs.microsoft.com/en-us/azure/kusto/query/series-outliersfunction
示例:
let _data =
range Timestamp from ago(7d) to now() step 1min
| extend Value=case(rand(1000)==10, 1200.0, rand(100));
//
_data
| make-series AvgValue=avg(Value) default=0 on Timestamp in range(ago(7d), now(), 5min)
| extend outliers=series_outliers(AvgValue)
| render timechart
如果问题是关于为用户定义的函数提供参数的一般方法,
在这里查看更多信息:
https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions
特别是,您可以将系列传递给用户定义的函数(例如,获取统计信息):
let OutliersAt = (_serie:dynamic) {
let stats = series_stats_dynamic(_serie);
todouble(stats.max_idx) >= 0
};
let _data =
range Timestamp from ago(7d) to now() step 1min
| extend Value=case(rand(1000)==10, 1200.0, rand(100));
//
_data
| make-series AvgValue=avg(Value) default=0 on Timestamp in range(ago(7d), now(), 5min)
| extend outliers=series_outliers(AvgValue)
| project hasOutliers=OutliersAt(outliers)
假设我想测试一个函数,该函数可以发现过去数据中的异常值。我很想得到一个看起来像这样的 table:
Time Outliers_At_Time
<somedate> 0
<somedate + interval> 1
函数如下所示:
let OutliersAt = (TheDate:datetime) {
<… outputs zero or a positive integer>
}
我的直觉是做这样的事情:
let SomeDates = range AtTime from ago(10d) to now() step 10m;
SomeDates | extend NumOutliers = OutliersAt (AtTime)
…但这给了我这个错误信息:
Error Semantic error: '' has the following semantic error: Unresolved reference binding: 'AtTime'. clientRequestId: KustoWebV2;1ea28ba0-12f1-4a52-95e7-975db3310f59
建议?
如果您正在寻找异常值 - Kusto 中有一个内置函数可以执行此操作: https://docs.microsoft.com/en-us/azure/kusto/query/series-outliersfunction
示例:
let _data =
range Timestamp from ago(7d) to now() step 1min
| extend Value=case(rand(1000)==10, 1200.0, rand(100));
//
_data
| make-series AvgValue=avg(Value) default=0 on Timestamp in range(ago(7d), now(), 5min)
| extend outliers=series_outliers(AvgValue)
| render timechart
如果问题是关于为用户定义的函数提供参数的一般方法, 在这里查看更多信息: https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions
特别是,您可以将系列传递给用户定义的函数(例如,获取统计信息):
let OutliersAt = (_serie:dynamic) {
let stats = series_stats_dynamic(_serie);
todouble(stats.max_idx) >= 0
};
let _data =
range Timestamp from ago(7d) to now() step 1min
| extend Value=case(rand(1000)==10, 1200.0, rand(100));
//
_data
| make-series AvgValue=avg(Value) default=0 on Timestamp in range(ago(7d), now(), 5min)
| extend outliers=series_outliers(AvgValue)
| project hasOutliers=OutliersAt(outliers)