Real-Time Intelligence tutorial part 4: Query streaming data using KQL

Note

This tutorial is part of a series. For the previous section, see: Real-Time Intelligence tutorial part 3: Transform data in a KQL database.

In this part of the tutorial, you learn how to query your streaming data using KQL. You write a KQL query and visualize the data in a time chart.

Write a KQL query

The name of the table you created from the update policy in a previous step is TransformedData. Use this (case-sensitive) name as the data source for your query.

Tip

If you have a sufficient subscription, you can use the Copilot feature to help you write queries. Copilot provides queries based on data in your table and natural language prompts. For more information, see Copilot for Real-Time Intelligence (preview)

  1. Enter the following query. Then press Shift + Enter to run the query.

    TransformedData
    | where BikepointID > 100 and Neighbourhood == "Chelsea"
    | project Timestamp, No_Bikes
    | render timechart
    

    This query creates a time chart that shows the number of bikes in the Chelsea neighborhood as a time chart.

    Screenshot of bikes timechart in Real-Time Intelligence.

Create a materialized view

In this step, you create a materialized view, which returns an up-to-date result of the aggregation query (always fresh). Querying a materialized view is more performant than running the aggregation directly over the source table.

  1. Copy/paste and run the following command to create a materialized view that shows the most recent number of bikes at each bike station:

    .create-or-alter materialized-view with (folder="Gold") AggregatedData on table TransformedData
    {
       TransformedData
       | summarize arg_max(Timestamp,No_Bikes) by BikepointID
    }
    
  2. Copy/paste and run the following query to see the data in the materialized view visualized as a column chart:

    AggregatedData
    | sort by BikepointID
    | render columnchart with (ycolumns=No_Bikes,xcolumn=BikepointID)
    

You will use this query in the next step to create a Real-Time dashboard.

Important

If you have missed any of the steps used to create the tables, update policy, function, or materialized views, use this script to create all required resources: Tutorial commands script.

For more information about tasks performed in this tutorial, see:

Next step