Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion datafusion/functions/src/unicode/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ where
// Build from_map using reusable buffer
from_graphemes.extend(from.graphemes(true));
for (index, c) in from_graphemes.iter().enumerate() {
from_map.insert(*c, index);
// Ignore characters that already exist in from_map, else insert
from_map.entry(*c).or_insert(index);
}

// Build to_graphemes
Expand Down Expand Up @@ -259,6 +260,18 @@ mod tests {
Utf8,
StringArray
);
test_function!(
TranslateFunc::new(),
vec![
ColumnarValue::Scalar(ScalarValue::from("abcabc")),
ColumnarValue::Scalar(ScalarValue::from("aa")),
ColumnarValue::Scalar(ScalarValue::from("de"))
],
Ok(Some("dbcdbc")),
&str,
Utf8,
StringArray
);
test_function!(
TranslateFunc::new(),
vec![
Expand Down
10 changes: 5 additions & 5 deletions datafusion/sqllogictest/test_files/string/string_query.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ FROM test_basic_operator;
Andrew
Xiangpeng
Raphael
under_scrre
under_scare
percent
(empty)
(empty)
Expand All @@ -542,10 +542,10 @@ SELECT
TRANSLATE(unicode_1, 'foo', 'bar') as c
FROM test_basic_operator;
----
databusirn📊🔥
databusirn数据融合
databusirnДатаФусион
un iść crre
databusian📊🔥
databusian数据融合
databusianДатаФусион
un iść care
pan Tadeusz ma iść w kąt
(empty)
(empty)
Expand Down