1+ -- name: test_decimal_cast
2+ CREATE TABLE t1 (
3+     k1 bigint NULL,
4+ 
5+     c_tinyint tinyint null,
6+     c_int int null,
7+     c_bigint bigint null,
8+     c_largeint largeint null
9+ ) ENGINE=OLAP
10+ DUPLICATE KEY(`k1`)
11+ DISTRIBUTED BY HASH(`k1`) BUCKETS 96
12+ PROPERTIES (
13+     "replication_num" = "1"
14+ );
15+ -- result:
16+ -- !result
17+ insert into t1 values
18+     (1, 127, 2147483647, 9223372036854775807, 170141183460469231731687303715884105727),
19+     (2, -128, -2147483648, -9223372036854775808, -170141183460469231731687303715884105728),
20+     (3, null, null, null, null),
21+     (4, 0, 0, 0, 0),
22+     (5, 1, 1, 1, 1),
23+     (6, -1, -1, -1, -1),
24+     (7, 12, 214748364, 922337203685477580, 17014118346046923173168730371588410572),
25+     (8, -12, -214748364, -922337203685477580, -17014118346046923173168730371588410572);
26+ -- result:
27+ -- !result
28+ select 
29+     k1,
30+     cast(c_tinyint as DECIMAL(9,0)),
31+     cast(c_int as DECIMAL(9,0)),
32+     cast(c_bigint as DECIMAL(9,0)),
33+     cast(c_largeint as DECIMAL(9,0))
34+ from t1
35+ order by k1;
36+ -- result:
37+ 1	127	2147483647	9223372036854775807	None
38+ 2	-128	-2147483648	-9223372036854775808	None
39+ 3	None	None	None	None
40+ 4	0	0	0	0
41+ 5	1	1	1	1
42+ 6	-1	-1	-1	-1
43+ 7	12	214748364	922337203685477580	None
44+ 8	-12	-214748364	-922337203685477580	None
45+ -- !result
46+ select 
47+     k1,
48+     cast(c_tinyint as DECIMAL(9,1)),
49+     cast(c_int as DECIMAL(9,1)),
50+     cast(c_bigint as DECIMAL(9,1)),
51+     cast(c_largeint as DECIMAL(9,1))
52+ from t1
53+ order by k1;
54+ -- result:
55+ 1	127.0	2147483647.0	None	None
56+ 2	-128.0	-2147483648.0	None	None
57+ 3	None	None	None	None
58+ 4	0.0	0.0	0.0	0.0
59+ 5	1.0	1.0	1.0	1.0
60+ 6	-1.0	-1.0	-1.0	-1.0
61+ 7	12.0	214748364.0	922337203685477580.0	None
62+ 8	-12.0	-214748364.0	-922337203685477580.0	None
63+ -- !result
64+ select 
65+     k1,
66+     cast(c_tinyint as DECIMAL(27,0)),
67+     cast(c_int as DECIMAL(27,0)),
68+     cast(c_bigint as DECIMAL(27,0)),
69+     cast(c_largeint as DECIMAL(27,0))
70+ from t1
71+ order by k1;
72+ -- result:
73+ 1	127	2147483647	9223372036854775807	170141183460469231731687303715884105727
74+ 2	-128	-2147483648	-9223372036854775808	-170141183460469231731687303715884105728
75+ 3	None	None	None	None
76+ 4	0	0	0	0
77+ 5	1	1	1	1
78+ 6	-1	-1	-1	-1
79+ 7	12	214748364	922337203685477580	17014118346046923173168730371588410572
80+ 8	-12	-214748364	-922337203685477580	-17014118346046923173168730371588410572
81+ -- !result
82+ select 
83+     k1,
84+     cast(c_tinyint as DECIMAL(27,1)),
85+     cast(c_int as DECIMAL(27,1)),
86+     cast(c_bigint as DECIMAL(27,1)),
87+     cast(c_largeint as DECIMAL(27,1))
88+ from t1
89+ order by k1;
90+ -- result:
91+ 1	127.0	2147483647.0	9223372036854775807.0	None
92+ 2	-128.0	-2147483648.0	-9223372036854775808.0	None
93+ 3	None	None	None	None
94+ 4	0.0	0.0	0.0	0.0
95+ 5	1.0	1.0	1.0	1.0
96+ 6	-1.0	-1.0	-1.0	-1.0
97+ 7	12.0	214748364.0	922337203685477580.0	17014118346046923173168730371588410572.0
98+ 8	-12.0	-214748364.0	-922337203685477580.0	-17014118346046923173168730371588410572.0
99+ -- !result
100+ select 
101+     k1,
102+     cast(c_tinyint as DECIMAL(38,0)),
103+     cast(c_int as DECIMAL(38,0)),
104+     cast(c_bigint as DECIMAL(38,0)),
105+     cast(c_largeint as DECIMAL(38,0))
106+ from t1
107+ order by k1;
108+ -- result:
109+ 1	127	2147483647	9223372036854775807	170141183460469231731687303715884105727
110+ 2	-128	-2147483648	-9223372036854775808	-170141183460469231731687303715884105728
111+ 3	None	None	None	None
112+ 4	0	0	0	0
113+ 5	1	1	1	1
114+ 6	-1	-1	-1	-1
115+ 7	12	214748364	922337203685477580	17014118346046923173168730371588410572
116+ 8	-12	-214748364	-922337203685477580	-17014118346046923173168730371588410572
117+ -- !result
118+ select 
119+     k1,
120+     cast(c_tinyint as DECIMAL(38,1)),
121+     cast(c_int as DECIMAL(38,1)),
122+     cast(c_bigint as DECIMAL(38,1)),
123+     cast(c_largeint as DECIMAL(38,1))
124+ from t1
125+ order by k1;
126+ -- result:
127+ 1	127.0	2147483647.0	9223372036854775807.0	None
128+ 2	-128.0	-2147483648.0	-9223372036854775808.0	None
129+ 3	None	None	None	None
130+ 4	0.0	0.0	0.0	0.0
131+ 5	1.0	1.0	1.0	1.0
132+ 6	-1.0	-1.0	-1.0	-1.0
133+ 7	12.0	214748364.0	922337203685477580.0	17014118346046923173168730371588410572.0
134+ 8	-12.0	-214748364.0	-922337203685477580.0	-17014118346046923173168730371588410572.0
135+ -- !result
136+ select k1, c_tinyint * 0, c_int * 0, c_bigint * 0, c_largeint * 0 from t1 order by k1;
137+ -- result:
138+ 1	0	0	0	0
139+ 2	0	0	0	0
140+ 3	None	None	None	None
141+ 4	0	0	0	0
142+ 5	0	0	0	0
143+ 6	0	0	0	0
144+ 7	0	0	0	0
145+ 8	0	0	0	0
146+ -- !result
147+ select k1, c_tinyint * 1, c_int * 1, c_bigint * 1, c_largeint * 1 from t1 order by k1;
148+ -- result:
149+ 1	127	2147483647	9223372036854775807	170141183460469231731687303715884105727
150+ 2	-128	-2147483648	-9223372036854775808	-170141183460469231731687303715884105728
151+ 3	None	None	None	None
152+ 4	0	0	0	0
153+ 5	1	1	1	1
154+ 6	-1	-1	-1	-1
155+ 7	12	214748364	922337203685477580	17014118346046923173168730371588410572
156+ 8	-12	-214748364	-922337203685477580	-17014118346046923173168730371588410572
157+ -- !result
158+ select k1, cast(c_tinyint * 0 as decimal(38, 0)), cast(c_int * 0 as decimal(38, 0)), cast(c_bigint * 0 as decimal(38, 0)), cast(c_largeint * 0 as decimal(38, 0)) from t1 order by k1;
159+ -- result:
160+ 1	0	0	0	0
161+ 2	0	0	0	0
162+ 3	None	None	None	None
163+ 4	0	0	0	0
164+ 5	0	0	0	0
165+ 6	0	0	0	0
166+ 7	0	0	0	0
167+ 8	0	0	0	0
168+ -- !result
169+ select k1, cast(c_tinyint * 1 as decimal(38, 0)), cast(c_int * 1 as decimal(38, 0)), cast(c_bigint * 1 as decimal(38, 0)), cast(c_largeint * 1 as decimal(38, 0)) from t1 order by k1;
170+ -- result:
171+ 1	127	2147483647	9223372036854775807	170141183460469231731687303715884105727
172+ 2	-128	-2147483648	-9223372036854775808	-170141183460469231731687303715884105728
173+ 3	None	None	None	None
174+ 4	0	0	0	0
175+ 5	1	1	1	1
176+ 6	-1	-1	-1	-1
177+ 7	12	214748364	922337203685477580	17014118346046923173168730371588410572
178+ 8	-12	-214748364	-922337203685477580	-17014118346046923173168730371588410572
179+ -- !result
0 commit comments