Skip to content

Commit 1b67927

Browse files
authored
Merge branch 'main' into add-missing-conditional-functions
2 parents 835f91f + 645d261 commit 1b67927

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

crates/core/src/functions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ expr_fn!(chr, arg, "Returns the character with the given code.");
496496
expr_fn_vec!(coalesce);
497497
expr_fn_vec!(greatest);
498498
expr_fn_vec!(least);
499+
expr_fn!(
500+
contains,
501+
string search_str,
502+
"Return true if search_str is found within string (case-sensitive)."
503+
);
499504
expr_fn!(cos, num);
500505
expr_fn!(cosh, num);
501506
expr_fn!(cot, num);
@@ -968,6 +973,7 @@ pub(crate) fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
968973
m.add_wrapped(wrap_pyfunction!(col))?;
969974
m.add_wrapped(wrap_pyfunction!(concat_ws))?;
970975
m.add_wrapped(wrap_pyfunction!(concat))?;
976+
m.add_wrapped(wrap_pyfunction!(contains))?;
971977
m.add_wrapped(wrap_pyfunction!(corr))?;
972978
m.add_wrapped(wrap_pyfunction!(cos))?;
973979
m.add_wrapped(wrap_pyfunction!(cosh))?;

python/datafusion/functions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
"col",
117117
"concat",
118118
"concat_ws",
119+
"contains",
119120
"corr",
120121
"cos",
121122
"cosh",
@@ -443,6 +444,20 @@ def digest(value: Expr, method: Expr) -> Expr:
443444
return Expr(f.digest(value.expr, method.expr))
444445

445446

447+
def contains(string: Expr, search_str: Expr) -> Expr:
448+
"""Returns true if ``search_str`` is found within ``string`` (case-sensitive).
449+
450+
Examples:
451+
>>> ctx = dfn.SessionContext()
452+
>>> df = ctx.from_pydict({"a": ["the quick brown fox"]})
453+
>>> result = df.select(
454+
... dfn.functions.contains(dfn.col("a"), dfn.lit("brown")).alias("c"))
455+
>>> result.collect_column("c")[0].as_py()
456+
True
457+
"""
458+
return Expr(f.contains(string.expr, search_str.expr))
459+
460+
446461
def concat(*args: Expr) -> Expr:
447462
"""Concatenates the text representations of all the arguments.
448463

python/tests/test_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ def test_array_function_obj_tests(stmt, py_expr):
745745
f.split_part(column("a"), literal("l"), literal(1)),
746746
pa.array(["He", "Wor", "!"]),
747747
),
748+
(f.contains(column("a"), literal("ell")), pa.array([True, False, False])),
748749
(f.starts_with(column("a"), literal("Wor")), pa.array([False, True, False])),
749750
(f.strpos(column("a"), literal("o")), pa.array([5, 2, 0], type=pa.int32())),
750751
(

0 commit comments

Comments
 (0)