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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
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)