如何将标量值传递给已保存的函数? [英] How to pass a scalar value to a saved function?
问题描述
我有一个查询,我想在其他一系列查询中重复使用,所以我创建了一个函数,如下所述:https://docs.microsoft.com/zh-cn/azure/log -analytics/query-language/advanced-query-writing?toc =/azure/azure-monitor/toc.json#functions
I have a query that I want to reuse in a bunch of other queries, so I created a function as described here: https://docs.microsoft.com/en-us/azure/log-analytics/query-language/advanced-query-writing?toc=/azure/azure-monitor/toc.json#functions
但是,我希望能够将标量值传递给函数以使其更有用.例如,共享函数如下所示:
However, I want to be able to pass a scalar value into the function to make it more useful. For example, the shared function looks something like this:
KubePodInventory
| where TimeGenerated > arg1
| where ClusterName =~ arg2
| distinct ContainerID
...
例如,我想在查询中使用它并控制TimeGenerated和ClusterName过滤器的值
I would like to use it from a query and control the values of the TimeGenerated and the ClusterName filter, for example
let arg1 = ago(1d);
let arg2 = "myclustername";
myfunction
| ...
| ...
但是,在函数中引用这些标量值不起作用.有什么方法可以将它们传递给外部函数吗?
However, referencing these scalar values in the function does not work. Is there some way to pass them into the external function?
推荐答案
您需要在函数的签名中传递标量.
You'll need to pass the scalar in a signature for the function.
let Add7 = (arg0:long = 5) { arg0 + 7 };
range x from 1 to 10 step 1
| extend x_plus_7 = Add7(x), five_plus_seven = Add7()
因此,这里的第一个括号表示默认值5,然后括号表示要执行的操作.希望有帮助!
So the first parenthesis here are representing the default value of 5, then the brackets indicate what operation to perform. Hope that helps!
let KubePodInv = (arg1:long, arg2:string) {
KubePodInventory
| where TimeGenerated > arg1
| where ClusterName =~ arg2
| distinct ContainerID
};
这篇关于如何将标量值传递给已保存的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!