8000 feat: add python bindings for ends_with function (#693) · datapythonista/datafusion-python@344ebad · GitHub
[go: up one dir, main page]

Skip to content

Commit 344ebad

Browse files
authored
feat: add python bindings for ends_with function (apache#693)
* fix: resolve merge conflicts * fix: wrap pyfunction * fix: alphabetical ordering of function * refactor: update arg names * fix: assert correct column number
1 parent 1da28b5 commit 344ebad

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

python/datafusion/tests/test_functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ def test_string_functions(df):
533533
f.translate(column("a"), literal("or"), literal("ld")),
534534
f.trim(column("c")),
535535
f.upper(column("c")),
536+
f.ends_with(column("a"), literal("llo")),
536537
)
537538
result = df.collect()
538539
assert len(result) == 1
@@ -573,6 +574,7 @@ def test_string_functions(df):
573574
assert result.column(25) == pa.array(["Helll", "Wldld", "!"])
574575
assert result.column(26) == pa.array(["hello", "world", "!"])
575576
assert result.column(27) == pa.array(["HELLO ", " WORLD ", " !"])
577+
assert result.column(28) == pa.array([True, False, False])
576578

577579

578580
def test_hash_functions(df):

src/functions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ expr_fn!(cosh, num);
407407
expr_fn!(degrees, num);
408408
expr_fn!(decode, input encoding);
409409
expr_fn!(encode, input encoding);
410+
expr_fn!(ends_with, string suffix, "Returns true if string ends with suffix.");
410411
expr_fn!(exp, num);
411412
expr_fn!(factorial, num);
412413
expr_fn!(floor, num);
@@ -473,7 +474,7 @@ expr_fn!(
473474
"Splits string at occurrences of delimiter and returns the n'th field (counting from one)."
474475
);
475476
expr_fn!(sqrt, num);
476-
expr_fn!(starts_with, arg1 arg2, "Returns true if string starts with prefix.");
477+
expr_fn!(starts_with, string prefix, "Returns true if string starts with prefix.");
477478
expr_fn!(strpos, string substring, "Returns starting index of specified substring within string, or zero if it's not present. (Same as position(substring in string), but note the reversed argument order.)");
478479
expr_fn!(substr, string position);
479480
expr_fn!(tan, num);
@@ -652,6 +653,7 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
652653
m.add_wrapped(wrap_pyfunction!(datetrunc))?;
653654
m.add_wrapped(wrap_pyfunction!(date_trunc))?;
654655
m.add_wrapped(wrap_pyfunction!(digest))?;
656+
m.add_wrapped(wrap_pyfunction!(ends_with))?;
655657
m.add_wrapped(wrap_pyfunction!(exp))?;
656658
m.add_wrapped(wrap_pyfunction!(factorial))?;
657659
m.add_wrapped(wrap_pyfunction!(floor))?;

0 commit comments

Comments
 (0)
0