mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
dbms: add test for Enums [#METR-19265]
This commit is contained in:
parent
16912808a7
commit
19362c0cce
109
dbms/tests/queries/0_stateless/00294_enums.reference
Normal file
109
dbms/tests/queries/0_stateless/00294_enums.reference
Normal file
@ -0,0 +1,109 @@
|
||||
d Date DEFAULT CAST(\'2015-12-29\' AS Date)
|
||||
k UInt8 DEFAULT 0
|
||||
e Enum8(\'hello\' = 1, \'world\' = 2)
|
||||
sign Enum8(\'minus\' = -1, \'plus\' = 1)
|
||||
letter Enum16(\'*\' = -256, \'a\' = 0, \'b\' = 1, \'c\' = 2)
|
||||
2015-12-29 0 hello minus *
|
||||
d Date DEFAULT CAST(\'2015-12-29\' AS Date)
|
||||
k UInt8 DEFAULT 0
|
||||
e Enum8(\'hello\' = 1, \'world\' = 2, \'!\' = 3)
|
||||
sign Enum8(\'minus\' = -1, \'plus\' = 1)
|
||||
letter Enum16(\'*\' = -256, \'a\' = 0, \'b\' = 1, \'c\' = 2)
|
||||
2015-12-29 0 ! plus b
|
||||
2015-12-29 0 hello minus *
|
||||
d Date DEFAULT CAST(\'2015-12-29\' AS Date)
|
||||
k UInt8 DEFAULT 0
|
||||
e Enum16(\'hello\' = 1, \'world\' = 2, \'!\' = 3)
|
||||
sign Enum16(\'minus\' = -1, \'plus\' = 1)
|
||||
letter Enum16(\'no letter\' = -256, \'a\' = 0, \'b\' = 1, \'c\' = 2)
|
||||
2015-12-29 0 ! plus b
|
||||
2015-12-29 0 hello minus no letter
|
||||
d Date DEFAULT CAST(\'2015-12-29\' AS Date)
|
||||
k UInt8 DEFAULT 0
|
||||
e Enum8(\'hello\' = 1, \'world\' = 2, \'!\' = 3)
|
||||
sign Enum8(\'minus\' = -1, \'plus\' = 1)
|
||||
letter Enum16(\'no letter\' = -256, \'a\' = 0, \'b\' = 1, \'c\' = 2)
|
||||
2015-12-29 0 ! plus b
|
||||
2015-12-29 0 hello minus no letter
|
||||
2015-12-29 0 world minus c
|
||||
d
|
||||
b
|
||||
a
|
||||
c
|
||||
a
|
||||
d
|
||||
a
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
d
|
||||
d
|
||||
d
|
||||
c
|
||||
b
|
||||
a
|
||||
a
|
||||
2 a
|
||||
1 b
|
||||
1 c
|
||||
2 d
|
||||
d
|
||||
d
|
||||
a
|
||||
a
|
||||
d
|
||||
d
|
||||
b
|
||||
a
|
||||
c
|
||||
a
|
||||
d
|
||||
d
|
||||
b
|
||||
a
|
||||
c
|
||||
d
|
||||
b
|
||||
a
|
||||
c
|
||||
a
|
||||
d
|
||||
d
|
||||
a
|
||||
a
|
||||
d
|
||||
d
|
||||
b
|
||||
c
|
||||
d
|
||||
d 0
|
||||
b 0
|
||||
a 1
|
||||
c 0
|
||||
a 1
|
||||
d 0
|
||||
d 1
|
||||
b 0
|
||||
a 0
|
||||
c 1
|
||||
a 0
|
||||
d 1
|
||||
3 3 3 d d
|
||||
1 1 1 b b
|
||||
0 0 0 a a
|
||||
2 2 2 c c
|
||||
0 0 0 a a
|
||||
3 3 3 d d
|
||||
d
|
||||
b
|
||||
a
|
||||
c
|
||||
a
|
||||
d
|
||||
d
|
||||
b
|
||||
a
|
||||
c
|
||||
a
|
||||
d
|
79
dbms/tests/queries/0_stateless/00294_enums.sql
Normal file
79
dbms/tests/queries/0_stateless/00294_enums.sql
Normal file
@ -0,0 +1,79 @@
|
||||
drop table if exists test.enums;
|
||||
|
||||
create table test.enums (
|
||||
d Date default '2015-12-29', k default 0,
|
||||
e Enum8('world' = 2, 'hello' = 1), sign Enum8('minus' = -1, 'plus' = 1),
|
||||
letter Enum16('a' = 0, 'b' = 1, 'c' = 2, '*' = -256)
|
||||
) engine = MergeTree(d, k, 1);
|
||||
|
||||
desc table test.enums;
|
||||
|
||||
-- insert default values
|
||||
insert into test.enums (k) values (0);
|
||||
select * from test.enums;
|
||||
|
||||
alter table test.enums modify column e Enum8('world' = 2, 'hello' = 1, '!' = 3);
|
||||
desc table test.enums;
|
||||
|
||||
insert into test.enums (e, sign, letter) values ('!', 'plus', 'b');
|
||||
select * from test.enums;
|
||||
|
||||
-- expand `e` and `sign` from Enum8 to Enum16 without changing values, change values of `letter` without changing type
|
||||
alter table test.enums
|
||||
modify column e Enum16('world' = 2, 'hello' = 1, '!' = 3),
|
||||
modify column sign Enum16('minus' = -1, 'plus' = 1),
|
||||
modify column letter Enum16('a' = 0, 'b' = 1, 'c' = 2, 'no letter' = -256);
|
||||
desc table test.enums;
|
||||
|
||||
select * from test.enums;
|
||||
|
||||
alter table test.enums
|
||||
modify column e Enum8('world' = 2, 'hello' = 1, '!' = 3),
|
||||
modify column sign Enum8('minus' = -1, 'plus' = 1);
|
||||
|
||||
desc table test.enums;
|
||||
|
||||
insert into test.enums (letter, e) values ('c', 'world');
|
||||
select * from test.enums;
|
||||
|
||||
drop table test.enums;
|
||||
|
||||
create table test.enums (e Enum8('a' = 0, 'b' = 1, 'c' = 2, 'd' = 3)) engine = TinyLog;
|
||||
insert into test.enums values ('d'), ('b'), ('a'), ('c'), ('a'), ('d');
|
||||
select * from test.enums;
|
||||
|
||||
-- ORDER BY
|
||||
select * from test.enums order by e;
|
||||
select * from test.enums order by e desc;
|
||||
|
||||
-- GROUP BY
|
||||
select count(), e from test.enums group by e;
|
||||
select any(e) from test.enums;
|
||||
|
||||
-- IN
|
||||
select * from test.enums where e in ('a', 'd');
|
||||
select * from test.enums where e in (select e from test.enums);
|
||||
|
||||
-- DISTINCT
|
||||
select distinct e from test.enums;
|
||||
|
||||
-- Comparison
|
||||
select * from test.enums where e = e;
|
||||
select * from test.enums where e = 'a' or e = 'd';
|
||||
select * from test.enums where e != 'a';
|
||||
select *, e < 'b' from test.enums;
|
||||
select *, e > 'b' from test.enums;
|
||||
|
||||
-- Conversion
|
||||
select toInt8(e), toInt16(e), toUInt64(e), toString(e), e from test.enums;
|
||||
|
||||
drop table if exists test.enums_copy;
|
||||
create table test.enums_copy engine = TinyLog as select * from test.enums;
|
||||
select * from test.enums_copy;
|
||||
|
||||
drop table test.enums_copy;
|
||||
create table test.enums_copy engine = TinyLog as select * from remote('localhost', test, enums);
|
||||
select * from remote('localhost', test, enums_copy);
|
||||
|
||||
drop table test.enums_copy;
|
||||
drop table test.enums;
|
Loading…
Reference in New Issue
Block a user