microsoft / Kusto-Query-Language

Kusto Query Language is a simple and productive language for querying Big Data.
Apache License 2.0
510 stars 97 forks source link

False positives on KustoCode.ParseAndAnalyze (functions that return a dynamic are not recognized as dynamic) #122

Closed jkindwall closed 11 months ago

jkindwall commented 1 year ago

Our team stores a fairly large library of .kql files in source control that are used to ensure the schema of our main database is properly in sync with the rest of our code. We frequently run into deployment failures due to errors in these kql files that were not caught during code review and we don't find out about them until we are attempting to deploy the changes to our database.

I would like to use this library and specifically the KustoCode.ParseAndAnalyze method in a validation step as part of our PR builds to try and catch these types of errors before they are merged into our main branch. However, I'm currently running into far too many false positives in kql code that actually executes without issue against the actual database.

I am using this library: https://github.com/mattwar/Kusto.Toolkit to automatically generate the GlobalState object based on the current state of our test environment database, then running each command through the ParseAndAnalyze() method to detect errors.

One such error is that the functions that return dynamic are not recognized as dynamic

let tag = tolower(strcat_array(CustomParseFunction(stringParameter).Parts, ":"));

KS107 - A value of type dynamic expected. The "CustomParseFunction" returns a dynamic object with the field "Parts" as a dynamic array, however the analyzer does not recognize it as such.

let info = CustomParseFunction(stringParameter);
let data = getDataFunction(info.Parts[0]);

KS147 - The element access operator [] is not allowed in this context. Again, the Parts field of the object returned by CustomParseFunction is not recognized as a dynamic array.

mattwar commented 1 year ago

A recent change in how dynamic types are understood has caused both of these problems. Fortunately, I fixed them yesterday. It might take a week or two for a new build to be published.