Kusto,根据条件执行操作
Kusto, Performing operations based on a condition
我正在尝试编写一个 Kusto 查询,其中有一个 bool 变量,我想根据该变量调用不同的函数。
例如:
let flag = true;
let result = iff(flag == "true", function1, function2)
// function1 will return a different table and function2 will return another table.
上面的代码是不可能的,因为像iff() and case()
这样的方法只能对标量值进行操作。
那么,有什么方法可以实现这个目标吗?
常用技术是使用联合:
union (function1 | where flag), (function2 | where not(flag))
这是一个完整的例子:
let A = datatable(col1:string)["A"];
let B = datatable(col1:string)["B"];
let funcA = view(){
A
};
let funcB= view(){
B
};
let flag = true;
union (funcA() | where flag), (funcB() | where not(flag))
col1
A
当标志为 false 时:
let A = datatable(col1:string)["A"];
let B = datatable(col1:string)["B"];
let funcA = view(){
A
};
let funcB= view(){
B
};
let flag = false;
union (funcA() | where flag), (funcB() | where not(flag))
col1
B
我正在尝试编写一个 Kusto 查询,其中有一个 bool 变量,我想根据该变量调用不同的函数。 例如:
let flag = true;
let result = iff(flag == "true", function1, function2)
// function1 will return a different table and function2 will return another table.
上面的代码是不可能的,因为像iff() and case()
这样的方法只能对标量值进行操作。
那么,有什么方法可以实现这个目标吗?
常用技术是使用联合:
union (function1 | where flag), (function2 | where not(flag))
这是一个完整的例子:
let A = datatable(col1:string)["A"];
let B = datatable(col1:string)["B"];
let funcA = view(){
A
};
let funcB= view(){
B
};
let flag = true;
union (funcA() | where flag), (funcB() | where not(flag))
col1 |
---|
A |
当标志为 false 时:
let A = datatable(col1:string)["A"];
let B = datatable(col1:string)["B"];
let funcA = view(){
A
};
let funcB= view(){
B
};
let flag = false;
union (funcA() | where flag), (funcB() | where not(flag))
col1 |
---|
B |