mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-27 06:06:19 +00:00
feat: sqlness test for interval type (#2265)
* feat: add integration-test for interval type. * chore: add two cases. * chore: cr * chore: Field to Column
This commit is contained in:
@@ -111,27 +111,3 @@ DROP TABLE test_unixtime;
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
select INTERVAL '1 year 2 months 3 days 4 hours 5 minutes 6 seconds 100 microseconds';
|
||||
|
||||
+---------------------------------------------------------+
|
||||
| IntervalMonthDayNano("1109194275255040973236744059552") |
|
||||
+---------------------------------------------------------+
|
||||
| 0 years 14 mons 3 days 4 hours 5 mins 6.000100000 secs |
|
||||
+---------------------------------------------------------+
|
||||
|
||||
select INTERVAL '1 year 2 months 3 days 4 hours' + INTERVAL '1 year';
|
||||
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| IntervalMonthDayNano("1109194275255040972930743959552") + IntervalMonthDayNano("950737950171172051122527404032") |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| 0 years 26 mons 3 days 4 hours 0 mins 0.000000000 secs |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
select INTERVAL '1 year 2 months 3 days 4 hours' - INTERVAL '1 year';
|
||||
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| IntervalMonthDayNano("1109194275255040972930743959552") - IntervalMonthDayNano("950737950171172051122527404032") |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| 0 years 2 mons 3 days 4 hours 0 mins 0.000000000 secs |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
|
||||
@@ -32,8 +32,3 @@ select TO_UNIXTIME(b) from test_unixtime;
|
||||
|
||||
DROP TABLE test_unixtime;
|
||||
|
||||
select INTERVAL '1 year 2 months 3 days 4 hours 5 minutes 6 seconds 100 microseconds';
|
||||
|
||||
select INTERVAL '1 year 2 months 3 days 4 hours' + INTERVAL '1 year';
|
||||
|
||||
select INTERVAL '1 year 2 months 3 days 4 hours' - INTERVAL '1 year';
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
-- common test
|
||||
SELECT INTERVAL '1 year 2 months 3 days 4 hours 5 minutes 6 seconds 100 microseconds';
|
||||
|
||||
+---------------------------------------------------------+
|
||||
| IntervalMonthDayNano("1109194275255040973236744059552") |
|
||||
+---------------------------------------------------------+
|
||||
| 0 years 14 mons 3 days 4 hours 5 mins 6.000100000 secs |
|
||||
+---------------------------------------------------------+
|
||||
|
||||
SELECT INTERVAL '1.5 year';
|
||||
|
||||
+---------------------------------------------------------+
|
||||
| IntervalMonthDayNano("1426106925256758076683791106048") |
|
||||
+---------------------------------------------------------+
|
||||
| 0 years 18 mons 0 days 0 hours 0 mins 0.000000000 secs |
|
||||
+---------------------------------------------------------+
|
||||
|
||||
SELECT INTERVAL '-2 months';
|
||||
|
||||
+---------------------------------------------------------+
|
||||
| IntervalMonthDayNano("-158456325028528675187087900672") |
|
||||
+---------------------------------------------------------+
|
||||
| 0 years -2 mons 0 days 0 hours 0 mins 0.000000000 secs |
|
||||
+---------------------------------------------------------+
|
||||
|
||||
SELECT INTERVAL '1 year 2 months 3 days 4 hours' + INTERVAL '1 year';
|
||||
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| IntervalMonthDayNano("1109194275255040972930743959552") + IntervalMonthDayNano("950737950171172051122527404032") |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| 0 years 26 mons 3 days 4 hours 0 mins 0.000000000 secs |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
SELECT INTERVAL '1 year 2 months 3 days 4 hours' - INTERVAL '1 year';
|
||||
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| IntervalMonthDayNano("1109194275255040972930743959552") - IntervalMonthDayNano("950737950171172051122527404032") |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
| 0 years 2 mons 3 days 4 hours 0 mins 0.000000000 secs |
|
||||
+------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
SELECT INTERVAL '6 years' * 2;
|
||||
|
||||
Error: 3000(PlanQuery), This feature is not implemented: Unsupported interval operator: Multiply
|
||||
|
||||
SELECT INTERVAL '6 years' / 2;
|
||||
|
||||
Error: 3000(PlanQuery), This feature is not implemented: Unsupported interval operator: Divide
|
||||
|
||||
SELECT INTERVAL '6 years' = INTERVAL '72 months';
|
||||
|
||||
Error: 3000(PlanQuery), This feature is not implemented: Unsupported interval operator: Eq
|
||||
|
||||
SELECT arrow_typeof(INTERVAL '1 month');
|
||||
|
||||
+---------------------------------------------------------------------+
|
||||
| arrow_typeof(IntervalMonthDayNano("79228162514264337593543950336")) |
|
||||
+---------------------------------------------------------------------+
|
||||
| Interval(MonthDayNano) |
|
||||
+---------------------------------------------------------------------+
|
||||
|
||||
-- INTERVAL + TIME CONSTANT
|
||||
SELECT current_time() + INTERVAL '1 hour';
|
||||
|
||||
Error: 3000(PlanQuery), Error during planning: Cannot coerce arithmetic expression Time64(Nanosecond) + Interval(MonthDayNano) to valid types
|
||||
|
||||
-- table with interval type test
|
||||
CREATE TABLE IF NOT EXISTS intervals(
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
interval_value INTERVAL,
|
||||
);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DESCRIBE TABLE intervals;
|
||||
|
||||
+----------------+----------------------+-----+------+---------+---------------+
|
||||
| Column | Type | Key | Null | Default | Semantic Type |
|
||||
+----------------+----------------------+-----+------+---------+---------------+
|
||||
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
|
||||
| interval_value | IntervalMonthDayNano | | YES | | FIELD |
|
||||
+----------------+----------------------+-----+------+---------+---------------+
|
||||
|
||||
INSERT INTO intervals(ts, interval_value)
|
||||
values
|
||||
('2022-01-01 00:00:01', INTERVAL '1 year'),
|
||||
('2022-01-01 00:00:02', INTERVAL '1 year'),
|
||||
('2022-02-01 00:00:01', INTERVAL '2 year 2 months'),
|
||||
('2022-03-01 00:00:01', INTERVAL '3 year 3 hours'),
|
||||
('2022-04-01 00:00:01', INTERVAL '4 year 4 minutes'),
|
||||
('2022-05-01 00:00:01', INTERVAL '5 year 5 seconds'),
|
||||
('2022-06-01 00:00:01', INTERVAL '6 year 6 milliseconds'),
|
||||
('2022-07-01 00:00:01', INTERVAL '7 year 7 microseconds'),
|
||||
('2022-08-01 00:00:01', INTERVAL '8 year 8 nanoseconds'),
|
||||
('2022-09-01 00:00:01', INTERVAL '9 year 9 days'),
|
||||
('2022-10-01 00:00:01', INTERVAL '10 year 10 hours 10 minutes 10 seconds 10 milliseconds 10 microseconds 10 nanoseconds'),
|
||||
('2022-11-01 00:00:01', INTERVAL '11 year 11 days 11 hours 11 minutes 11 seconds 11 milliseconds 11 microseconds 11 nanoseconds'),
|
||||
('2022-12-01 00:00:01', INTERVAL '12 year 12 days 12 hours 12 minutes 12 seconds 12 milliseconds 12 microseconds 12 nanoseconds');
|
||||
|
||||
Affected Rows: 13
|
||||
|
||||
SELECT * FROM intervals;
|
||||
|
||||
+---------------------+-------------------------------------------------------------+
|
||||
| ts | interval_value |
|
||||
+---------------------+-------------------------------------------------------------+
|
||||
| 2022-01-01T00:00:01 | 0 years 12 mons 0 days 0 hours 0 mins 0.000000000 secs |
|
||||
| 2022-01-01T00:00:02 | 0 years 12 mons 0 days 0 hours 0 mins 0.000000000 secs |
|
||||
| 2022-02-01T00:00:01 | 0 years 26 mons 0 days 0 hours 0 mins 0.000000000 secs |
|
||||
| 2022-03-01T00:00:01 | 0 years 36 mons 0 days 3 hours 0 mins 0.000000000 secs |
|
||||
| 2022-04-01T00:00:01 | 0 years 48 mons 0 days 0 hours 4 mins 0.000000000 secs |
|
||||
| 2022-05-01T00:00:01 | 0 years 60 mons 0 days 0 hours 0 mins 5.000000000 secs |
|
||||
| 2022-06-01T00:00:01 | 0 years 72 mons 0 days 0 hours 0 mins 0.006000000 secs |
|
||||
| 2022-07-01T00:00:01 | 0 years 84 mons 0 days 0 hours 0 mins 0.000007000 secs |
|
||||
| 2022-08-01T00:00:01 | 0 years 96 mons 0 days 0 hours 0 mins 0.000000008 secs |
|
||||
| 2022-09-01T00:00:01 | 0 years 108 mons 9 days 0 hours 0 mins 0.000000000 secs |
|
||||
| 2022-10-01T00:00:01 | 0 years 120 mons 0 days 10 hours 10 mins 10.010010010 secs |
|
||||
| 2022-11-01T00:00:01 | 0 years 132 mons 11 days 11 hours 11 mins 11.011011011 secs |
|
||||
| 2022-12-01T00:00:01 | 0 years 144 mons 12 days 12 hours 12 mins 12.012012012 secs |
|
||||
+---------------------+-------------------------------------------------------------+
|
||||
|
||||
SELECT DISTINCT interval_value FROM intervals ORDER BY interval_value;
|
||||
|
||||
+-------------------------------------------------------------+
|
||||
| interval_value |
|
||||
+-------------------------------------------------------------+
|
||||
| 0 years 12 mons 0 days 0 hours 0 mins 0.000000000 secs |
|
||||
| 0 years 26 mons 0 days 0 hours 0 mins 0.000000000 secs |
|
||||
| 0 years 36 mons 0 days 3 hours 0 mins 0.000000000 secs |
|
||||
| 0 years 48 mons 0 days 0 hours 4 mins 0.000000000 secs |
|
||||
| 0 years 60 mons 0 days 0 hours 0 mins 5.000000000 secs |
|
||||
| 0 years 72 mons 0 days 0 hours 0 mins 0.006000000 secs |
|
||||
| 0 years 84 mons 0 days 0 hours 0 mins 0.000007000 secs |
|
||||
| 0 years 96 mons 0 days 0 hours 0 mins 0.000000008 secs |
|
||||
| 0 years 108 mons 9 days 0 hours 0 mins 0.000000000 secs |
|
||||
| 0 years 120 mons 0 days 10 hours 10 mins 10.010010010 secs |
|
||||
| 0 years 132 mons 11 days 11 hours 11 mins 11.011011011 secs |
|
||||
| 0 years 144 mons 12 days 12 hours 12 mins 12.012012012 secs |
|
||||
+-------------------------------------------------------------+
|
||||
|
||||
-- ts + interval
|
||||
SELECT ts + interval_value as new_value from intervals;
|
||||
|
||||
+-------------------------+
|
||||
| new_value |
|
||||
+-------------------------+
|
||||
| 2023-01-01T00:00:01 |
|
||||
| 2023-01-01T00:00:02 |
|
||||
| 2024-04-01T00:00:01 |
|
||||
| 2025-03-01T03:00:01 |
|
||||
| 2026-04-01T00:04:01 |
|
||||
| 2027-05-01T00:00:06 |
|
||||
| 2028-06-01T00:00:01.006 |
|
||||
| 2029-07-01T00:00:01 |
|
||||
| 2030-08-01T00:00:01 |
|
||||
| 2031-09-10T00:00:01 |
|
||||
| 2032-10-01T10:10:11.010 |
|
||||
| 2033-11-12T11:11:12.011 |
|
||||
| 2034-12-13T12:12:13.012 |
|
||||
+-------------------------+
|
||||
|
||||
-- ts - interval
|
||||
SELECT ts - interval_value as new_value from intervals;
|
||||
|
||||
+-------------------------+
|
||||
| new_value |
|
||||
+-------------------------+
|
||||
| 2021-01-01T00:00:01 |
|
||||
| 2021-01-01T00:00:02 |
|
||||
| 2019-12-01T00:00:01 |
|
||||
| 2019-02-28T21:00:01 |
|
||||
| 2018-03-31T23:56:01 |
|
||||
| 2017-04-30T23:59:56 |
|
||||
| 2016-06-01T00:00:00.994 |
|
||||
| 2015-07-01T00:00:00.999 |
|
||||
| 2014-08-01T00:00:00.999 |
|
||||
| 2013-08-23T00:00:01 |
|
||||
| 2012-09-30T13:49:50.989 |
|
||||
| 2011-10-20T12:48:49.988 |
|
||||
| 2010-11-18T11:47:48.987 |
|
||||
+-------------------------+
|
||||
|
||||
-- DATE + INTERVAL
|
||||
SELECT DATE '2000-10-30' + interval_value from intervals;
|
||||
|
||||
+-----------------------------------------------+
|
||||
| Utf8("2000-10-30") + intervals.interval_value |
|
||||
+-----------------------------------------------+
|
||||
| 2001-10-30 |
|
||||
| 2001-10-30 |
|
||||
| 2002-12-30 |
|
||||
| 2003-10-30 |
|
||||
| 2004-10-30 |
|
||||
| 2005-10-30 |
|
||||
| 2006-10-30 |
|
||||
| 2007-10-30 |
|
||||
| 2008-10-30 |
|
||||
| 2009-11-08 |
|
||||
| 2010-10-30 |
|
||||
| 2011-11-10 |
|
||||
| 2012-11-11 |
|
||||
+-----------------------------------------------+
|
||||
|
||||
-- DATE - INTERVAL
|
||||
-- Run failed in distributed mode, but passed in standalone mode:
|
||||
-- SELECT DATE '2000-10-30' - interval_value from intervals;
|
||||
-- INTERVAL + TIMESTAMP CONSTANT
|
||||
SELECT TIMESTAMP '1992-09-20 11:30:00.123456' + interval_value as new_value from intervals;
|
||||
|
||||
+-------------------------------+
|
||||
| new_value |
|
||||
+-------------------------------+
|
||||
| 1993-09-20T11:30:00.123456 |
|
||||
| 1993-09-20T11:30:00.123456 |
|
||||
| 1994-11-20T11:30:00.123456 |
|
||||
| 1995-09-20T14:30:00.123456 |
|
||||
| 1996-09-20T11:34:00.123456 |
|
||||
| 1997-09-20T11:30:05.123456 |
|
||||
| 1998-09-20T11:30:00.129456 |
|
||||
| 1999-09-20T11:30:00.123463 |
|
||||
| 2000-09-20T11:30:00.123456008 |
|
||||
| 2001-09-29T11:30:00.123456 |
|
||||
| 2002-09-20T21:40:10.133466010 |
|
||||
| 2003-10-01T22:41:11.134467011 |
|
||||
| 2004-10-02T23:42:12.135468012 |
|
||||
+-------------------------------+
|
||||
|
||||
-- TIMESTAMP CONSTANT - INTERVAL
|
||||
SELECT TIMESTAMP '1992-09-20 11:30:00.123456' - interval_value as new_value from intervals;
|
||||
|
||||
+-------------------------------+
|
||||
| new_value |
|
||||
+-------------------------------+
|
||||
| 1991-09-20T11:30:00.123456 |
|
||||
| 1991-09-20T11:30:00.123456 |
|
||||
| 1990-07-20T11:30:00.123456 |
|
||||
| 1989-09-20T08:30:00.123456 |
|
||||
| 1988-09-20T11:26:00.123456 |
|
||||
| 1987-09-20T11:29:55.123456 |
|
||||
| 1986-09-20T11:30:00.117456 |
|
||||
| 1985-09-20T11:30:00.123449 |
|
||||
| 1984-09-20T11:30:00.123455992 |
|
||||
| 1983-09-11T11:30:00.123456 |
|
||||
| 1982-09-20T01:19:50.113445990 |
|
||||
| 1981-09-09T00:18:49.112444989 |
|
||||
| 1980-09-07T23:17:48.111443988 |
|
||||
+-------------------------------+
|
||||
|
||||
-- Interval type does not support aggregation functions.
|
||||
SELECT MIN(interval_value) from intervals;
|
||||
|
||||
Error: 1003(Internal), Internal error: Min/Max accumulator not implemented for type Interval(MonthDayNano). This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
|
||||
|
||||
SELECT MAX(interval_value) from intervals;
|
||||
|
||||
Error: 1003(Internal), Internal error: Min/Max accumulator not implemented for type Interval(MonthDayNano). This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
|
||||
|
||||
SELECT SUM(interval_value) from intervals;
|
||||
|
||||
Error: 3000(PlanQuery), Error during planning: The function Sum does not support inputs of type Interval(MonthDayNano).
|
||||
|
||||
SELECT AVG(interval_value) from intervals;
|
||||
|
||||
Error: 3000(PlanQuery), Error during planning: The function Avg does not support inputs of type Interval(MonthDayNano).
|
||||
|
||||
DROP TABLE intervals;
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
-- common test
|
||||
SELECT INTERVAL '1 year 2 months 3 days 4 hours 5 minutes 6 seconds 100 microseconds';
|
||||
|
||||
SELECT INTERVAL '1.5 year';
|
||||
|
||||
SELECT INTERVAL '-2 months';
|
||||
|
||||
SELECT INTERVAL '1 year 2 months 3 days 4 hours' + INTERVAL '1 year';
|
||||
|
||||
SELECT INTERVAL '1 year 2 months 3 days 4 hours' - INTERVAL '1 year';
|
||||
|
||||
SELECT INTERVAL '6 years' * 2;
|
||||
|
||||
SELECT INTERVAL '6 years' / 2;
|
||||
|
||||
SELECT INTERVAL '6 years' = INTERVAL '72 months';
|
||||
|
||||
SELECT arrow_typeof(INTERVAL '1 month');
|
||||
|
||||
-- INTERVAL + TIME CONSTANT
|
||||
SELECT current_time() + INTERVAL '1 hour';
|
||||
|
||||
-- table with interval type test
|
||||
CREATE TABLE IF NOT EXISTS intervals(
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
interval_value INTERVAL,
|
||||
);
|
||||
|
||||
DESCRIBE TABLE intervals;
|
||||
|
||||
INSERT INTO intervals(ts, interval_value)
|
||||
values
|
||||
('2022-01-01 00:00:01', INTERVAL '1 year'),
|
||||
('2022-01-01 00:00:02', INTERVAL '1 year'),
|
||||
('2022-02-01 00:00:01', INTERVAL '2 year 2 months'),
|
||||
('2022-03-01 00:00:01', INTERVAL '3 year 3 hours'),
|
||||
('2022-04-01 00:00:01', INTERVAL '4 year 4 minutes'),
|
||||
('2022-05-01 00:00:01', INTERVAL '5 year 5 seconds'),
|
||||
('2022-06-01 00:00:01', INTERVAL '6 year 6 milliseconds'),
|
||||
('2022-07-01 00:00:01', INTERVAL '7 year 7 microseconds'),
|
||||
('2022-08-01 00:00:01', INTERVAL '8 year 8 nanoseconds'),
|
||||
('2022-09-01 00:00:01', INTERVAL '9 year 9 days'),
|
||||
('2022-10-01 00:00:01', INTERVAL '10 year 10 hours 10 minutes 10 seconds 10 milliseconds 10 microseconds 10 nanoseconds'),
|
||||
('2022-11-01 00:00:01', INTERVAL '11 year 11 days 11 hours 11 minutes 11 seconds 11 milliseconds 11 microseconds 11 nanoseconds'),
|
||||
('2022-12-01 00:00:01', INTERVAL '12 year 12 days 12 hours 12 minutes 12 seconds 12 milliseconds 12 microseconds 12 nanoseconds');
|
||||
|
||||
SELECT * FROM intervals;
|
||||
|
||||
SELECT DISTINCT interval_value FROM intervals ORDER BY interval_value;
|
||||
|
||||
-- ts + interval
|
||||
SELECT ts + interval_value as new_value from intervals;
|
||||
|
||||
-- ts - interval
|
||||
SELECT ts - interval_value as new_value from intervals;
|
||||
|
||||
-- DATE + INTERVAL
|
||||
SELECT DATE '2000-10-30' + interval_value from intervals;
|
||||
|
||||
-- DATE - INTERVAL
|
||||
-- Run failed in distributed mode, but passed in standalone mode:
|
||||
-- SELECT DATE '2000-10-30' - interval_value from intervals;
|
||||
|
||||
-- INTERVAL + TIMESTAMP CONSTANT
|
||||
SELECT TIMESTAMP '1992-09-20 11:30:00.123456' + interval_value as new_value from intervals;
|
||||
|
||||
-- TIMESTAMP CONSTANT - INTERVAL
|
||||
SELECT TIMESTAMP '1992-09-20 11:30:00.123456' - interval_value as new_value from intervals;
|
||||
|
||||
|
||||
-- Interval type does not support aggregation functions.
|
||||
SELECT MIN(interval_value) from intervals;
|
||||
|
||||
SELECT MAX(interval_value) from intervals;
|
||||
|
||||
SELECT SUM(interval_value) from intervals;
|
||||
|
||||
SELECT AVG(interval_value) from intervals;
|
||||
|
||||
DROP TABLE intervals;
|
||||
Reference in New Issue
Block a user