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:
- 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
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
- demoData| where Environment == "dev"
Case Insensitive Comparison
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:
- 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:
- demoData| where Environment =~ "dev"
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
Post a Comment