Docsity

Practical Implementation Of KQL, Study notes of Programming Languages

Toggle sidebar
bg1
Kusto Query Example
๎˜Kusto Queries Usage with Example
kusto query language is used for gaining insights on huge volume of data and identify patterns, statistical
analysis model development and many more.
kusto query language (kql) will be demonstrated with examples and commands for getting some overview
of the language.
Row Counting
Count operator can be used for this purpose.
For demonstration we would be using the Storm Events sample table,
stormEvents
|count
Output:
59066
Schema
Getschema would be used for this purpose
stormEvents
|getschema
Output
StartTime ๎˜๎˜ ๎˜0 System.DateTime datetime
EndTime ๎˜๎˜ ๎˜๎˜๎˜ ๎˜๎˜๎˜ ๎˜1 System.DateTime datetime
EpisodeId ๎˜๎˜ ๎˜2 System.Int32 ๎˜๎˜ ๎˜๎˜๎˜ ๎˜int
EventId ๎˜๎˜ ๎˜๎˜๎˜ ๎˜๎˜ ๎˜๎˜3 System.Int32 ๎˜๎˜ ๎˜๎˜๎˜ ๎˜int
State ๎˜๎˜ ๎˜๎˜๎˜ ๎˜๎˜๎˜ ๎˜4 System.String ๎˜๎˜ ๎˜๎˜๎˜ ๎˜string
EventType ๎˜๎˜ ๎˜5 System.String ๎˜๎˜ ๎˜๎˜๎˜ ๎˜string
InjuriesDirect ๎˜๎˜๎˜ ๎˜6 System.Int32๎˜๎˜ ๎˜๎˜๎˜ ๎˜ int
InjuriesIndirect๎˜๎˜๎˜ ๎˜7 System.Int32 int
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Practical Implementation Of KQL and more Study notes Programming Languages in PDF only on Docsity!

Kusto Query Example

Kusto Queries Usage with Example kusto query language is used for gaining insights on huge volume of data and identify patterns, statistical analysis model development and many more. kusto query language (kql) will be demonstrated with examples and commands for getting some overview of the language. Row Counting Count operator can be used for this purpose. For demonstration we would be using the Storm Events sample table, stormEvents |count Output: 59066 Schema Getschema would be used for this purpose stormEvents |getschema Output StartTime 0 System.DateTime datetime EndTime 1 System.DateTime datetime EpisodeId 2 System.Int32 int EventId 3 System.Int32 int State 4 System.String string EventType 5 System.String string InjuriesDirect 6 System.Int32 int InjuriesIndirect 7 System.Int32 int

DeathsDirect 8 System.Int32 int DeathsIndirect 9 System.Int32 int DamageProperty 10 System.Int32 int DamageCrops 11 System.Int32 int Source 12 System.String string BeginLocation 13 System.String string EndLocation 14 System.String string BeginLat 15 System.Double real BeginLon 16 System.Double real EndLat 17 System.Double real EndLon 18 System.Double real EpisodeNarrative 19 System.String string EventNarrative 20 System.String string StormSummary 21 System.Object dynamic Column Subsetting Project Operator can be used for this purpose and for filtering where clause has been used for the EventId. StormEvents | where EventId=='60913' | project EventType Output EventType Tornado Random Sampling Take is used for this purpose. StormEvents | take 5

Melbourne Beach and briefly moved toward shore.","Location":"ATLANTIC SOUTH"}} 2007-12-20T07:50:00Z 2007-12-20T07:53:00Z 12554 68796 MISSISSIPPI Thunderstorm Wind 0 0 0 0 20000 0 Emergency Manager CRANFIELD LEESDALE 31.54 -91.21 31.5452 -91.1948 A small, but potent, storm system evolved and moved east across the region during the first half of the day. A large MCV (meso-scale convective vortex) developed across Central Louisiana during the morning hours and moved east adding an extra kick to the atmosphere and aided in generating a line of severe thunderstorms which produced five tornadoes and wind damage. All the severe weather was confined to the southern areas, generally along Highway 84, and extended from Natchez to Brookhaven to Laurel. Numerous large trees were blown down with some down on power lines. Damage occurred in eastern Adams county. {"TotalDamages":20000,"StartTime":"2007-12- 20T07:50:00.0000000Z","EndTime":"2007-12-20T07:53:00.0000000Z","Details": {"Description":"Numerous large trees were blown down with some down on power lines. Damage occurred in eastern Adams county.","Location":"MISSISSIPPI"}} 2007-12-30T16:00:00Z 2007-12-30T16:05:00Z 11749 64588 GEORGIA Thunderstorm Wind 0 0 0 0 2000 0 Law Enforcement LOTTS LOTTS 31.56 -82.89 31.56 -82.89 An area of low pressure developed near the central Gulf coast states and tracked northeast along a nearly stationary front across south Georgia during the late afternoon of December 30th. Pre-frontal storms developed across south Georgia where surface based lifted indices were near -2 to -3. Storms had persistent mesocyclone rotations and several storms developed bow echo signatures with outbound velocities around 40 to 50 knots along the leading edge of the bow around 3-4 kft above ground level prior to warning issuance.The county dispatch reported several trees were blown down along Quincey Batten Loop near State Road 206. The cost of tree removal was estimated. {"TotalDamages":2000,"StartTime":"2007-12- 30T16:00:00.0000000Z","EndTime":"2007-12-30T16:05:00.0000000Z","Details": {"Description":"The county dispatch reported several trees were blown down along Quincey Batten Loop near State Road 206. The cost of tree removal was estimated.","Location":"GEORGIA"}} Sorting Result Here desc for descending order or may use asc for ascending order and top for getting first 5 rows StormEvents | top 5 by EventId desc | project EventType

Output: EventType High Surf Rip Current Rip Current Rip Current Rip Current New Column Formation: StormEvents | limit 2 | extend Duration = EndTime - StartTime | project Duration,EventType Output: Duration EventType 00:00:00 Waterspout 22:00:00 Heavy Rain Aggregration: StormEvents | summarize event_count = count() by EventType output: Show expand view EventType event_count Thunderstorm Wind 13015 Hail 12711 Flash Flood 3688 Drought 3616 Winter Weather 3349 Winter Storm 3010 Heavy Snow 2589 High Wind 2289 Frost/Freeze 1851 Flood 1787 Tornado 1238 Ice Storm 1071 Marine Thunderstorm Wind 963 Heavy Rain 836 Strong Wind 825

StormEvents | where StartTime > datetime(2007-03-12) and StartTime < datetime(2007-

| summarize event_count = count() by bin(StartTime, 2 d) Output: StartTime event_count 2007-03-12T00:00:00Z 183 2007-03-14T00:00:00Z 207 2007-03-16T00:00:00Z 391 2007-03-18T00:00:00Z 11 Chart StormEvents | summarize event_count=count(), mid = avg(BeginLat) by EventType | sort by mid | where event_count > 500 | project EventType, event_count | render columnchart StormEvents | summarize event_count=count() by bin(StartTime, 2 d) | render timechart StormEvents | where StartTime > datetime(2007-05-03) and StartTime < datetime(2007- 05-09) | where Source in ("Source","Public","Emergency Manager") | summarize count() by bin(StartTime, 5 h), Source Output: StartTime Source count_ 2007-05-02T22:00:00Z Emergency Manager 1 2007-05-03T03:00:00Z Public 2 2007-05-03T08:00:00Z Emergency Manager 3 2007-05-03T08:00:00Z Public 1 2007-05-03T13:00:00Z Emergency Manager 17 2007-05-03T13:00:00Z Public 21 2007-05-03T18:00:00Z Emergency Manager 4 2007-05-03T23:00:00Z Emergency Manager 1 2007-05-04T04:00:00Z Public 2 2007-05-04T09:00:00Z Public 4 2007-05-04T14:00:00Z Public 26

StormEvents | where EventType == "Lightning" | join ( StormEvents | where EventType == "Avalanche" ) on State | distinct State Output: State OREGON UTAH WYOMING WASHINGTON COLORADO IDAHO NEVADA Percentiles StormEvents |extend duration=EndTime-StartTime | summarize percentiles(duration, 5 , 20 , 50 , 80 , 95 ) Output: percentile_duration_5 percentile_duration_20 percentile_duration_ percentile_duration_80 percentile_duration_ 00:00:00 00:00:00 00:10:16.7570755 18:22:25. 29.05:40:09. Percentages StormEvents | where (InjuriesDirect > 0) and (InjuriesIndirect > 0) | extend Percentage = ( 100 * InjuriesDirect / (InjuriesDirect + InjuriesIndirect) ) | project StartTime, InjuriesDirect, InjuriesIndirect, Percentage Output: StartTime InjuriesDirect InjuriesIndirect Percentage 2007-05-01T16:50:00Z 1 1 50 2007-08-10T21:25:00Z 7 2 77

2007-08-23T12:05:00Z 7 22 24

2007-08-23T14:20:00Z 3 2 60

2007-09-10T13:45:00Z 4 1 80

2007-12-06T08:30:00Z 3 3 50

2007-12-08T12:00:00Z 1 1 50

Let Statement: let LightningStorms = StormEvents | where EventType == "Lightning"; let AvalancheStorms = StormEvents | where EventType == "Avalanche"; LightningStorms | join (AvalancheStorms) on State | distinct State Output: State OREGON UTAH WYOMING WASHINGTON COLORADO IDAHO NEVADA Good Luck!