Skip to main content

Working with Kusto Case Sensitivity

Like most of the other programming and query languages, Kusto too has sense of case sensitivity, which means, it can deal with upper-case and lower-case while performing comparisons between values.

Let’s consider below sample data:

  1. let demoData = datatable(Environment: string, Feature:string)  
  2. [    
  3.    "dev""Feature1",  
  4.    "test""Feature1",  
  5.    "prod""Feature1",  
  6.    "Dev""Feature2",  
  7.    "test""Feature2",  
  8.    "dev""Feature3",  
  9.    "test""Feature3",  
  10.    "prod""Feature3"    
  11. ];

Case Sensitive Comparison

The Case sensitive means match should be exact, upper-case letter must match with upper-case only and same for lower-case. Whenever the match is performed between an upper-case character and a lower-case character, query would return false, although both the characters are same. For example, dev and Dev are not same.

Query description

Get list of features, which belongs to dev environment.

Query

  1. demoData| where Environment == "dev"  
As “==” stands for case sensitive comparison, above query will result in below output:








Case Insensitive Comparison

Case insensitive comparison behaves in completely opposite fashion as case sensitive comparison does. Whenever the match is performed between an upper-case character and a lower-case character, query would return true, as long as both the characters are same. For example, dev and Dev are same.

Now, to achieve this behavior there are multiple approaches.

Approach 1

In this approach, one can first convert the string using toupper(…) or tolower(…) functions and then perform the comparison as shown below:

  1. demoData| where tolower(Environment) == "dev"  

Approach 2

In this approach, no need to call any extra function as inbuild operator will do this for us as shown below:

  1. demoData| where Environment =~ "dev"  

Here “=~” performs the for case-insensitive comparison. 

Execution of both the above queries result in same output as shown below:

 


Performance Tip

  • Always prefer case-sensitive over case-insensitive, wherever possible.
  • Always prefer has or in over contains.
  • Avoid using short strings as it impacts indexing. 

Happy kustoing!

Comments