Skip to content

Commit 87194d8

Browse files
Devanshudevanshu0987
authored andcommitted
Make translate function postgres compatible
1 parent 7fde30a commit 87194d8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

datafusion/functions/src/unicode/translate.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ where
170170
// Build from_map using reusable buffer
171171
from_graphemes.extend(from.graphemes(true));
172172
for (index, c) in from_graphemes.iter().enumerate() {
173-
from_map.insert(*c, index);
173+
// Ignore characters that already exist in from_map, else insert
174+
from_map.entry(*c).or_insert(index);
174175
}
175176

176177
// Build to_graphemes
@@ -259,6 +260,18 @@ mod tests {
259260
Utf8,
260261
StringArray
261262
);
263+
test_function!(
264+
TranslateFunc::new(),
265+
vec![
266+
ColumnarValue::Scalar(ScalarValue::from("abcabc")),
267+
ColumnarValue::Scalar(ScalarValue::from("aa")),
268+
ColumnarValue::Scalar(ScalarValue::from("de"))
269+
],
270+
Ok(Some("dbcdbc")),
271+
&str,
272+
Utf8,
273+
StringArray
274+
);
262275
test_function!(
263276
TranslateFunc::new(),
264277
vec![

0 commit comments

Comments
 (0)