8000 add Binary String Functions (#494) · Bernolt/arrow-datafusion-python@106786a · GitHub
[go: up one dir, main page]

Skip to content

Commit 106786a

Browse files
authored
add Binary String Functions (apache#494)
1 parent 41d65d1 commit 106786a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

datafusion/tests/test_functions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,17 @@ def test_case(df):
477477
assert result.column(0) == pa.array([10, 8, 8])
478478
assert result.column(1) == pa.array(["Hola", "Mundo", "!!"])
479479
assert result.column(2) == pa.array(["Hola", "Mundo", None])
480+
481+
482+
def test_binary_string_functions(df):
483+
df = df.select(
484+
f.encode(column("a"), literal("base64")),
485+
f.decode(f.encode(column("a"), literal("base64")), literal("base64")),
486+
)
487+
result = df.collect()
488+
assert len(result) == 1
489+
result = result[0]
490+
assert result.column(0) == pa.array(["SGVsbG8", "V29ybGQ", "IQ"])
491+
assert pa.array(result.column(1)).cast(pa.string()) == pa.array(
492+
["Hello", "World", "!"]
493+
)

src/functions.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ scalar_function!(r#struct, Struct); // Use raw identifier since struct is a keyw
332332
scalar_function!(from_unixtime, FromUnixtime);
333333
scalar_function!(arrow_typeof, ArrowTypeof);
334334
scalar_function!(random, Random);
335+
//Binary String Functions
336+
scalar_function!(encode, Encode);
337+
scalar_function!(decode, Decode);
335338

336339
aggregate_function!(approx_distinct, ApproxDistinct);
337340
aggregate_function!(approx_median, ApproxMedian);
@@ -486,5 +489,9 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
486489
m.add_wrapped(wrap_pyfunction!(var_pop))?;
487490
m.add_wrapped(wrap_pyfunction!(var_samp))?;
488491
m.add_wrapped(wrap_pyfunction!(window))?;
492+
493+
//Binary String Functions
494+
m.add_wrapped(wrap_pyfunction!(encode))?;
495+
m.add_wrapped(wrap_pyfunction!(decode))?;
489496
Ok(())
490497
}

0 commit comments

Comments
 (0)
0