简体   繁体   中英

Is there a way to define a dictionary in kusto query and get both key and value

I defined two variables by using kusto query, for example, TableA has a column "Path" such as \L1\L2\L3\L4, want to get the name of each part of this Path. If want to get all rows which path's second part is "L2", we need the index == 1. If we want to get all rows which path's third part is "L3", we need change both variable index to 2 and name to "L3".

let index = 1;
let name = 'L2';
TableA
| extend PathSeperated = split(Path, "\\")
| project Name = PathSeperated[toint(index)]
| where Name == name

How can we make a mapping such as using a dictionary to clarify that it is obvious to know whenever we want to change the value of name, we have to change the value of index at the same time.

I tried to use dynamic, but it requires the key as a String, I defined it as

let mapping = dynamic("1", "L2");

I need both key and value, but I can't use mapping.1 to get the associated value "L2". Also, I can't find a way to get a key's value.

Could somebody know if there's a way to get both key and value for kusto query?

Does this work:

let index = 1;
let dict = dynamic(["L1","L2", "L3", "L4"]);
datatable(Path:string)[@'foo\bar\baz', @'L1\L2\L3\L4']
| extend PathSeperated = split(Path, "\\")
| project Name = PathSeperated[index]
| where Name == tostring(dict[index])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM