This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion-python.git
The following commit(s) were added to refs/heads/main by this push:
new 106786a add Binary String Functions (#494)
106786a is described below
commit 106786ab57cfe9b16f2b867fe6d53170bd14c841
Author: zhenxing jiang <[email protected]>
AuthorDate: Wed Sep 20 19:15:45 2023 +0800
add Binary String Functions (#494)
---
datafusion/tests/test_functions.py | 14 ++++++++++++++
src/functions.rs | 7 +++++++
2 files changed, 21 insertions(+)
diff --git a/datafusion/tests/test_functions.py
b/datafusion/tests/test_functions.py
index 80795bf..f1f64c3 100644
--- a/datafusion/tests/test_functions.py
+++ b/datafusion/tests/test_functions.py
@@ -477,3 +477,17 @@ def test_case(df):
assert result.column(0) == pa.array([10, 8, 8])
assert result.column(1) == pa.array(["Hola", "Mundo", "!!"])
assert result.column(2) == pa.array(["Hola", "Mundo", None])
+
+
+def test_binary_string_functions(df):
+ df = df.select(
+ f.encode(column("a"), literal("base64")),
+ f.decode(f.encode(column("a"), literal("base64")), literal("base64")),
+ )
+ result = df.collect()
+ assert len(result) == 1
+ result = result[0]
+ assert result.column(0) == pa.array(["SGVsbG8", "V29ybGQ", "IQ"])
+ assert pa.array(result.column(1)).cast(pa.string()) == pa.array(
+ ["Hello", "World", "!"]
+ )
diff --git a/src/functions.rs b/src/functions.rs
index 79cc19b..ef26240 100644
--- a/src/functions.rs
+++ b/src/functions.rs
@@ -332,6 +332,9 @@ scalar_function!(r#struct, Struct); // Use raw identifier
since struct is a keyw
scalar_function!(from_unixtime, FromUnixtime);
scalar_function!(arrow_typeof, ArrowTypeof);
scalar_function!(random, Random);
+//Binary String Functions
+scalar_function!(encode, Encode);
+scalar_function!(decode, Decode);
aggregate_function!(approx_distinct, ApproxDistinct);
aggregate_function!(approx_median, ApproxMedian);
@@ -486,5 +489,9 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(var_pop))?;
m.add_wrapped(wrap_pyfunction!(var_samp))?;
m.add_wrapped(wrap_pyfunction!(window))?;
+
+ //Binary String Functions
+ m.add_wrapped(wrap_pyfunction!(encode))?;
+ m.add_wrapped(wrap_pyfunction!(decode))?;
Ok(())
}