Skip to content

Commit

Permalink
fix: like panic due to Chinese (#12155)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudong963 authored Jul 20, 2023
1 parent 88c1c82 commit 9294a08
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/query/sql/src/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3214,16 +3214,24 @@ fn check_prefix(like_str: &str) -> bool {

let mut i: usize = like_str.len();
while i > 0 {
if like_str.chars().nth(i - 1).unwrap() != '%' {
break;
if let Some(c) = like_str.chars().nth(i - 1) {
if c != '%' {
break;
}
} else {
return false;
}
i -= 1;
}
if i == like_str.len() {
return false;
}
for j in (0..i).rev() {
if like_str.chars().nth(j).unwrap() == '_' {
if let Some(c) = like_str.chars().nth(j) {
if c == '_' {
return false;
}
} else {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,18 @@ query B
select count(*)=5 from t_string_like where URL like '%%'
----
1

# issue https://github.com/datafuselabs/databend/issues/12154
statement ok
create table b01(card_no int, deal_type varchar);

statement ok
insert into b01 values(1000,'地铁入站');

query IT
select * from b01 where deal_type like '地铁%';
----
1000 地铁入站

statement ok
drop table b01;

1 comment on commit 9294a08

@vercel
Copy link

@vercel vercel bot commented on 9294a08 Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend.vercel.app
databend-databend.vercel.app
databend.rs
databend-git-main-databend.vercel.app

Please sign in to comment.