我正在嘗試對字串陣列(動態型別)應用簡單的轉換。
為了這個例子,我想映射一個字串陣列。用破折號包裹的每個字串 -["a", "b", "c"] => ["---a---", "---b---", "---c---"]
我試過:
let foof = (fooTable: dynamic) {
fooTable | mv-apply fooTable on ( project abc=strcat("---", fooTable, "---") | summarize make_list(abc))
};
let fooTable = datatable(str: string, record: dynamic) [
"name1", dynamic(["a", "b", "c"]),
"name2", dynamic(["a", "b", "c"]),
"name3", dynamic(["a", "b", "c"]),
];
fooTable | project abc=foof(record)
我期待得到映射的三行(在每一行上應用的 UDF)。
似乎我在沒有 UDF 的情況下做對了:
fooTable | mv-apply record on (
project abc=strcat("--", record, "---") | summarize make_list(abc)
)
但我對 UDF 做錯了。
但我得到:
Operator source expression should be table or column
我正在嘗試僅更改 UDF,因此在 KQL 中,我只會在給定的列上呼叫 UDF。
uj5u.com熱心網友回復:
您的 UDF 應該有一個表格引數而不是標量引數,您可以使用invoke運算子:
let foof = (fooTable: (record: dynamic)) {
fooTable | mv-apply record on ( project abc=strcat("---", record, "---") | summarize abc = make_list(abc))
};
let fooTable = datatable(str: string, record: dynamic) [
"name1", dynamic(["a", "b", "c"]),
"name2", dynamic(["a", "b", "c"]),
"name3", dynamic(["a", "b", "c"]),
];
fooTable | invoke foof() // you can also replace this line with "foof(fooTable)"
| 字串 | 美國廣播公司 |
|---|---|
| 姓名1 | [ "---a---", "---b---", "---c---" ] |
| 姓名2 | [ "---a---", "---b---", "---c---" ] |
| 姓名 3 | [ "---a---", "---b---", "---c---" ] |
關于你的評論——
- 假設我正確理解了你的口頭描述——你可以試試這個:
- 否則,請按要求澄清/提供示例。
let some_variable = dynamic(['a','b','c']);
let foof = (some_variable: dynamic) {
toscalar(
print some_variable
| mv-apply v = some_variable on ( project v = strcat("---", v, "---"))
| summarize make_set(v)
);
};
let T = datatable(str: string) [
"---abc---",
"---a---",
"---b---d---c",
];
T
| where str has_any (foof(some_variable))
| 字串 |
|---|
| - -一個 - - |
| ---b---d---c |
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/403444.html
標籤:
