Skip to content

Serialize this expression to a string in binary or JSON format

Description

Serialize this expression to a string in binary or JSON format

Usage

<Expr>$meta$serialize(..., format = c("binary", "json"))

Arguments

These dots are for future extensions and must be empty.
format The format in which to serialize. Must be one of:
  • “binary” (default): serialize to binary format (bytes).
  • “json”: serialize to JSON format (string).

Details

Serialization is not stable across Polars versions: a LazyFrame serialized in one Polars version may not be deserializable in another Polars version.

Value

A polars expression

Examples

library("polars")


# Serialize the expression into a binary representation.
expr <- pl$col("foo")$sum()$over("bar")
bytes <- expr$meta$serialize()
rawToChar(bytes)
#> [1] "\xa1fWindow\xa4hfunction\xa1cAgg\xa1cSum\xa1fColumncfoolpartition_by\x81\xa1fColumncbarhorder_by\xf6goptions\xa1dOverlGroupsToRows"
pl$deserialize_expr(bytes)
#> col("foo").sum().over([col("bar")])
# Serialize into json
expr$meta$serialize(format = "json") |>
  jsonlite::prettify()
#> {
#>     "Window": {
#>         "function": {
#>             "Agg": {
#>                 "Sum": {
#>                     "Column": "foo"
#>                 }
#>             }
#>         },
#>         "partition_by": [
#>             {
#>                 "Column": "bar"
#>             }
#>         ],
#>         "order_by": null,
#>         "options": {
#>             "Over": "GroupsToRows"
#>         }
#>     }
#> }
#>