2022-09-14 20:27:53 +00:00
-- datatable(FirstName:string, LastName:string, Occupation:string, Education:string, Age:int) [
-- 'Theodore', 'Diaz', 'Skilled Manual', 'Bachelors', 28,
-- 'Stephanie', 'Cox', 'Management abcd defg', 'Bachelors', 33,
-- 'Peter', 'Nara', 'Skilled Manual', 'Graduate Degree', 26,
-- 'Latoya', 'Shen', 'Professional', 'Graduate Degree', 25,
-- 'Joshua', 'Lee', 'Professional', 'Partial College', 26,
-- 'Edward', 'Hernandez', 'Skilled Manual', 'High School', 36,
-- 'Dalton', 'Wood', 'Professional', 'Partial College', 42,
-- 'Christine', 'Nara', 'Skilled Manual', 'Partial College', 33,
-- 'Cameron', 'Rodriguez', 'Professional', 'Partial College', 28,
-- 'Angel', 'Stewart', 'Professional', 'Partial College', 46,
-- 'Apple', '', 'Skilled Manual', 'Bachelors', 28,
-- dynamic(null), 'why', 'Professional', 'Partial College', 38
-- ]
2022-07-18 19:56:57 +00:00
DROP TABLE IF EXISTS Customers ;
CREATE TABLE Customers
(
FirstName Null able ( String ) ,
LastName String ,
Occupation String ,
Education String ,
Age Null able ( UInt8 )
) ENGINE = Memory ;
2022-08-05 02:33:08 +00:00
INSERT INTO Customers VALUES ( ' Theodore ' , ' Diaz ' , ' Skilled Manual ' , ' Bachelors ' , 28 ) , ( ' Stephanie ' , ' Cox ' , ' Management abcd defg ' , ' Bachelors ' , 33 ) , ( ' Peter ' , ' Nara ' , ' Skilled Manual ' , ' Graduate Degree ' , 26 ) , ( ' Latoya ' , ' Shen ' , ' Professional ' , ' Graduate Degree ' , 25 ) , ( ' Joshua ' , ' Lee ' , ' Professional ' , ' Partial College ' , 26 ) , ( ' Edward ' , ' Hernandez ' , ' Skilled Manual ' , ' High School ' , 36 ) , ( ' Dalton ' , ' Wood ' , ' Professional ' , ' Partial College ' , 42 ) , ( ' Christine ' , ' Nara ' , ' Skilled Manual ' , ' Partial College ' , 33 ) , ( ' Cameron ' , ' Rodriguez ' , ' Professional ' , ' Partial College ' , 28 ) , ( ' Angel ' , ' Stewart ' , ' Professional ' , ' Partial College ' , 46 ) , ( ' Apple ' , ' ' , ' Skilled Manual ' , ' Bachelors ' , 28 ) , ( NULL , ' why ' , ' Professional ' , ' Partial College ' , 38 ) ;
2022-09-14 20:27:53 +00:00
drop table if exists EventLog ;
create table EventLog
(
LogEntry String ,
Created Int64
) ENGINE = Memory ;
insert into EventLog values ( ' Darth Vader has entered the room. ' , 546 ) , ( ' Rambo is suspciously looking at Darth Vader. ' , 245234 ) , ( ' Darth Sidious electrocutes both using Force Lightning. ' , 245554 ) ;
2022-07-18 19:56:57 +00:00
2022-09-29 21:35:28 +00:00
drop table if exists Dates ;
create table Dates
(
EventTime DateTime ,
) ENGINE = Memory ;
Insert into Dates VALUES ( ' 2015-10-12 ' ) , ( ' 2016-10-12 ' )
2022-07-18 19:56:57 +00:00
Select ' -- test summarize -- ' ;
set dialect = ' kusto ' ;
Customers | summarize count ( ) , min ( Age ) , max ( Age ) , avg ( Age ) , sum ( Age ) ;
Customers | summarize count ( ) , min ( Age ) , max ( Age ) , avg ( Age ) , sum ( Age ) by Occupation ;
Customers | summarize countif ( Age > 40 ) by Occupation ;
Customers | summarize MyMax = maxif ( Age , Age < 40 ) by Occupation ;
Customers | summarize MyMin = minif ( Age , Age < 40 ) by Occupation ;
Customers | summarize MyAvg = avgif ( Age , Age < 40 ) by Occupation ;
Customers | summarize MySum = sumif ( Age , Age < 40 ) by Occupation ;
2022-07-27 00:24:29 +00:00
Customers | summarize dcount ( Education ) ;
2022-07-18 19:56:57 +00:00
Customers | summarize dcountif ( Education , Occupation = = ' Professional ' ) ;
2022-09-14 06:12:14 +00:00
Customers | summarize count_ = count ( ) by bin ( Age , 10 ) | order by count_ asc ;
2022-09-14 20:27:53 +00:00
Customers | summarize job_count = count ( ) by Occupation | where job_count > 0 ;
2022-10-07 02:38:18 +00:00
Customers | summarize ' Edu Count ' = count ( ) by Education | sort by ' Edu Count ' desc ; -- { clientError 62 }
2022-07-18 19:56:57 +00:00
2022-09-14 20:27:53 +00:00
print ' -- make_list() -- ' ;
2022-08-05 02:33:08 +00:00
Customers | summarize f_list = make_list ( Education ) by Occupation ;
Customers | summarize f_list = make_list ( Education , 2 ) by Occupation ;
2022-09-14 20:27:53 +00:00
print ' -- make_list_if() -- ' ;
2022-08-05 02:33:08 +00:00
Customers | summarize f_list = make_list_if ( FirstName , Age > 30 ) by Occupation ;
Customers | summarize f_list = make_list_if ( FirstName , Age > 30 , 1 ) by Occupation ;
2022-09-14 20:27:53 +00:00
print ' -- make_set() -- ' ;
2022-08-05 02:33:08 +00:00
Customers | summarize f_list = make_set ( Education ) by Occupation ;
Customers | summarize f_list = make_set ( Education , 2 ) by Occupation ;
2022-09-14 20:27:53 +00:00
print ' -- make_set_if() -- ' ;
2022-08-05 02:33:08 +00:00
Customers | summarize f_list = make_set_if ( Education , Age > 30 ) by Occupation ;
Customers | summarize f_list = make_set_if ( Education , Age > 30 , 1 ) by Occupation ;
2022-09-14 20:27:53 +00:00
print ' -- stdev() -- ' ;
2022-09-06 15:03:24 +00:00
Customers | project Age | summarize stdev ( Age ) ;
2022-09-14 20:27:53 +00:00
print ' -- stdevif() -- ' ;
2022-09-06 15:03:24 +00:00
Customers | project Age | summarize stdevif ( Age , Age % 2 = = 0 ) ;
2022-09-14 20:27:53 +00:00
print ' -- binary_all_and -- ' ;
2022-09-06 15:03:24 +00:00
Customers | project Age | where Age > 40 | summarize binary_all_and ( Age ) ;
2022-09-14 20:27:53 +00:00
print ' -- binary_all_or -- ' ;
2022-09-06 15:03:24 +00:00
Customers | project Age | where Age > 40 | summarize binary_all_or ( Age ) ;
2022-09-14 20:27:53 +00:00
print ' -- binary_all_xor -- ' ;
2022-09-06 15:03:24 +00:00
Customers | project Age | where Age > 40 | summarize binary_all_xor ( Age ) ;
2022-08-05 02:33:08 +00:00
2022-09-09 17:52:16 +00:00
Customers | project Age | summarize percentile ( Age , 95 ) ;
Customers | project Age | summarize percentiles ( Age , 5 , 50 , 95 ) ;
Customers | project Age | summarize percentiles ( Age , 5 , 50 , 95 ) [ 1 ] ;
2022-09-14 20:27:53 +00:00
Customers | summarize w = count ( ) by AgeBucket = bin ( Age , 5 ) | summarize percentilew ( AgeBucket , w , 75 ) ;
Customers | summarize w = count ( ) by AgeBucket = bin ( Age , 5 ) | summarize percentilesw ( AgeBucket , w , 50 , 75 , 99 . 9 ) ;
print ' -- Summarize following sort -- ' ;
Customers | sort by FirstName | summarize count ( ) by Occupation ;
2022-09-06 15:03:24 +00:00
2022-09-14 20:27:53 +00:00
print ' -- summarize with bin -- ' ;
EventLog | summarize count = count ( ) by bin ( Created , 1000 ) ;
EventLog | summarize count = count ( ) by bin ( unixtime_seconds_todatetime ( Created / 1000 ) , 1 s ) ;
EventLog | summarize count = count ( ) by time_label = bin ( Created / 1000 , 1 s ) ;
2022-09-29 21:35:28 +00:00
Dates | project bin ( datetime ( EventTime ) , 1 m ) ;
2022-09-27 14:24:55 +00:00
print ' -- make_list_with_nulls -- ' ;
2022-09-28 14:30:20 +00:00
Customers | summarize t = make_list_with_nulls ( FirstName ) ;
Customers | summarize f_list = make_list_with_nulls ( FirstName ) by Occupation ;
2022-09-27 14:24:55 +00:00
2022-09-14 20:27:53 +00:00
-- TODO:
2022-07-18 19:56:57 +00:00
-- arg_max()
-- arg_min()