Skip to content

daft.functions.like#

like #

like(expr: Expression, pattern: str | Expression) -> Expression

Checks whether each string matches the given SQL LIKE pattern, case sensitive.

Returns:

Name Type Description
Expression Expression

a Boolean expression indicating whether each value matches the provided pattern

Note

Use % as a multiple-character wildcard or _ as a single-character wildcard.

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import like
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(like(df["x"], "daf%"))
>>> df.show()
╭───────╮
│ x     │
│ ---   │
│ Bool  │
╞═══════╡
│ true  │
├╌╌╌╌╌╌╌┤
│ false │
├╌╌╌╌╌╌╌┤
│ false │
╰───────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
def like(expr: Expression, pattern: str | Expression) -> Expression:
    """Checks whether each string matches the given SQL LIKE pattern, case sensitive.

    Returns:
        Expression: a Boolean expression indicating whether each value matches the provided pattern

    Note:
        Use % as a multiple-character wildcard or _ as a single-character wildcard.

    Examples:
        >>> import daft
        >>> from daft.functions import like
        >>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
        >>> df = df.select(like(df["x"], "daf%"))
        >>> df.show()
        ╭───────╮
        │ x     │
        │ ---   │
        │ Bool  │
        ╞═══════╡
        │ true  │
        ├╌╌╌╌╌╌╌┤
        │ false │
        ├╌╌╌╌╌╌╌┤
        │ false │
        ╰───────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("like", expr, pattern)