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:
- let demoData = datatable(Environment: string, Feature:string)
- [
- "dev", "Feature1",
- "test", "Feature1",
- "prod", "Feature1",
- "Dev", "Feature2",
- "test", "Feature2",
- "dev", "Feature3",
- "test", "Feature3",
- "prod", "Feature3"
- ];
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
- 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,
- 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,
- 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!