Skip to content

daft.functions.length_bytes#

length_bytes #

length_bytes(expr: Expression) -> Expression

Retrieves the length for a UTF-8 string column in bytes.

Returns:

Name Type Description
Expression Expression

an UInt64 expression with the length of each string

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import length_bytes
>>> df = daft.from_pydict({"x": ["๐Ÿ˜‰test", "heyฬ†", "baz"]})
>>> df = df.select(length_bytes(df["x"]))
>>> df.show()
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ x      โ”‚
โ”‚ ---    โ”‚
โ”‚ UInt64 โ”‚
โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•ก
โ”‚ 8      โ”‚
โ”œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ”ค
โ”‚ 5      โ”‚
โ”œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ”ค
โ”‚ 3      โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
def length_bytes(expr: Expression) -> Expression:
    """Retrieves the length for a UTF-8 string column in bytes.

    Returns:
        Expression: an UInt64 expression with the length of each string

    Examples:
        >>> import daft
        >>> from daft.functions import length_bytes
        >>> df = daft.from_pydict({"x": ["๐Ÿ˜‰test", "heyฬ†", "baz"]})
        >>> df = df.select(length_bytes(df["x"]))
        >>> df.show()
        โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
        โ”‚ x      โ”‚
        โ”‚ ---    โ”‚
        โ”‚ UInt64 โ”‚
        โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•ก
        โ”‚ 8      โ”‚
        โ”œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ”ค
        โ”‚ 5      โ”‚
        โ”œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ”ค
        โ”‚ 3      โ”‚
        โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("length_bytes", expr)