动态数组上的 Kusto UDF(映射字符串值)
Kusto UDF on dynamic array (map string values)
我正在尝试对字符串数组(动态类型)应用简单的转换。
为了示例,我想映射一个字符串数组。每个字符串用破折号包裹 - ["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。
您的 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)"
str
abc
name1
[
"---a---",
"---b---",
"---c---"
]
name2
[
"---a---",
"---b---",
"---c---"
]
name3
[
"---a---",
"---b---",
"---c---"
]
关于您的意见 -
- 假设我正确理解了你的口头描述 - 你可以试试这个:
- 否则,请clarify/provide请求示例。
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))
str
---a---
---b---d---c
我正在尝试对字符串数组(动态类型)应用简单的转换。
为了示例,我想映射一个字符串数组。每个字符串用破折号包裹 - ["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。
您的 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)"
str | abc |
---|---|
name1 | [ "---a---", "---b---", "---c---" ] |
name2 | [ "---a---", "---b---", "---c---" ] |
name3 | [ "---a---", "---b---", "---c---" ] |
关于您的意见 -
- 假设我正确理解了你的口头描述 - 你可以试试这个:
- 否则,请clarify/provide请求示例。
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))
str |
---|
---a--- |
---b---d---c |