microsoft / Kusto-Query-Language

Kusto Query Language is a simple and productive language for querying Big Data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positives on KustoCode.ParseAndAnalyze (ifexists is ignored).

jkindwall opened this issue · comments

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 "ifexists" parameter seems to be ignored on .drop and .rename commands.

.drop column MyTable.Status ifexists

KS142 - The name 'Status' does not refer to any known column, table, variable or function.
The analyzer seems to be ignoring the "ifexists" parameter which should make this code execute without errors even when the Status field doesn't exist.

.rename tables MyTable_Old=MyTable ifexists

KS204 - The name 'MyTable' does not refer to any known table, tabular variable or function.
Again, its ignoring "ifexists"

Broke it up into separate issues.

There is not much support for control commands beyond syntax parsing and recognizing a few locations where things like names appear, but no general recognition of other terms during analysis. I will look into finding a solution for this case, but it may not be good idea to rely on semantic analysis for control commands. You probably only want to rely on checking syntax errors.

That's a pretty significant limitation. I'm trying to use this library to validate the files that define our database schema and functions. They are pretty much all control commands. Mostly the following:

.create-or-alter function
.create-merge table
.alter table policy
.delete table policy