question

Max Guernsey, III avatar image
Max Guernsey, III asked

KQL "let" keyword doesn't work consistently

Hi,

It would be nice to be able to simplify my KQL queries by pulling some information out into "let" statements. That is very difficult, right now.

For instance, the following KQL query is more or less adapted directly from the KQL documentation (here).

let start_time = ago(5h); 
let end_time = start_time + 2h; 

['events.all'] | where Timestamp > start_time and Timestamp < end_time

It does not work. I get this error:

Error 

 'where' operator: Failed to resolve column or scalar expression named '["start_time"]'

 clientRequestId: KustoWebV2;d54c841c-6de3-4cd4-a476-6ed283c358af

It's possible I'm doing something wrong and I haven't checked whether this is a limitation of the UI or happening when I hit the API directly.

In any event, it is important to be able to do things like join against data tables defined outside of the primary query at the end of the KQL document. We can't do that if we cannot access objects defined with the let keyword. At least I've not been able to figure out how.

Here are the things I've tried to define with let and been unable to use:

  • Constant scalar values
  • Data tables
  • Functions

Thanks,

Max

***EDIT***

Thanks to @SethDu for figuring out what was going on, here. It's the addition of blank lines.

For instance, this statement works:

let Unrelated = 1;
let Me = datatable (Entity_Id:string)["<my id>"];
['events.all'] | join kind=inner Me on Entity_Id | limit 10

...but this statement doesn't:

let Unrelated = 1;

let Me = datatable (Entity_Id:string)["<my id>"];
['events.all'] | join kind=inner Me on Entity_Id | limit 10

I still assert this is a bug. Note that the query breaks even though Unrelated is not used. The mere presence of a constant definition that is not even used, separated from the rest of the query by a blank line, means that the query will break.

The good news, for whoever stumbles upon this, is that the workaround is as @SethDu said: Just get rid of all your blank lines.

analytics
ebt9i.png (12.7 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

Hi, I have tried to reproduce your issue, please delete the 3rd line becuase blank line seems to report this error. Currently, Explorer in my title works fine:


6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Max Guernsey, III avatar image Max Guernsey, III commented ·

Indeed. Note the title is "doesn't work consistently". I had already determined that it worked under some circumstances but not others but I hadn't noticed what those circumstances were.

Thank you for figuring out that...

1 Like 1 ·
Max Guernsey, III avatar image Max Guernsey, III Max Guernsey, III commented ·

I still think this is a bug. We have a clear understanding of what the bug is, now.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Max Guernsey, III commented ·

After the discussion with team. This phenomenon should be by design. Blank line in Kusto language doesn't mean escape. If you click on the sentences, sentences to be executed will be marked as highlight and you may find differences when there are blank lines.

I am not expert on Kusto language. If you have any question on it, please navigate to Azure Data Explorer community.

1 Like 1 ·
Show more comments
Max Guernsey, III avatar image Max Guernsey, III commented ·

I can't figure out how to accept this answer. Maybe someone accepted it for me and that's why it says "best answer"?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.