我有一个requests
包含url
, name
,timestamp
列的数据表,我向其中添加了另一个计算列operationType
。
我想requests
根据定义的动态对象属性进行过滤和查询data
,以获得操作及其使用次数,如下所示:
operationType | Counts
-------------------------
1.1 Operation A | 2400
-------------------------
1.2 Operation B | 1500
我有的:
let daysAgo = 100d;
let data = dynamic([
{
'searchKey': 'url',
'searchOperator': 'contains',
'searchValue': 'AjaxContent?option=something',
'operationName': '1.1 Operation A'
},
{
'searchKey': 'name',
'searchOperator': 'matches regex',
'searchValue': 'POST /api/repo/\\d+/filters',
'operationName': '1.2 Operation B'
}]);
let req = requests
| where (timestamp >= ago(daysAgo))
| where
//Issue #1: I want data[0].searchKey to be used as the requests column name
data[0].searchKey contains data[0].searchValue
//url contains data[0].searchValue //works
//Issue #2: 'doesn't work, error 'matches regex' operator requires string arguments
or name matches data[1].searchValue
//or name matches regex 'POST /api/repo/\\d+/filters' //works
| extend operationType=
case(name == data[2].searchValue, data[2].operationName,
url contains data[0].searchValue, data[0].operationName
'Other - please check' )
| order by timestamp desc;
req | summarize Counts = count() by operationType
理想的情况是创建一个自定义查询,如下所示(甚至可能循环通过动态数组属性data
)(Q #3):
requests | where data[0].searchKey data[0].searchOperator data[0].searchValue
在相同的上下文中,理想的方法是将计算operationType
列扩展为以某种方式自定义创建(Q #4):
requests
| where
...
| extend operationType= case(url contains data[0].searchValue, data[0].operationName,
name matches regex data[0].searchValue, data[0].operationName)
或者
requests
| where
...
| extend operationType= case(data[0].searchKey data[0].searchOperator data[0].searchValue, data[0].operationName,
data[1].searchKey data[1].searchOperator data[0].searchValue, data[0].operationName)
- 动态值可以用作
where
语句中的数据表列名(问题#1)吗? matches regex
动态值可以用作语句中的右手吗(问题#2)?- 可以创建动态自定义查询
where
语句,循环遍历动态数组(Q #3)吗? - 可以在语句中自定义创建计算扩展列
case
(Q #4)吗?