Let’s say I have a KQL query that uses several tables to retrieve the data.
I need to write some code in C#, that will take all the tables used by a given KQL query, and put all those table names into a list.
Simply put: I need to analyze each KQL query to know from which tables it gets the data.
I already tried doing so by writing this code:
var query = "Table1 | project a ,b,c";
var code = KustoCode.Parse(query);
var parseCode = code.Analyze();
Console.WriteLine(parseCode.ResultType.Display.ToString());
But this doesn’t return the tables names, but instead it returns the columns names that this query used, which is not what I want.
If you could help me solve this I would greatly appreciate it!
3
Answers
Thanks for the help! I finally was able to find a solution for this so here is my code:
This would seem to do the trick (based on
.show queryplan
)I don’t believe this is knowable a priori as some table names can be resolved at query time and some queries (for example using find) can cover all/multiple tables that are not enumerated until query time.
You can find this information shortly after the fact if you turn on Table Usage Statistics in the ‘Diagnostic settings’ tab in the azure portal view of your ADX cluster. This will pump detailed information into an app insights resource that will show what table/extents get used.