ClickHouse/tests/queries/0_stateless/02366_kql_makeseries.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
4.9 KiB
MySQL
Raw Normal View History

2022-09-09 17:52:16 +00:00
-- Azure Data Explore Test Data
-- let make_series_test_table = datatable (Supplier:string, Fruit:string, Price: real, Purchase:datetime)
-- [
-- 'Aldi','Apple',4,'2016-09-10',
-- 'Costco','Apple',2,'2016-09-11',
-- 'Aldi','Apple',6,'2016-09-10',
-- 'Costco','Snargaluff',100,'2016-09-12',
-- 'Aldi','Apple',7,'2016-09-12',
-- 'Aldi','Snargaluff',400,'2016-09-11',
-- 'Costco','Snargaluff',104,'2016-09-12',
-- 'Aldi','Apple',5,'2016-09-12',
-- 'Aldi','Snargaluff',600,'2016-09-11',
-- 'Costco','Snargaluff',200,'2016-09-10',
-- ];
DROP TABLE IF EXISTS make_series_test_table;
CREATE TABLE make_series_test_table
2023-12-08 19:20:48 +00:00
(
2022-09-09 17:52:16 +00:00
Supplier Nullable(String),
Fruit String ,
Price Float64,
2023-12-08 19:20:48 +00:00
Purchase Date
2022-09-09 17:52:16 +00:00
) ENGINE = Memory;
INSERT INTO make_series_test_table VALUES ('Aldi','Apple',4,'2016-09-10'), ('Costco','Apple',2,'2016-09-11'), ('Aldi','Apple',6,'2016-09-10'), ('Costco','Snargaluff',100,'2016-09-12'), ('Aldi','Apple',7,'2016-09-12'), ('Aldi','Snargaluff',400,'2016-09-11'),('Costco','Snargaluff',104,'2016-09-12'),('Aldi','Apple',5,'2016-09-12'),('Aldi','Snargaluff',600,'2016-09-11'),('Costco','Snargaluff',200,'2016-09-10');
DROP TABLE IF EXISTS make_series_test_table2;
CREATE TABLE make_series_test_table2
2023-12-08 19:20:48 +00:00
(
2022-09-09 17:52:16 +00:00
Supplier Nullable(String),
Fruit String ,
Price Int32,
2023-12-08 19:20:48 +00:00
Purchase Int32
2022-09-09 17:52:16 +00:00
) ENGINE = Memory;
INSERT INTO make_series_test_table2 VALUES ('Aldi','Apple',4,10),('Costco','Apple',2,11),('Aldi','Apple',6,10),('Costco','Snargaluff',100,12),('Aldi','Apple',7,12),('Aldi','Snargaluff',400,11),('Costco','Snargaluff',104,12),('Aldi','Apple',5,12),('Aldi','Snargaluff',600,11),('Costco','Snargaluff',200,10);
DROP TABLE IF EXISTS make_series_test_table3;
CREATE TABLE make_series_test_table3
2023-12-08 19:20:48 +00:00
(
2022-09-09 17:52:16 +00:00
timestamp datetime,
metric Float64,
) ENGINE = Memory;
2023-01-18 21:23:11 +00:00
INSERT INTO make_series_test_table3 VALUES (parseDateTimeBestEffort('2016-12-31T06:00', 'UTC'), 50), (parseDateTimeBestEffort('2017-01-01', 'UTC'), 4), (parseDateTimeBestEffort('2017-01-02', 'UTC'), 3), (parseDateTimeBestEffort('2017-01-03', 'UTC'), 4), (parseDateTimeBestEffort('2017-01-03T03:00', 'UTC'), 6), (parseDateTimeBestEffort('2017-01-05', 'UTC'), 8), (parseDateTimeBestEffort('2017-01-05T13:40', 'UTC'), 13), (parseDateTimeBestEffort('2017-01-06', 'UTC'), 4), (parseDateTimeBestEffort('2017-01-07', 'UTC'), 3), (parseDateTimeBestEffort('2017-01-08', 'UTC'), 8), (parseDateTimeBestEffort('2017-01-08T21:00', 'UTC'), 8), (parseDateTimeBestEffort('2017-01-09', 'UTC'), 2), (parseDateTimeBestEffort('2017-01-09T12:00', 'UTC'), 11), (parseDateTimeBestEffort('2017-01-10T05:00', 'UTC'), 5);
2022-09-09 17:52:16 +00:00
2023-12-08 19:20:48 +00:00
-- This test requies sorting after some of aggregations but I don't know KQL, sorry
set max_bytes_before_external_group_by = 0;
2022-09-09 17:52:16 +00:00
set dialect = 'kusto';
2023-12-08 19:20:48 +00:00
2022-09-09 17:52:16 +00:00
print '-- from to';
make_series_test_table | make-series PriceAvg = avg(Price) default=0 on Purchase from datetime(2016-09-10) to datetime(2016-09-13) step 1d by Supplier, Fruit | order by Supplier, Fruit;
print '-- from';
make_series_test_table | make-series PriceAvg = avg(Price) default=0 on Purchase from datetime(2016-09-10) step 1d by Supplier, Fruit | order by Supplier, Fruit;
print '-- to';
make_series_test_table | make-series PriceAvg = avg(Price) default=0 on Purchase to datetime(2016-09-13) step 1d by Supplier, Fruit | order by Supplier, Fruit;
print '-- without from/to';
make_series_test_table | make-series PriceAvg = avg(Price) default=0 on Purchase step 1d by Supplier, Fruit | order by Supplier, Fruit;
print '-- without by';
make_series_test_table | make-series PriceAvg = avg(Price) default=0 on Purchase step 1d;
print '-- without aggregation alias';
make_series_test_table | make-series avg(Price) default=0 on Purchase step 1d by Supplier, Fruit;
print '-- assign group alias';
make_series_test_table | make-series avg(Price) default=0 on Purchase step 1d by Supplier_Name = Supplier, Fruit;
print '-- 3d step';
make_series_test_table | make-series PriceAvg = avg(Price) default=0 on Purchase from datetime(2016-09-10) to datetime(2016-09-13) step 3d by Supplier, Fruit | order by Supplier, Fruit;
print '-- numeric column'
print '-- from to';
make_series_test_table2 | make-series PriceAvg=avg(Price) default=0 on Purchase from 10 to 15 step 1.0 by Supplier, Fruit;
print '-- from';
make_series_test_table2 | make-series PriceAvg=avg(Price) default=0 on Purchase from 10 step 1.0 by Supplier, Fruit;
print '-- to';
make_series_test_table2 | make-series PriceAvg=avg(Price) default=0 on Purchase to 18 step 4.0 by Supplier, Fruit;
print '-- without from/to';
make_series_test_table2 | make-series PriceAvg=avg(Price) default=0 on Purchase step 2.0 by Supplier, Fruit;
print '-- without by';
make_series_test_table2 | make-series PriceAvg=avg(Price) default=0 on Purchase step 2.0;
2023-12-08 19:20:48 +00:00
make_series_test_table3 | make-series avg(metric) default=0 on timestamp from datetime(2017-01-01) to datetime(2017-01-10) step 1d
-- print '-- summarize --'
-- make_series_test_table | summarize count() by format_datetime(bin(Purchase, 1d), 'yy-MM-dd');