Skip to content

Commit

Permalink
acrolinx check
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJamesHerring committed Oct 23, 2023
1 parent ca95218 commit 6a1ab4f
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions Instructions/Labs/12-query-data-in-kql-database.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
lab:
title: 'Query data in KQL database'
title: 'Query data in KQL Database'
module: 'Query data from a Kusto Query database in Microsoft Fabric'
---
# Get started with querying a Kusto database in Microsoft Fabric
A KQL Queryset is a tool that allows you to execute queries, modify, and display query results from a KQL database. You can link each tab in the KQL Queryset to a different KQL database, and save your queries for future use or share them with others for data analysis. You can also switch the KQL database for any tab, so you can compare the query results from different data sources.

The KQL Queryset uses the Kusto Query language, which is compatible with many SQL functions, to create queries. To learn more about the [kusto query (KQL)language](https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/?context=%2Ffabric%2Fcontext%2Fcontext),

This lab will take approximately **25** minutes to complete.
This lab takes approximately **25** minutes to complete.

## Create a workspace

Expand All @@ -21,19 +21,19 @@ Before working with data in Fabric, create a workspace with the Fabric trial ena

![Screenshot of an empty workspace in Power BI.](./Images/new-workspace.png)

In this lab, you´ll use the Real-Time Analytics (RTA) in Fabric to create a KQL database from a sample eventstream. Real-Time Analytics conveniently provides a sample dataset that you can use to explore RTA's capabilities. You´ll use this sample data to create KQL | SQL queryes and querysets that analyzes some real-time data and allow for additional use in downstream processes.
In this lab, you use the Real-Time Analytics (RTA) in Fabric to create a KQL database from a sample eventstream. Real-Time Analytics conveniently provides a sample dataset that you can use to explore RTA's capabilities. You use this sample data to create KQL | SQL queries and querysets that analyzes real-time data and allow for other uses in downstream processes.

## Create a KQL Database

1. Within the **Real-Time Analytics**, select the **KQL Database** box.

![Image of choose kqldatabase](./Images/select-kqldatabase.png)
![Image of choose KQL Database](./Images/select-kqldatabase.png)

2. You'll be prompted to **Name** the KQL Database
2. You're prompted to **Name** the KQL Database

![Image of name kqldatabase](./Images/name-kqldatabase.png)
![Image of name KQL Database](./Images/name-kqldatabase.png)

3. Give the KQL Database a name that you'll remember, such as **MyStockData**, press **Create**.
3. Give the KQL Database a name that you remember, such as **MyStockData**, press **Create**.

4. In the **Database details** panel, select the pencil icon to turn on availability in OneLake.

Expand All @@ -47,11 +47,11 @@ In this lab, you´ll use the Real-Time Analytics (RTA) in Fabric to create a KQL

![Image of choosing analytics data for lab](./Images/create-sample-data.png)

7. Once the data is finished loading, we can verify the KQL database is populated.
7. Once the data is finished loading, we can verify the KQL Database is populated.

![Data being loaded into the KQL Database](./Images/choose-automotive-operations-analytics.png)

7. Once the data is loaded, verfiy the data is loaded into the KQL database. You can accomplish this by selecting the elipses to the right of the table, navigating to **Query table** and selecting **Show any 100 records**.
7. Once the data is loaded, verify the data is loaded into the KQL database. You can accomplish this operation by selecting the ellipses to the right of the table, navigating to **Query table** and selecting **Show any 100 records**.

![Image of selecting the top 100 files from the RawServerMetrics table](./Images/rawservermetrics-top-100.png)

Expand All @@ -61,21 +61,21 @@ In this lab, you´ll use the Real-Time Analytics (RTA) in Fabric to create a KQL


## Scenario
In this scenario, you're an analyst that's tasked with querying a sample dataset of raw metrics NYC taxicab rides that you will pull summary statistics (profiling) the data from the Fabric environment. You use KQLto query this data and gather information in order to gain informational insights about the data.
In this scenario, you're an analyst that's tasked with querying a sample dataset of raw metrics NYC taxicab rides that you pull summary statistics (profiling) the data from the Fabric environment. You use KQLto query this data and gather information in order to gain informational insights about the data.

## Introduction to Kusto Query Language (KQL) and its syntax

Kusto Query Language (KQL) is a query language used to analyze data in Microsoft Azure Data Explorer, which is a part of the Azure Fabric. KQL is designed to be simple and intuitive, making it easy for beginners to learn and use. At the same time, it is also highly flexible and customizable, allowing advanced users to perform complex queries and analysis.
Kusto Query Language (KQL) is a query language used to analyze data in Microsoft Azure Data Explorer, which is a part of the Azure Fabric. KQL is designed to be simple and intuitive, making it easy for beginners to learn and use. At the same time, it's also highly flexible and customizable, allowing advanced users to perform complex queries and analysis.

KQL is based on a syntax similar to SQL, but with some key differences. For example, KQL uses a pipe operator (|) instead of a semicolon (;) to separate commands, and it uses a different set of functions and operators for filtering and manipulating data.

One of the key features of KQL is its ability to handle large volumes of data quickly and efficiently. This makes it ideal for analyzing logs, telemetry data, and other types of big data. KQL also supports a wide range of data sources, including structured and unstructured data, making it a versatile tool for data analysis.
One of the key features of KQL is its ability to handle large volumes of data quickly and efficiently. This capability makes it ideal for analyzing logs, telemetry data, and other types of big data. KQL also supports a wide range of data sources, including structured and unstructured data, making it a versatile tool for data analysis.

In the context of Microsoft Fabric, KQL can be used to query and analyze data from various sources, such as application logs, performance metrics, and system events. This can help you gain insights into the health and performance of your applications and infrastructure, and identify issues and opportunities for optimization.

Overall, KQL is a powerful and flexible query language that can help you gain insights into your data quickly and easily, whether you're working with Microsoft Fabric or other data sources. With its intuitive syntax and powerful capabilities, KQL is definitely worth exploring further.

In this module, we'll focus on the basics of queries against KQL Database You'll see quickly that in KQL, there is no ```SELECT``` we can simply use the table name and press run. We'll cover the steps of a simple analysis using KQL first and then SQL both against the same KQL Database which is based on Azure Data Explorer.
In this module, we focus on the basics of queries against KQL Database You see quickly that in KQL, there's no ```SELECT``` we can simply use the table name and press run. We cover the steps of a simple analysis using KQL first and then SQL both against the same KQL Database, which is based on Azure Data Explorer.

**SELECT** queries, which are used to retrieve data from one or more tables. For example, you can use a SELECT query to get the names and salaries of all employees in a company.

Expand All @@ -89,7 +89,7 @@ In this module, we'll focus on the basics of queries against KQL Database You'll
## ```SELECT``` data from our sample dataset using KQL

1. In this query, we will pull 100 records from the Trips table. We use the ```take``` keyword to ask the engine to return 100 records.
1. In this query, we pull 100 records from the Trips table. We use the ```take``` keyword to ask the engine to return 100 records.

```kql
Trips
Expand All @@ -98,7 +98,7 @@ Trips
> **NOTE:**
> The Pipe ```|``` character is used for two purposes in KQL includuing to separate query operators in a tabular expression statement. It is also used as a logical OR operator within square or round brackets to denote that you may specify one of the items separated by the pipe character.
2. We can be more precise by simply adding specific attributes we would like to query using the ```project``` keyword and then using the ```take``` keyword to tell the engine how many records to return.
2. We can be more precise by adding specific attributes we would like to query using the ```project``` keyword and then using the ```take``` keyword to tell the engine how many records to return.

> **NOTE:** the use of ```//``` denotes comments used within the Microsoft Fabric ***Explore your data*** query tool.
Expand All @@ -125,15 +125,15 @@ Trips
```
## ```GROUP BY``` data from our sample dataset using KQL

1. Then we may want to ***group by*** the pickup location which we do with the ```summarize``` operator. We're also able to use the ```project``` operator which allows us to select and rename the columns you want to include in your output. In this case we group by borough within the NY Taxi system to provide our users with the total distance from traveled from each borough.
1. Then we may want to ***group by*** the pickup location that we do with the ```summarize``` operator. We're also able to use the ```project``` operator that allows us to select and rename the columns you want to include in your output. In this case, we group by borough within the NY Taxi system to provide our users with the total distance from traveled from each borough.

```
Trips
| summarize ["Total Trip Distance"] = sum(trip_distance) by pickup_boroname
| project Borough = pickup_boroname, ["Total Trip Distance"]
```

2. You'll note that we have a blank value, which is never good for analysis, and we can use the ```case``` function along with the ```isempty``` and the ```isnull``` functions to categorize these in our
2. Note that we have a blank value, which is never good for analysis, and we can use the ```case``` function along with the ```isempty``` and the ```isnull``` functions to categorize into a ***Unidentified*** category for follow-up.
```
Trips
| summarize ["Total Trip Distance"] = sum(trip_distance) by pickup_boroname
Expand All @@ -142,7 +142,7 @@ Trips

## ```ORDER BY``` data from our sample dataset using KQL

1. To make more sense of our data, we will typically order it by a column, and this is done in KQL with either a ```sort by``` or ```order by``` operator and they act the same way.
1. To make more sense of our data, we typically order it by a column, and this process is done in KQL with either a ```sort by``` or ```order by``` operator and they act the same way.

```
// using the sort by operators
Expand All @@ -160,7 +160,7 @@ Trips

## ```WHERE``` clause to filter data in our sample KQL Query

1. Unlike SQL, our WHERE clause is immediately called in our KQL Query. We can still use the ```and``` as well as the ```or``` logical operators within your where clause and it will evaluate to true or false against the table and can be simple or a complex expression which might involve multiple columns, operators, and functions.
1. Unlike SQL, our WHERE clause is immediately called in our KQL Query. We can still use the ```and``` and the ```or``` logical operators within your where clause and it evaluates to true or false against the table and can be simple or a complex expression that might involve multiple columns, operators, and functions.

```
// let's filter our dataset immediately from the source by applying a filter directly after the table.
Expand All @@ -174,7 +174,7 @@ Trips

## Use T-SQL to query summary information

KQL Database does not support T-SQL natively, but it provides a T-SQL endpoint that emulates Microsoft SQL Server and allows you to run T-SQL queries on your data. However, the T-SQL endpoint has some limitations and differences from the native SQL Server. For example, it does not support creating, altering, or dropping tables, or inserting, updating, or deleting data. It also does not support some T-SQL functions and syntax that are not compatible with KQL. It was created to allow systems that didn't support KQL to use T-SQL to query the data within a KQL Database. So, it is recommended to use KQL as the primary query language for KQL Database, as it offers more capabilities and performance than T-SQL. You can also use some SQL functions that are supported by KQL, such as count, sum, avg, min, max, etc.
KQL Database doesn't support T-SQL natively, but it provides a T-SQL endpoint that emulates Microsoft SQL Server and allows you to run T-SQL queries on your data. However, the T-SQL endpoint has some limitations and differences from the native SQL Server. For example, it doesn't support creating, altering, or dropping tables, or inserting, updating, or deleting data. It also doesn't support some T-SQL functions and syntax that aren't compatible with KQL. It was created to allow systems that didn't support KQL to use T-SQL to query the data within a KQL Database. So, it's recommended to use KQL as the primary query language for KQL Database, as it offers more capabilities and performance than T-SQL. You can also use some SQL functions that are supported by KQL, such as count, sum, avg, min, max, etc.

## ```SELECT``` data from our sample dataset using T-SQL
1.
Expand All @@ -187,7 +187,7 @@ SELECT * FROM Trips
SELECT TOP 10 * from Trips
```

2. If you use the ```//``` which is a comment in the ***Explore your data** tool within the KQL database, you cannot highlight it when executing T-SQL queries, rather you should use the standard ```--``` SQL comments notation. this will also tell the KQL Engine to expect T-SQL in Azure Data Explorer.
2. If you use the ```//```, which is a comment in the ***Explore your data** tool within the KQL database, you can't highlight it when executing T-SQL queries, rather you should use the standard ```--``` SQL comments notation. this double-hypen will also tell the KQL Engine to expect T-SQL in Azure Data Explorer.

```
-- instead of using the 'project' and 'take' keywords we simply use a standard SQL Query
Expand Down

0 comments on commit 6a1ab4f

Please sign in to comment.