Querying Data in Azure Data Explorer Xavier Morera HELPING - - PowerPoint PPT Presentation

querying data in azure data explorer
SMART_READER_LITE
LIVE PREVIEW

Querying Data in Azure Data Explorer Xavier Morera HELPING - - PowerPoint PPT Presentation

Querying Data in Azure Data Explorer Xavier Morera HELPING DEVELOPERS UNDERSTAND SEARCH & BIG DATA @xmorera www.xaviermorera.com A Query Query Results Executing Queries Kusto Web UI Integration with Kusto Explorer other products


slide-1
SLIDE 1

@xmorera www.xaviermorera.com

HELPING DEVELOPERS UNDERSTAND SEARCH & BIG DATA

Xavier Morera

Querying Data in Azure Data Explorer

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4

A Query

slide-5
SLIDE 5

Query Results

slide-6
SLIDE 6

Kusto Web UI

Executing Queries

Integration with

  • ther products

Kusto Explorer

slide-7
SLIDE 7
slide-8
SLIDE 8

Getting to Know the Kusto Query Language

slide-9
SLIDE 9

A Kusto query is a read-only request to process data and return results

slide-10
SLIDE 10

A Kusto query is a read-only request to process data and return results

slide-11
SLIDE 11
slide-12
SLIDE 12

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

A Kusto Query

Plain text statement Data-flow model

  • Designed to make the syntax easy to read, author, and automate
slide-13
SLIDE 13

s h s

Kusto query

  • Uses schema entities
  • Organized in a hierarchy
  • Similar to SQL’s databases, tables, and columns

Functions are supported

  • Stored, query-defined, and built-in
slide-14
SLIDE 14

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

A Kusto Query

slide-15
SLIDE 15

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

A Kusto Query

Sequence of query statements

slide-16
SLIDE 16

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

A Kusto Query

Sequence of query statements

  • Delimited by a semicolon (;)
slide-17
SLIDE 17

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

A Kusto Query

Sequence of query statements

  • Delimited by a semicolon (;)

At least one statement being a tabular expression statement

slide-18
SLIDE 18

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

Tabular Expression Statement

Structure of a tabular expression statement

slide-19
SLIDE 19

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

Tabular Expression Statement

Structure of a tabular expression statement

  • Tabular data sources
  • Database is implicit
  • Part of the connection information
slide-20
SLIDE 20

StormEvents | where StartTime > datetime(2007-02-01) | where EventType == 'Flood' and State == 'CALIFORNIA’ | project StartTime, EndTime , State , EventType | take 10;

Statement Syntax

Data flow from one tabular query operator to another Through a set of data transformation operators

  • Optionally, a render instruction as the last statement

Bound together by a pipe (|) delimiter

slide-21
SLIDE 21

source1 | operator1 | operator2 | [renderInstruction]

Kusto Query

slide-22
SLIDE 22

KQL & SQL

slide-23
SLIDE 23

StormEvents StormEvents | where notnull(State) | project EpisodeId, State, StormEvents | summarize Count=count() by State | project State, Count | sort by Count desc | take int(100), Select * FROM StormEvents SELECT EpisodeId, State FROM StormEvents WHERE State IS NOT NULL SELECT TOP 100 State, COUNT(*) as Count FROM StormEvents GROUP BY State ORDER BY Count DESC

KQL SQL

slide-24
SLIDE 24

Demo

t h s

SQL to Kusto query translation Using EXPLAIN

slide-25
SLIDE 25

Querying Azure Data Explorer, the help Cluster, and the Sample Database

slide-26
SLIDE 26

The help Cluster and Sample Database

Data Explorer provides a help cluster

  • Created to aid learning

Contains sample data

  • StormEvents
  • Other databases
  • External tables
  • Functions

No need for you to spin up a cluster to test

slide-27
SLIDE 27

Demo

t h s

The help Cluster and Sample Databases

slide-28
SLIDE 28

https://help.kusto.windows.net/

slide-29
SLIDE 29
slide-30
SLIDE 30

Control Commands

slide-31
SLIDE 31

Control Commands

Retrieve data not in the database tables Requests to modify the state Three mechanisms to tell apart from queries

  • Language level
  • Start with a dot (.)
  • Protocol level
  • Different endpoint
  • API level
  • Different functions
slide-32
SLIDE 32

.show cluster

A Control Command

Control command to show cluster information

slide-33
SLIDE 33

.show cluster | count

A Control Command

Control command to show cluster information Command can be combined with a query

  • Must start with the command
  • Query cannot contain a command
slide-34
SLIDE 34

commands queries table schema tables databases capacity cluster

.show

slide-35
SLIDE 35

.create table .create-merge table .rename table .drop table

Table Management

Create a table in the current database

  • Or extend an existing table

Rename And drop

slide-36
SLIDE 36

Demo

t h s

Control commands

slide-37
SLIDE 37
slide-38
SLIDE 38

The Kusto Query Language (KQL)

slide-39
SLIDE 39
slide-40
SLIDE 40

Format Data Column Related Sort / Aggregate Date / Time Filter

Types of Commands

slide-41
SLIDE 41

T T | where Predicate where search [T [T] | ] | s search ch [ki [kind=Ca CaseSens nsitivi vity] ] [i [in ( (Ta TableSources)] )] Se SearchPredic icate

Filter Commands

slide-42
SLIDE 42

Filters on a predicate Similar to SQL Searches all columns

  • In the specified table
  • Or all tables
  • For the value

where search

StormEvents | search "heavy rain" StormEvents | where DamageCrops > 0

slide-43
SLIDE 43

and, or, ==, !=, =~, !~, <, >...

Predicates

has, !has, contains, !contains, startswith, endswith, matches... between, not-between, distinct in, !in case

slide-44
SLIDE 44

Looks for a specific word Better performance Looks for any substring match

has contains

StormEvents | where EventType contains "Storm" StormEvents | where EventType has "Storm"

slide-45
SLIDE 45

now

Date and Time

ago totimespan datetime_add, datetime_diff... dayofyear, dayofmonth, dayofweek...

slide-46
SLIDE 46

range join union count dcount dcountif summarize make-series top sort by

  • rder by

Sort and Aggregate

slide-47
SLIDE 47

extend project-away project

Columns

slide-48
SLIDE 48

parse mv-expand lookup format_datetime format_timespan

Format Data Commands

slide-49
SLIDE 49

Demo

t h s

The Basics of KQL

slide-50
SLIDE 50

https://docs.microsoft.com /en-us/azure/data- explorer/kql-quick- reference

slide-51
SLIDE 51

More KQL Operators

slide-52
SLIDE 52

Demo

t h s

More KQL Operators

slide-53
SLIDE 53

s h s

Bind names to expressions Name can be used

  • To refer to its bound value
  • Within current scope

When previously defined

  • Innermost let state binding used

Improve modularity

  • Break complex expressions

let

slide-54
SLIDE 54

let Name = ScalarExpression

let

Bind names to expressions

slide-55
SLIDE 55

let Name = TabularExpression

let

Bind names to expressions

slide-56
SLIDE 56

let Name = FunctionDefinitionExpression

let

Bind names to expressions

slide-57
SLIDE 57

let f=(a:int, b:string) { strcat(b, ":", a) }

let

Bind names to expressions

slide-58
SLIDE 58

Advanced KQL

slide-59
SLIDE 59

Machine learning Time series analysis

Advanced KQL

slide-60
SLIDE 60

Time Series Analysis

Analyze time series

  • Discover deviations
  • Compared to a baseline

Native support

  • Creation, manipulation, and analysis
  • Of time-series data

Enables near real-time monitoring

slide-61
SLIDE 61

let min_t = toscalar(TABLE| summarize min(TIMESTAMP)); let max_t = toscalar(TABLE| summarize max(TIMESTAMP)); let dt = 1h; TABLE | make-series num=count() default=0 on TIMESTAMP in range(min_t, max_t, dt) by COLUMN | render timechart

Time Series Analysis

Native series support

slide-62
SLIDE 62

let min_t = datetime(2017-01-05); let max_t = datetime(2017-02-03 22:00); let dt = 2h; demo_make_series2 | make-series num=avg(num) on TimeStamp from min_t to max_t step dt by sid | where sid == 'TS1’ | extend (anomalies, score, baseline) = series_decompose_anomalies(num, 1.5, -1, 'linefit’) | render anomalychart with(anomalycolumns=anomalies, title='Web app. traffic of a month, anomalies')

Time Series Anomaly Detection

Step by step

slide-63
SLIDE 63

Time Analysis Complex Functions

series_fir series_fit_line series_periods_detect series_fit_2lines series_iir series_periods_validate

slide-64
SLIDE 64

Machine Learning

Perform Root Cause Analysis

  • Complex and lengthy process

Three Machine Learning plugins

  • Autocluster
  • Basket
  • Diffpatterns
slide-65
SLIDE 65

Demo

t h s

Advanced KQL

slide-66
SLIDE 66

Querying External Tables

slide-67
SLIDE 67

Querying External Tables

Query data stored outside a Kusto cluster External tables

  • Recognized as database entities
  • Just like regular Kusto tables

Create external table

  • Data lake
  • Different formats supported
slide-68
SLIDE 68

Demo

t h s

Querying External Tables

slide-69
SLIDE 69

Data

All data

slide-70
SLIDE 70

Partitioned Data

2020 2019 2018

slide-71
SLIDE 71

(.create | .alter) external table TableName ( Schema ) kind = (blob | adl) [partition by ( Partitions ) [pathformat = ( PathFormat )]] dataformat = Format ( StorageConnectionString [, ...] ) [with (PropertyName = Value , ... )]

Create External Table with Partition

slide-72
SLIDE 72

Querying Data in Azure Monitor and Using the Flow Kusto Connector

slide-73
SLIDE 73

Query Data in Azure Monitor

Proxy Cluster (ADX Proxy)

  • Enables cross product queries

Data Explorer

  • The Azure Monitor Service
  • Application Insights (AI)
  • Log Analytics (LA)

Create a connection from ADX Web UI

  • To Application Insights/Log Analytics
  • Using virtual cluster
slide-74
SLIDE 74

https://ade.loganalytics.io/ subscriptions/ <subscription-id>/ resourcegroups/ <resource-group-name>/ providers/ microsoft.operationalinsights/ workspaces/ <workspace-name>

Log Analytics

slide-75
SLIDE 75

https://ade.applicationinsights.io/ subscriptions/ <subscription-id>/ resourcegroups/ <resource-group-name>/ providers/ microsoft.insights/ components/ <ai-app-name>

Application Insights

slide-76
SLIDE 76

https://aka.ms/LADemo

slide-77
SLIDE 77

Flow Connector

Azure Data Explorer flow connector

  • Allows to use flow capabilities
  • Microsoft Power Automate

Run Kusto queries and commands

  • Automatically on a schedule
  • Or triggered task

Useful to send reports, notifications, control command or export/import data

slide-78
SLIDE 78

Exporting Data

slide-79
SLIDE 79

Kusto Explorer

  • r Web UI

ingest from query .export

Client-side

Exporting Data

Service-side (pull) Service-side (push)

slide-80
SLIDE 80

Demo

t h s

Exporting Data

slide-81
SLIDE 81

t h s

What is a query?

  • A question
  • Answered with the information

available at hand Query in Data Explorer

  • Using Kusto Query Language
  • Web UI, Kusto Explorer, and other

products (integrations)

  • Sample database available (help)

Takeaway

slide-82
SLIDE 82

t h s

KQL

  • Control commands
  • Retrieve information
  • Modify service state
  • Read-only query

Basic

  • Filter, date/time, sort/aggregate,

column related, and format data Advanced KQL

  • Time series analysis and machine

learning

Takeaway