2022-03-24 11:21:42 +00:00
|
|
|
DROP TABLE IF EXISTS nnd;
|
2022-03-23 19:32:30 +00:00
|
|
|
|
2022-05-30 12:49:15 +00:00
|
|
|
CREATE TABLE nnd
|
|
|
|
(
|
|
|
|
id Int8, ts DateTime64(3, 'UTC'), metric Float64
|
|
|
|
)
|
|
|
|
ENGINE=MergeTree()
|
2022-06-03 11:14:20 +00:00
|
|
|
ORDER BY id;
|
2022-05-30 12:49:15 +00:00
|
|
|
|
|
|
|
INSERT INTO nnd VALUES (1, toDateTime64('1979-12-12 21:21:21.123', 3, 'UTC'), 1.1), (2, toDateTime64('1979-12-12 21:21:21.124', 3, 'UTC'), 2.34), (3, toDateTime64('1979-12-12 21:21:21.127', 3, 'UTC'), 3.7);
|
2022-06-03 11:14:20 +00:00
|
|
|
INSERT INTO nnd VALUES (4, toDateTime64('1979-12-12 21:21:21.129', 3, 'UTC'), 2.1), (5, toDateTime('1979-12-12 21:21:22', 'UTC'), 1.3345), (6, toDateTime('1979-12-12 21:21:23', 'UTC'), 1.54), (7, toDateTime('1979-12-12 21:21:23', 'UTC'), 1.54);
|
2022-05-30 12:49:15 +00:00
|
|
|
|
|
|
|
-- shall work for precise intervals
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Nanosecond
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 3 NANOSECOND) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Microsecond
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 4 MICROSECOND) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Millisecond
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 5 MILLISECOND) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Second
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 6 SECOND) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Minute
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 7 MINUTE) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Hour
|
2022-05-30 12:49:15 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 8 HOUR) OVER (ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Day
|
2022-05-30 12:49:15 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 9 DAY) OVER (ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Week
|
2022-05-30 12:49:15 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 10 WEEK) OVER (ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd;
|
2022-03-24 11:21:42 +00:00
|
|
|
|
2022-05-30 12:49:15 +00:00
|
|
|
-- shall not work for month, quarter, year (intervals with floating number of seconds)
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Month
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 11 MONTH) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Quarter
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 12 QUARTER) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
2022-05-30 15:34:00 +00:00
|
|
|
-- Year
|
2022-05-29 00:38:42 +00:00
|
|
|
SELECT ts, metric, nonNegativeDerivative(metric, ts, INTERVAL 13 YEAR) OVER (PARTITION BY metric ORDER BY ts ASC Rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS deriv FROM nnd; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
2022-03-24 11:21:42 +00:00
|
|
|
|
|
|
|
DROP TABLE IF EXISTS nnd;
|