在Kusto中显示特定条件下的消息而不是结果



在Kusto中,我希望根据某些标准向用户显示消息。例如

isempty(['_tenant'])
| print "Note: ", "You must select a tenant"
else???
Events
| where tenant == ['_tenant']
| ...

每个查询和消息的标准是不同的。

另一种方法是创建一个联合,其中联合的每个分支是互斥的。问题在于无论输入是什么,函数都必须返回一致的模式。因此,在本例中,您最终将得到一个Status列和一个x列。

let myFunc = (y:long) {
union 
(
print Status = "Y must be greater than 0"
| where y > 0
),
(
range x from 1 to 10 step 1
| where y <= 0
)        
};
myFunc(-1)

听起来您可能正在寻找assert()函数:https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/assert-function

let checkLength = (len:long, s:string)
{
assert(len > 0, "Length must be greater than zero") and
strlen(s) > len
};
datatable(input:string)
[
'123',
'4567'
]
| where checkLength(len=long(-1), input)

最新更新