Skip to content

Commit

Permalink
Implement KQL functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrk2 committed Sep 28, 2022
1 parent 083c721 commit c9eba36
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 25 deletions.
4 changes: 4 additions & 0 deletions tests/queries/0_stateless/02366_kql_extend.reference
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ Costco Apple 2 2016-09-11 Apple was purchased from Costco for $2 on 2016-09-11 2
-- extend #6 --
-- extend #7 --
-- extend #8 --
-- extend #9 --
-- extend #10 --
-- extend #11 --
5 [[2,1],[4,3]]
9 changes: 9 additions & 0 deletions tests/queries/0_stateless/02366_kql_extend.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ print '-- extend #7 --';

print '-- extend #8 --';
-- print x = 5 | extend array_sort_desc(range(0, x), range(1, x + 1))

print '-- extend #9 --';
print x = 19 | extend = 4 + ; -- { clientError SYNTAX_ERROR }

print '-- extend #10 --';
Ledger | extend PriceInCents = * Price | sort by PriceInCents asc | project Fruit, PriceInCents | summarize AveragePrice = avg(PriceInCents), Purchases = count() by Fruit | extend Sentence = strcat(Fruit, ' cost ', tostring(AveragePrice), ' on average based on ', tostring(Purchases), ' samples.') | project Sentence; -- { clientError SYNTAX_ERROR }

print '-- extend #11 --'; -- should ideally return this in the future: 5 [2,1] [4,3]
print x = 5 | extend ex = array_sort_desc(dynamic([1, 2]), dynamic([3, 4]));
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02366_kql_func_ip.reference
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fe80:0000:0000:0000:085d:e82c:9446:7994
2130706433
-- parse_ipv4(\'192.1.168.1\') < parse_ipv4(\'192.1.168.2\')
1
-- parse_ipv4(arrayStringConcat([\'127\', \'0\', \'0\', \'1\'], \'.\'))
-- parse_ipv4_mask(\'127.0.0.1\', 24) == 2130706432
1
-- parse_ipv4_mask(\'abc\', 31)
Expand Down
4 changes: 3 additions & 1 deletion tests/queries/0_stateless/02366_kql_func_ip.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ print '-- parse_ipv6(fe80::85d:e82c:9446:7994)';
print parse_ipv6('fe80::85d:e82c:9446:7994');
print '-- parse_ipv4(\'127.0.0.1\')';
print parse_ipv4('127.0.0.1');

print '-- parse_ipv4(\'192.1.168.1\') < parse_ipv4(\'192.1.168.2\')';
print parse_ipv4('192.1.168.1') < parse_ipv4('192.1.168.2');
print '-- parse_ipv4(arrayStringConcat([\'127\', \'0\', \'0\', \'1\'], \'.\'))';
print parse_ipv4(arrayStringConcat(['127', '0', '0', '1'], '.')); -- { clientError UNKNOWN_FUNCTION }

print '-- parse_ipv4_mask(\'127.0.0.1\', 24) == 2130706432';
print parse_ipv4_mask('127.0.0.1', 24) == 2130706432;
print '-- parse_ipv4_mask(\'abc\', 31)';
Expand Down
15 changes: 7 additions & 8 deletions tests/queries/0_stateless/02366_kql_func_string.reference
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ PINEAPPLE
20

20
\N
\N
\N
\N
\N
45.6
45.6

-- extract_all (https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/extractallfunction); TODO: captureGroups not supported yet
[['T','h','e'],['p','ric','e'],['P','INEAPPL','E'],['i','c','e'],['c','rea','m']]
Expand Down Expand Up @@ -298,11 +305,3 @@ asd
Number was: 1
-- has_any_index()
0 1 -1 -1
-- type convention of extract
\N
\N
\N
\N
\N
45.6
45.6
25 changes: 12 additions & 13 deletions tests/queries/0_stateless/02366_kql_func_string.sql
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,18 @@ Customers | project countof('The cat sat on the mat', 'at', 'normal') | take 1;
Customers | project countof('The cat sat on the mat', '\\s.he', 'regex') | take 1;
print '';
print '-- extract ( https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/extractfunction)';
Customers | project extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 0, 'The price of PINEAPPLE ice cream is 20') | take 1;
Customers | project extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 1, 'The price of PINEAPPLE ice cream is 20') | take 1;
Customers | project extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 2, 'The price of PINEAPPLE ice cream is 20') | take 1;
Customers | project extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 3, 'The price of PINEAPPLE ice cream is 20') | take 1;
Customers | project extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 2, 'The price of PINEAPPLE ice cream is 20', typeof(real)) | take 1;
print extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 0, 'The price of PINEAPPLE ice cream is 20');
print extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 1, 'The price of PINEAPPLE ice cream is 20');
print extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 2, 'The price of PINEAPPLE ice cream is 20');
print extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 3, 'The price of PINEAPPLE ice cream is 20');
print extract('(\\b[A-Z]+\\b).+(\\b\\d+)', 2, 'The price of PINEAPPLE ice cream is 20', typeof(real));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(bool));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(date));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(guid));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(int));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(long));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(real));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(decimal));
print '';
print '-- extract_all (https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/extractallfunction); TODO: captureGroups not supported yet';
Customers | project extract_all('(\\w)(\\w+)(\\w)','The price of PINEAPPLE ice cream is 20') | take 1;
Expand Down Expand Up @@ -220,11 +227,3 @@ print '-- replace_regex';
print replace_regex(strcat('Number is ', '1'), 'is (\d+)', 'was: \1');
print '-- has_any_index()';
print has_any_index('this is an example', dynamic(['this', 'example'])), has_any_index("this is an example", dynamic(['not', 'example'])), has_any_index("this is an example", dynamic(['not', 'found'])), has_any_index("this is an example", dynamic([]));
print '-- type convention of extract';
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(bool));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(date));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(guid));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(int));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(long));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(real));
print extract("x=([0-9.]+)", 1, "hello x=45.6|wo" , typeof(decimal));
21 changes: 20 additions & 1 deletion tests/queries/0_stateless/02366_kql_operator_in_sql.reference
Original file line number Diff line number Diff line change
@@ -1,56 +1,75 @@
-- test kql operator in sql --
-- #1 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Apple Skilled Manual Bachelors 28
-- #2 --
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
Apple Skilled Manual Bachelors 28
-- #3 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #4 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #5 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #6 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #7 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #8 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #9 --
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
Apple Skilled Manual Bachelors 28
-- #10 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #11 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #12 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #13 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #14 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Apple Skilled Manual Bachelors 28
-- #15 --
Theodore Diaz Skilled Manual Bachelors 28
Stephanie Cox Management abcd defg Bachelors 33
Latoya Shen Professional Graduate Degree 25
Expand Down
17 changes: 16 additions & 1 deletion tests/queries/0_stateless/02366_kql_operator_in_sql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,34 @@ CREATE TABLE Customers
) ENGINE = Memory;

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),('Apple','','Skilled Manual','Bachelors',28),(NULL,'why','Professional','Partial College',38);
Select '-- test kql operator in sql --' ;
Select '-- #1 --' ;
select * from kql(Customers | where FirstName !in ('Peter', 'Latoya'));
Select '-- #2 --' ;
select * from kql(Customers | where FirstName !in ("test", "test2"));
Select '-- #3 --' ;
select * from kql(Customers | where FirstName !contains 'Pet');
Select '-- #4 --' ;
select * from kql(Customers | where FirstName !contains_cs 'Pet');
Select '-- #5 --' ;
select * from kql(Customers | where FirstName !endswith 'ter');
Select '-- #6 --' ;
select * from kql(Customers | where FirstName !endswith_cs 'ter');
Select '-- #7 --' ;
select * from kql(Customers | where FirstName != 'Peter');
Select '-- #8 --' ;
select * from kql(Customers | where FirstName !has 'Peter');
Select '-- #9 --' ;
select * from kql(Customers | where FirstName !has_cs 'peter');
Select '-- #10 --' ;
select * from kql(Customers | where FirstName !hasprefix 'Peter');
Select '-- #11 --' ;
select * from kql(Customers | where FirstName !hasprefix_cs 'Peter');
Select '-- #12 --' ;
select * from kql(Customers | where FirstName !hassuffix 'Peter');
Select '-- #13 --' ;
select * from kql(Customers | where FirstName !hassuffix_cs 'Peter');
Select '-- #14 --' ;
select * from kql(Customers | where FirstName !startswith 'Peter');
Select '-- #15 --' ;
select * from kql(Customers | where FirstName !startswith_cs 'Peter');
DROP TABLE IF EXISTS Customers;
3 changes: 3 additions & 0 deletions tests/queries/0_stateless/02366_kql_summarize.reference
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ Management abcd defg 1
245 2
-- make_list_with_nulls --
['Theodore','Stephanie','Peter','Latoya','Joshua','Edward','Dalton','Christine','Cameron','Angel','Apple',NULL]
Skilled Manual ['Theodore','Peter','Edward','Christine','Apple']
Professional ['Latoya','Joshua','Dalton','Cameron','Angel',NULL]
Management abcd defg ['Stephanie']
3 changes: 2 additions & 1 deletion tests/queries/0_stateless/02366_kql_summarize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ EventLog | summarize count=count() by bin(unixtime_seconds_todatetime(Created/10
EventLog | summarize count=count() by time_label=bin(Created/1000, 1s);

print '-- make_list_with_nulls --';
Customers | summarize t = make_list_with_nulls(FirstName)
Customers | summarize t = make_list_with_nulls(FirstName);
Customers | summarize f_list = make_list_with_nulls(FirstName) by Occupation;

-- TODO:
-- arg_max()
Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02366_kql_tabular.reference
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ Christine Nara Skilled Manual Partial College 33
-- Test Filter using multi where --
Dalton Wood Professional Partial College 42
Angel Stewart Professional Partial College 46
-- Complex query with unknown function --
3 changes: 3 additions & 0 deletions tests/queries/0_stateless/02366_kql_tabular.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ Customers | project FirstName,LastName,Occupation,Education,Age | where Age > 30

print '-- Test Filter using multi where --';
Customers | project FirstName,LastName,Occupation,Education,Age | where Age > 30 | where Occupation == 'Professional';

print '-- Complex query with unknown function --';
hits | where CounterID == 62 and EventDate >= '2013-07-14' and EventDate <= '2013-07-15' and IsRefresh == 0 and DontCountHits == 0 | summarize count() by d=bin(poopoo(EventTime), 1m) | order by d | limit 10; -- { clientError UNKNOWN_FUNCTION }

0 comments on commit c9eba36

Please sign in to comment.