Skip to content

Commit ce55f93

Browse files
committed
chore(query): make soundex a mod
1 parent 5c22f91 commit ce55f93

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

src/query/functions-v2/src/scalars/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod boolean;
2222
mod control;
2323
mod datetime;
2424
mod math;
25+
mod soundex;
2526
mod string;
2627
mod string_multi_args;
2728

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
pub(crate) struct Soundex;
16+
17+
impl Soundex {
18+
#[inline(always)]
19+
pub fn number_map(i: char) -> Option<u8> {
20+
match i.to_ascii_lowercase() {
21+
'b' | 'f' | 'p' | 'v' => Some(b'1'),
22+
'c' | 'g' | 'j' | 'k' | 'q' | 's' | 'x' | 'z' => Some(b'2'),
23+
'd' | 't' => Some(b'3'),
24+
'l' => Some(b'4'),
25+
'm' | 'n' => Some(b'5'),
26+
'r' => Some(b'6'),
27+
_ => Some(b'0'),
28+
}
29+
}
30+
31+
#[inline(always)]
32+
pub fn is_drop(c: char) -> bool {
33+
matches!(
34+
c.to_ascii_lowercase(),
35+
'a' | 'e' | 'i' | 'o' | 'u' | 'y' | 'h' | 'w'
36+
)
37+
}
38+
39+
// https://github.com/mysql/mysql-server/blob/3290a66c89eb1625a7058e0ef732432b6952b435/sql/item_strfunc.cc#L1919
40+
#[inline(always)]
41+
pub fn is_uni_alphabetic(c: char) -> bool {
42+
('a'..='z').contains(&c) || ('A'..='Z').contains(&c) || c as i32 >= 0xC0
43+
}
44+
}

src/query/functions-v2/src/scalars/string.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use common_expression::Value;
3030
use common_expression::ValueRef;
3131
use itertools::izip;
3232

33+
use super::soundex::Soundex;
34+
3335
pub fn register(registry: &mut FunctionRegistry) {
3436
registry.register_passthrough_nullable_1_arg::<StringType, StringType, _, _>(
3537
"upper",
@@ -673,34 +675,3 @@ fn vectorize_string_to_string_2_arg(
673675
}
674676
}
675677
}
676-
677-
struct Soundex;
678-
679-
impl Soundex {
680-
#[inline(always)]
681-
fn number_map(i: char) -> Option<u8> {
682-
match i.to_ascii_lowercase() {
683-
'b' | 'f' | 'p' | 'v' => Some(b'1'),
684-
'c' | 'g' | 'j' | 'k' | 'q' | 's' | 'x' | 'z' => Some(b'2'),
685-
'd' | 't' => Some(b'3'),
686-
'l' => Some(b'4'),
687-
'm' | 'n' => Some(b'5'),
688-
'r' => Some(b'6'),
689-
_ => Some(b'0'),
690-
}
691-
}
692-
693-
#[inline(always)]
694-
fn is_drop(c: char) -> bool {
695-
matches!(
696-
c.to_ascii_lowercase(),
697-
'a' | 'e' | 'i' | 'o' | 'u' | 'y' | 'h' | 'w'
698-
)
699-
}
700-
701-
// https://github.com/mysql/mysql-server/blob/3290a66c89eb1625a7058e0ef732432b6952b435/sql/item_strfunc.cc#L1919
702-
#[inline(always)]
703-
fn is_uni_alphabetic(c: char) -> bool {
704-
('a'..='z').contains(&c) || ('A'..='Z').contains(&c) || c as i32 >= 0xC0
705-
}
706-
}

0 commit comments

Comments
 (0)