Azure Data Explorer - Working With Kusto Case Sensitivity

Like most other programming and query languages, Kusto too has case sensitivity, which means it can deal with upper-case and lower-case while performing comparisons between values.
 
Let’s consider the 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

 
Case sensitive means the matches should be exact, upper case letters must match with upper-case only and the same for lower-case. Whenever a match is performed between an upper-case character and a lower-case character, a query will return false, although both of the characters are same. For example, dev and Dev are not same.
 
Query description
 
Get the list of features, which belongs to the dev environment.
 
Query
  1. demoData| where Environment == "dev"  
As “==” stands for case sensitive comparison, the above query will result in the below output,
 
 

Case Insensitive Comparison

 
Case insensitive comparisons behave in a completely opposite fashion as case sensitive comparisons. Whenever the match is performed between an upper-case character and a lower-case character, the query will return true, as long as both of the characters are the same. For example, dev and Dev are the same.
 
Now, to achieve this behavior there are multiple approaches.
 
Approach1
 
In this approach, one can first convert the string using the toupper(…) or tolower(…) functions and then perform the comparison as shown below,
  1. demoData| where tolower(Environment) == "dev"  
Approach 2
 
In this approach, there is no need to call any extra function,  as the inbuilt operator will do this for us as shown below,
  1. demoData| where Environment =~ "dev"  
Here “=~” performs the case-insensitive comparison.
 
Execution of both the above queries results in the 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 kusto-ing!