Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/core/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ expr_fn!(length, string);
expr_fn!(char_length, string);
expr_fn!(chr, arg, "Returns the character with the given code.");
expr_fn_vec!(coalesce);
expr_fn!(
contains,
string search_str,
"Return true if search_str is found within string (case-sensitive)."
);
expr_fn!(cos, num);
expr_fn!(cosh, num);
expr_fn!(cot, num);
Expand Down Expand Up @@ -960,6 +965,7 @@ pub(crate) fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(col))?;
m.add_wrapped(wrap_pyfunction!(concat_ws))?;
m.add_wrapped(wrap_pyfunction!(concat))?;
m.add_wrapped(wrap_pyfunction!(contains))?;
m.add_wrapped(wrap_pyfunction!(corr))?;
m.add_wrapped(wrap_pyfunction!(cos))?;
m.add_wrapped(wrap_pyfunction!(cosh))?;
Expand Down
15 changes: 15 additions & 0 deletions python/datafusion/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"col",
"concat",
"concat_ws",
"contains",
"corr",
"cos",
"cosh",
Expand Down Expand Up @@ -436,6 +437,20 @@ def digest(value: Expr, method: Expr) -> Expr:
return Expr(f.digest(value.expr, method.expr))


def contains(string: Expr, search_str: Expr) -> Expr:
"""Return true if ``search_str`` is found within ``string`` (case-sensitive).

Examples:
>>> ctx = dfn.SessionContext()
>>> df = ctx.from_pydict({"a": ["the quick brown fox"]})
>>> result = df.select(
... dfn.functions.contains(dfn.col("a"), dfn.lit("brown")).alias("c"))
>>> result.collect_column("c")[0].as_py()
True
"""
return Expr(f.contains(string.expr, search_str.expr))


def concat(*args: Expr) -> Expr:
"""Concatenates the text representations of all the arguments.

Expand Down
1 change: 1 addition & 0 deletions python/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ def test_array_function_obj_tests(stmt, py_expr):
f.split_part(column("a"), literal("l"), literal(1)),
pa.array(["He", "Wor", "!"]),
),
(f.contains(column("a"), literal("ell")), pa.array([True, False, False])),
(f.starts_with(column("a"), literal("Wor")), pa.array([False, True, False])),
(f.strpos(column("a"), literal("o")), pa.array([5, 2, 0], type=pa.int32())),
(
Expand Down
Loading