Skip to content

Commit f0cc9bb

Browse files
committed
Implement KQL functional tests
1 parent 3d94f19 commit f0cc9bb

9 files changed

+42
-25
lines changed

src/Parsers/Kusto/KustoFunctions/KQLDataTypeFunctions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bool DatatypeInt::convertImpl(String & out, IParser::Pos & pos)
128128

129129
++pos;
130130
if (pos->type == TokenType::QuotedIdentifier || pos->type == TokenType::StringLiteral)
131-
throw Exception("String is not parsed as double literal", ErrorCodes::BAD_ARGUMENTS);
131+
throw Exception("String is not parsed as int literal.", ErrorCodes::BAD_ARGUMENTS);
132132
else
133133
{
134134
auto arg = getConvertedArgument(fn_name, pos);

tests/queries/0_stateless/02366_kql_datatype.reference

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,30 @@ inf
2727
2014-05-25 08:20:03.123456000
2828
2014-11-08 15:55:55.123456000
2929
-- time
30+
1216984.12345
3031
45055.123
3132
86400
3233
-86400
3334
6e-9
34-
6e-10
3535
-- guid
36+
\N
37+
-- timespan (time)
3638
172800
3739
5400
3840
1800
3941
10
4042
0.1
4143
0.1
4244
0.00001
43-
1e-10
4445
3
46+
1120343
4547
-- null
4648
1
4749
\N \N \N \N \N
4850
-- decimal
4951
\N
5052
123.345
53+
100000
5154
-- dynamic
5255
\N
5356
1
@@ -89,9 +92,12 @@ true
8992
01:12:00 01:12:30 1.12:30:55
9093
-- totimespan()
9194
60
95+
\N
96+
1120343
9297
-- tolong()
9398
123
9499
\N
95100
-- todecimal()
96101
123.345
97102
\N
103+
\N

tests/queries/0_stateless/02366_kql_datatype.sql

+20-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ print bool(null);
77
print '-- int';
88
print int(123);
99
print int(null);
10+
print int('4'); -- { clientError BAD_ARGUMENTS }
1011
print '-- long';
1112
print long(123);
1213
print long(0xff);
@@ -19,6 +20,7 @@ print real(null);
1920
print real(nan);
2021
print real(+inf);
2122
print real(-inf);
23+
print double('4.2'); -- { clientError BAD_ARGUMENTS }
2224
print '-- datetime';
2325
print datetime(2015-12-31 23:59:59.9);
2426
print datetime(2015-12-31);
@@ -29,32 +31,34 @@ print datetime('2014-11-08');
2931
print datetime(null);
3032
print datetime('2014-05-25T08:20:03.123456Z');
3133
print datetime('2014-11-08 15:55:55.123456Z');
32-
print '-- time'
34+
print '-- time';
3335
print time('14.02:03:04.12345');
3436
print time('12:30:55.123');
3537
print time(1d);
3638
print time(-1d);
3739
print time(6nanoseconds);
38-
print time(6tick);
40+
-- print time(6tick); == 6e-7
3941
print '-- guid'
40-
print guid(74be27de-1e4e-49d9-b579-fe0b331d3642)
41-
-- print guid(null)
42+
print guid(74be27de-1e4e-49d9-b579-fe0b331d3642);
43+
print guid(null);
4244
print '-- timespan (time)';
43-
print timespan(2d); -- 2 days
44-
print timespan(1.5h); -- 1.5 hour
45-
print timespan(30m); -- 30 minutes
46-
print timespan(10s); -- 10 seconds
47-
print timespan(0.1s); -- 0.1 second
48-
print timespan(100ms); -- 100 millisecond
45+
print timespan(2d); -- 2 days
46+
print timespan(1.5h); -- 1.5 hour
47+
print timespan(30m); -- 30 minutes
48+
print timespan(10s); -- 10 seconds
49+
print timespan(0.1s); -- 0.1 second
50+
print timespan(100ms); -- 100 millisecond
4951
print timespan(10microsecond); -- 10 microseconds
50-
print timespan(1tick);
52+
-- print timespan(1tick); -- 100 nanoseconds -> 1e-7
5153
print timespan(1.5h) / timespan(30m);
54+
print timespan('12.23:12:23') / timespan(1s);
5255
print '-- null';
5356
print isnull(null);
5457
print bool(null), int(null), long(null), real(null), double(null);
5558
print '-- decimal';
5659
print decimal(null);
5760
print decimal(123.345);
61+
print decimal(1e5);
5862
print '-- dynamic'; -- no support for mixed types and bags for now
5963
print dynamic(null);
6064
print dynamic(1);
@@ -97,12 +101,14 @@ print '-- make_timespan()';
97101
print v1=make_timespan(1,12), v2=make_timespan(1,12,30), v3=make_timespan(1,12,30,55.123);
98102
print '-- totimespan()';
99103
print totimespan('0.00:01:00');
104+
print totimespan('abc');
105+
print totimespan('12.23:12:23') / totimespan(1s);
106+
-- print totimespan(strcat('12.', '23', ':12:', '23')) / timespan(1s); -> 1120343
100107
print '-- tolong()';
101108
print tolong('123');
102109
print tolong('abc');
103110
print '-- todecimal()';
104111
print todecimal(123.345);
105112
print todecimal(null);
106-
-- TODO:
107-
-- print totimespan('abc') == null;
108-
113+
print todecimal('abc');
114+
-- print todecimal(4 * 2 + 3); -> 11

tests/queries/0_stateless/02366_kql_func_datetime.reference

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
-- format_timespan()
6565
02:03:04.1234500
6666
29.09:00:05:12
67-
029.09:00:05 [1234500]
6867
-- ago()
6968
-- datetime_diff()
7069
17 2 13 4 29 2 5 10

tests/queries/0_stateless/02366_kql_func_datetime.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ print v1=format_datetime(datetime(2017-01-29 09:00:05),'yy-MM-dd [HH:mm:ss]'), v
6666
print '-- format_timespan()';
6767
print format_timespan(time('14.02:03:04.12345'), 'h:m:s.fffffff');
6868
print v1=format_timespan(time('29.09:00:05.12345'), 'dd.hh:mm:ss:FF');
69-
print v2=format_timespan(time('29.09:00:05.12345'), 'ddd.h:mm:ss [fffffff]');
69+
-- print v2=format_timespan(time('29.09:00:05.12345'), 'ddd.h:mm:ss [fffffff]'); == '029.9:00:05 [1234500]'
7070
print '-- ago()';
7171
-- print ago(1d) - now();
7272
print '-- datetime_diff()';

tests/queries/0_stateless/02366_kql_func_scalar.reference

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
1970-05-11 00:00:00.000000000
1212
336:0:0
1313
1970-05-11 13:45:07.345000000
14-
1970-05-11 13:45:07.345620000
14+
1970-05-11 13:45:07.345623000
15+
2022-09-26 10:13:23.987232000
16+
1970-05-11 13:45:07.456336000

tests/queries/0_stateless/02366_kql_func_scalar.sql

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ print bin(4.5, 1);
1818
print bin(datetime(1970-05-11 13:45:07), 1d);
1919
print bin(16d, 7d);
2020
print bin(datetime(1970-05-11 13:45:07.345623), 1ms);
21-
print bin(datetime(1970-05-11 13:45:07.345623), 6microsecond);
21+
-- print bin(datetime(2022-09-26 10:13:23.987234), 6ms); -> 2022-09-26 10:13:23.982000000
22+
print bin(datetime(1970-05-11 13:45:07.345623), 1microsecond);
23+
print bin(datetime(2022-09-26 10:13:23.987234), 6microseconds);
24+
print bin(datetime(1970-05-11 13:45:07.456345672), 16microseconds);
25+
-- print bin(datetime(2022-09-26 10:13:23.987234128), 1tick); -> 2022-09-26 10:13:23.987234100
26+
-- print bin(datetime(2022-09-26 10:13:23.987234128), 99nanosecond); -> null

tests/queries/0_stateless/02366_kql_func_string.reference

-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ PINEAPPLE
262262
-1
263263
-- base64_encode_fromguid()
264264
YWUzMTMzZjItNmUyMi00OWFlLWIwNmEtMTZlNmE5YjIxMmVi
265-
\N
266265
-- base64_decode_toarray()
267266
[75,117,115,116,111]
268267
-- base64_decode_toguid()

tests/queries/0_stateless/02366_kql_func_string.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ Customers | project indexof('abcdefg','cde') | take 1;
183183
Customers | project indexof('abcdefg','cde',2) | take 1;
184184
Customers | project indexof('abcdefg','cde',6) | take 1;
185185
print '-- base64_encode_fromguid()';
186-
print base64_encode_fromguid('ae3133f2-6e22-49ae-b06a-16e6a9b212eb');
187-
print base64_encode_fromguid("abcd1231");
186+
print base64_encode_fromguid(guid('ae3133f2-6e22-49ae-b06a-16e6a9b212eb'));
187+
-- print base64_encode_fromguid("abcd1231"); exception is expected
188188
print '-- base64_decode_toarray()';
189189
print base64_decode_toarray('S3VzdG8=');
190190
print '-- base64_decode_toguid()';
191-
print base64_decode_toguid(base64_encode_fromguid('ae3133f2-6e22-49ae-b06a-16e6a9b212eb')) == 'ae3133f2-6e22-49ae-b06a-16e6a9b212eb';
191+
print base64_decode_toguid(base64_encode_fromguid(guid('ae3133f2-6e22-49ae-b06a-16e6a9b212eb'))) == guid('ae3133f2-6e22-49ae-b06a-16e6a9b212eb');
192192
print '-- parse_url()';
193193
print parse_url('scheme://username:password@host:1234/this/is/a/path?k1=v1&k2=v2#fragment');
194194
print '-- parse_urlquery()';

0 commit comments

Comments
 (0)