daft.Expression.encode

daft.Expression.encode#

Expression.encode(codec: Literal['deflate', 'gzip', 'gz', 'zlib']) Expression[source]#

Encodes the expression (binary strings) using the specified codec.

Example

>>> import daft
>>> from daft import col
>>> df = daft.from_pydict({"text": [b"hello, world!"]})  # binary
>>> df.select(col("text").encode("zlib")).show()
╭────────────────────────────────╮
│ text                           │
│ ---                            │
│ Binary                         │
╞════════════════════════════════╡
│ b"x\x9c\xcbH\xcd\xc9\xc9\xd7Q… │
╰────────────────────────────────╯

(Showing first 1 of 1 rows)

Example

>>> import daft
>>> from daft import col
>>> df = daft.from_pydict({"text": ["hello, world!"]})  # string
>>> df.select(col("text").encode("zlib")).show()
╭────────────────────────────────╮
│ text                           │
│ ---                            │
│ Binary                         │
╞════════════════════════════════╡
│ b"x\x9c\xcbH\xcd\xc9\xc9\xd7Q… │
╰────────────────────────────────╯

(Showing first 1 of 1 rows)
Parameters:

codec (str) – encoding codec (deflate, gzip, zlib)

Returns:

A new expression with the encoded values.

Return type:

Expression