Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 846442d

Browse files
committed
fix(query): enable duckdb e2e compatibility cases
1 parent 622cb97 commit 846442d

16 files changed

Lines changed: 300 additions & 181 deletions

File tree

src/query/functions/src/scalars/arithmetic/src/arithmetic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ fn parse_number<T>(
289289
where
290290
T: FromStr + num_traits::Num,
291291
{
292+
let s = s.trim();
292293
match s.parse::<T>() {
293294
Ok(v) => Ok(v),
294295
Err(e) => {

src/query/functions/src/scalars/boolean.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,10 @@ fn eval_boolean_to_string(val: Value<BooleanType>, ctx: &mut EvalContext) -> Val
477477

478478
fn eval_string_to_boolean(val: Value<StringType>, ctx: &mut EvalContext) -> Value<BooleanType> {
479479
vectorize_with_builder_1_arg::<StringType, BooleanType>(|val, output, ctx| {
480-
if val.eq_ignore_ascii_case("true") {
480+
let val = val.trim();
481+
if val.eq_ignore_ascii_case("true") || val == "1" {
481482
output.push(true);
482-
} else if val.eq_ignore_ascii_case("false") {
483+
} else if val.eq_ignore_ascii_case("false") || val == "0" {
483484
output.push(false);
484485
} else {
485486
ctx.set_error(output.len(), "cannot parse to type `BOOLEAN`");

tests/sqllogictests/suites/duckdb/common/test_cast_hugeint.test

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ INSERT INTO broken_doubles VALUES (1361129467683753853853498429727072845824.0),
7777
# 9.223372036854776e18
7878
# -9.223372036854776e18
7979

80+
# Keep the string/HUGEINT blocks commented for now: they rely on DuckDB's
81+
# HUGEINT and overflow handling semantics. Databend currently casts BIGINT to
82+
# Int64-compatible ranges and reports overflow instead of silently widening,
83+
# saturating, or wrapping.
84+
8085
# statement ok
8186
# CREATE TABLE working_strings(f VARCHAR)
8287

@@ -109,23 +114,35 @@ SELECT typeof(18446744073709551615), 18446744073709551615
109114
----
110115
BIGINT UNSIGNED 18446744073709551615
111116

112-
# query II
113-
# SELECT typeof(4832904823908104981209840981240981277), 4832904823908104981209840981240981277
117+
query TR
118+
SELECT typeof(4832904823908104981209840981240981277), 4832904823908104981209840981240981277
119+
----
120+
DECIMAL(37, 0) 4832904823908104981209840981240981277
114121

115-
# query II
116-
# SELECT typeof(48329048239081049812098409812409812772), 48329048239081049812098409812409812772
122+
query TR
123+
SELECT typeof(48329048239081049812098409812409812772), 48329048239081049812098409812409812772
124+
----
125+
DECIMAL(38, 0) 48329048239081049812098409812409812772
117126

118-
# query II
119-
# SELECT typeof(483290482390810498120984098124098127725), 483290482390810498120984098124098127725
127+
query TR
128+
SELECT typeof(483290482390810498120984098124098127725), 483290482390810498120984098124098127725
129+
----
130+
DECIMAL(39, 0) 483290482390810498120984098124098127725
120131

121-
# query II
122-
# SELECT typeof(4832904823908104981209840981240981277256), 4832904823908104981209840981240981277256
132+
query TR
133+
SELECT typeof(4832904823908104981209840981240981277256), 4832904823908104981209840981240981277256
134+
----
135+
DECIMAL(40, 0) 4832904823908104981209840981240981277256
123136

124-
# query II
125-
# SELECT typeof(48329048239081049812098409812409812772568), 48329048239081049812098409812409812772568
137+
query TR
138+
SELECT typeof(48329048239081049812098409812409812772568), 48329048239081049812098409812409812772568
139+
----
140+
DECIMAL(41, 0) 48329048239081049812098409812409812772568
126141

127-
# query II
128-
# SELECT typeof(483290482390810498120984098124098127725683), 483290482390810498120984098124098127725683
142+
query TR
143+
SELECT typeof(483290482390810498120984098124098127725683), 483290482390810498120984098124098127725683
144+
----
145+
DECIMAL(42, 0) 483290482390810498120984098124098127725683
129146

130147
query T
131148
SELECT 0::BIGINT::VARCHAR
@@ -137,35 +154,33 @@ select '255'::BIGINT::UINT8
137154
----
138155
255
139156

140-
# TODO https://github.com/datafuselabs/databend/issues/7347
141-
# statement error xxx
142-
# select '-1'::BIGINT::uint8
157+
statement error 1006
158+
select '-1'::BIGINT::uint8
143159

144-
# TODO https://github.com/datafuselabs/databend/issues/7347
145-
# statement error xxx
146-
# select '256'::BIGINT::uint8
160+
statement error 1006
161+
select '256'::BIGINT::uint8
147162

148163
query I
149164
select '65535'::BIGINT::UINT16
150165
----
151166
65535
152167

153-
# TODO https://github.com/datafuselabs/databend/issues/7347
154-
# statement error xxx
155-
# select '-1'::BIGINT::uint16
168+
statement error 1006
169+
select '-1'::BIGINT::uint16
156170

157-
# TODO https://github.com/datafuselabs/databend/issues/7347
158-
# statement error xxx
159-
# select '65536'::BIGINT::uint16
171+
statement error 1006
172+
select '65536'::BIGINT::uint16
160173

161174
query I
162175
select '4294967295'::BIGINT::UINT32
163176
----
164177
4294967295
165178

166-
# TODO https://github.com/datafuselabs/databend/issues/7347
167-
# statement error xxx
168-
# select '-1'::BIGINT::uint32
179+
statement error 1006
180+
select '-1'::BIGINT::uint32
181+
182+
# Keep this commented for now: DuckDB expects UINT32 saturation to 4294967295,
183+
# while Databend currently treats the out-of-range cast as overflow.
169184

170185
# TODO https://github.com/datafuselabs/databend/issues/7347
171186
# query I
@@ -177,9 +192,8 @@ select '4294967295'::BIGINT::UINT32
177192
statement error 1006
178193
select '18446744073709551615'::BIGINT::UINT64
179194

180-
# TODO https://github.com/datafuselabs/databend/issues/7347
181-
# statement error XXX
182-
# select '-1'::BIGINT::UINT64
195+
statement error 1006
196+
select '-1'::BIGINT::UINT64
183197

184198
statement error 1006
185199
select '18446744073709551616'::BIGINT::UINT64
@@ -199,10 +213,13 @@ select '4294967295'::UINT32::BIGINT
199213
----
200214
4294967295
201215

216+
# Keep this commented for now: the UINT64 value cannot fit in Databend's signed
217+
# BIGINT/Int64 range. Returning a value here would require a separate decision
218+
# on widening, saturation, or wrapping semantics.
219+
202220
# TODO https://github.com/datafuselabs/databend/issues/7347
203221
# query I
204222
# select '18446744073709551615'::UINT64::BIGINT
205223

206224
# ----
207225
# 18446744073709551615
208-
Lines changed: 89 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# statement error 1025
2-
# with test(round) as (
3-
# select 0
4-
# union all
5-
# select round+1 from test where round <= 20
6-
# )
7-
# select test.round
8-
# from
9-
# (select round from test limit 1) as subselect,
10-
# test
1+
statement error 1065
2+
with test(round) as (
3+
select 0
4+
union all
5+
select round+1 from test where round <= 20
6+
)
7+
select test.round
8+
from
9+
(select round from test limit 1) as subselect,
10+
test
1111

1212
query I
1313
with test(round) as (
@@ -31,35 +31,84 @@ from
3131
----
3232
0 0
3333

34-
# statement error 1025
35-
# with recursive test(round) as (
36-
# select 0
37-
# union all
38-
# select round+1 from test where round <= 20
39-
# )
40-
# select test.round
41-
# from
42-
# test
43-
44-
# statement error 1025
45-
# with recursive test(round) as (
46-
# select 0
47-
# union all
48-
# select round+1 from test where round <= 20
49-
# )
50-
# select count(*)
51-
# from
52-
# (select round from test limit 1) as subselect,
53-
# test
34+
query I
35+
with recursive test(round) as (
36+
select 0
37+
union all
38+
select round+1 from test where round <= 20
39+
)
40+
select test.round
41+
from
42+
test
43+
order by test.round
44+
----
45+
0
46+
1
47+
2
48+
3
49+
4
50+
5
51+
6
52+
7
53+
8
54+
9
55+
10
56+
11
57+
12
58+
13
59+
14
60+
15
61+
16
62+
17
63+
18
64+
19
65+
20
66+
21
5467

55-
# statement error 1025
56-
# with recursive test(round) as (
57-
# select 0
58-
# union all
59-
# select round+1 from test where round <= 20
60-
# )
61-
# select *
62-
# from
63-
# (select round from test limit 1) as subselect,
64-
# test
68+
query I
69+
with recursive test(round) as (
70+
select 0
71+
union all
72+
select round+1 from test where round <= 20
73+
)
74+
select count(*)
75+
from
76+
(select round from test limit 1) as subselect,
77+
test
78+
----
79+
22
6580

81+
query II
82+
with recursive test(round) as (
83+
select 0
84+
union all
85+
select round+1 from test where round <= 20
86+
)
87+
select *
88+
from
89+
(select round from test limit 1) as subselect,
90+
test
91+
order by test.round
92+
----
93+
0 0
94+
0 1
95+
0 2
96+
0 3
97+
0 4
98+
0 5
99+
0 6
100+
0 7
101+
0 8
102+
0 9
103+
0 10
104+
0 11
105+
0 12
106+
0 13
107+
0 14
108+
0 15
109+
0 16
110+
0 17
111+
0 18
112+
0 19
113+
0 20
114+
0 21
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,59 @@
1-
# CTEs on Insert/update/delete statements
2-
# issue https://github.com/datafuselabs/databend/issues/7356
1+
statement ok
2+
drop table if exists x all
33

4-
# statement ok
5-
# drop table if exists x
4+
statement ok
5+
create table x (x int)
66

7-
# statement ok
8-
# create table x (x int)
7+
statement ok
8+
with y(y) as (select 1) insert into x (select y from y)
99

10-
# statement error 1005
11-
# with y(y) as (select 1) insert into x (select y from y)
12-
13-
# statement ok
14-
# select x from x
10+
query I
11+
select x from x
12+
----
13+
1
1514

16-
# statement error 1005
17-
# with y(y) as (select 1) update x set x = 2 from y where x = y
15+
statement ok
16+
with y(y) as (select 1) update x set x = 2 from y where x = y
1817

19-
# statement ok
20-
# select x from x
18+
query I
19+
select x from x
20+
----
21+
2
2122

22-
# statement error 1005
23-
# with y(y) as (select 2) delete from x using y where x = y
23+
statement ok
24+
with y(y) as (select 2) delete from x where x in (select y from y)
2425

25-
# statement ok
26-
# select x from x
26+
query I
27+
select x from x
28+
----
2729

28-
# statement error 1005
29-
# with y(y) as (select 1), z(z) as (select 2) insert into x (select (select y + z + 7) from y, z)
30+
statement ok
31+
with y(y) as (select 1), z(z) as (select 2) insert into x (select (select y + z + 7) from y, z)
3032

31-
# statement error 1005
32-
# with recursive t as (select 1 as x union all select x+1 from t where x < 3) insert into x (select * from t)
33+
statement ok
34+
with recursive t as (select 1 as x union all select x+1 from t where x < 3) insert into x (select * from t)
3335

34-
# statement ok
35-
# select x from x
36+
query I
37+
select x from x order by x
38+
----
39+
1
40+
2
41+
3
42+
10
3643

37-
# statement error 1005
38-
# with y(y) as (with z(z) as (select 20) select * from z) delete from x using y where x < y
44+
statement ok
45+
with y(y) as (with z(z) as (select 20) select * from z) delete from x where x < (select y from y)
3946

40-
# statement ok
41-
# select x from x
47+
query I
48+
select x from x
49+
----
4250

43-
# statement error 1005
44-
# with y(y) as (select 2) delete from x using (select y) z(z) where x = z
51+
statement ok
52+
with y(y) as (select 2) delete from x where x in (select y from y)
4553

54+
# Databend does not support DuckDB's `INSERT INTO x DEFAULT VALUES` syntax yet.
4655
# statement error 1005
4756
# insert into x default values
4857

58+
statement ok
59+
drop table x all

0 commit comments

Comments
 (0)