Skip to content

Commit ad38a2c

Browse files
committed
test(expression): Add repeat function test
1 parent 1dcfc88 commit ad38a2c

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/array/ops.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,13 @@ impl ArrayImpl {
643643
num.type_string(),
644644
));
645645
};
646-
Ok(A::new_string(binary_op(
647-
a.as_ref(),
648-
b.as_ref(),
649-
|a, b| {
650-
if *b < 0 {
651-
return String::new();
652-
}
653-
a.repeat(*b as usize)
654-
},
655-
)))
646+
Ok(A::new_string(binary_op(a.as_ref(), b.as_ref(), |a, b| {
647+
let mut res = String::new();
648+
for _ in 0..(*b) {
649+
res += a;
650+
}
651+
res
652+
})))
656653
}
657654

658655
pub fn vector_l2_distance(&self, other: &ArrayImpl) -> Result {

tests/sql/repeat.slt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
query I
2+
select repeat('abc', 3);
3+
----
4+
abcabcabc
5+
6+
statement ok
7+
create table t(v varchar(20));
8+
9+
statement ok
10+
insert into t values ('test1'), ('test2'), ('test3'), ('test4'), ('test5'), ('test6'), ('test7'), ('test8');
11+
12+
query I
13+
select repeat(v, 2) from t;
14+
----
15+
test1test1
16+
test2test2
17+
test3test3
18+
test4test4
19+
test5test5
20+
test6test6
21+
test7test7
22+
test8test8
23+
24+
query I
25+
select repeat(v, -1) from t;
26+
----
27+
(empty)
28+
(empty)
29+
(empty)
30+
(empty)
31+
(empty)
32+
(empty)
33+
(empty)
34+
(empty)

0 commit comments

Comments
 (0)