The Kusto Query Language (KQL) Statement Structure
A KQL query is a read-only request to process the data and return results which is stated in plain text, using the data-flow model designed to make the syntax easy to read, write, and automate; while consisting of a sequence of query statements in which at least one of them is a tabular expression statement that produces data arranged in a table-like mesh of columns as well as rows.
The tabular expression statement's syntax has tabular data flow from one tabular query operator to another, starting with the data source and then flowing through a set of data transformation operators bound together through the use of pipe (|) delimiter.
Note- it is essential to understand how the results flow through the pipe "|". Everything on the left of the pipe is processed then sent to the right of the pipe.
Access the Log Analytics demo environment
If you have an account to log into Azure, then Microsoft can provide you with an access to an environment to practice writing KQL statements. No charges are required to your Azure account to access this environment and you can execute the KQL statements in this module in the demo environment. The Query window has three primary sections:
- The left area is a reference list of the tables in the environment.
- The middle top area is the Query editor.
- The bottom area is the Query Results.
Before running a query, adjust the time range to scope the data. To change the result columns displayed, select the Columns box, and choose the required columns.
Use Let statement
Let statements can bind names to expressions and for the rest of the scope, where the let statement appears, the name refers to its bound value. They improves the modularity and reuse since they allow you to break a potentially complex expression into multiple parts as well as the creation of user-defined functions and views. The views are the expressions whose results looks like a new table.
Use the Search operator
The search operator provides a multi-table/multi-column search experience. Although it is easy to use, but it is inefficient compared to the where operator. However, even after this, you can use search to find data when unsure which table or column to filter.
Use the Where operator
The where operator filters a table to the subset of the rows that satisfy a predicate.
Use the Extend operator
It creates calculated columns and append the new columns to the result set.
Use the Order By operator
It sorts the rows of the input table by one or more columns by utilizing the operator's order it allows you to utilize any column or multiple columns by using a comma separator each of which can be either ascending or descending.
Use the Project operator
The project operators controls what columns to include, add, remove, or rename in the result set of a statement. There are multiple types of project operators described as follows:
Operator
|
Description
|
project
|
Selects
the columns to include, rename, or drop and insert new computed columns.
|
project-away
|
Selects
what column from the input to exclude from the output.
|
Project-keep
|
Selects
what column from the input to keep in the output.
|
project-rename
|
Selects
what columns to rename in the resulting output.
|
Project-reorder
|
Sets
the column order in the resulting output.
|
Comments
Post a Comment