Reputation: 59
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?
Upvotes: 1
Views: 4042
Reputation: 7608
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])
Upvotes: 1