Evaluate the query in streaming mode and write to Arrow IPC File Format
Description
This allows streaming results that are larger than RAM to be written to disk.
-
\don’t write directly to the output file(s) until$lazy_sink\_\*() $collect()is called. This is useful if you want to save a query to review or run later. -
\write directly to the output file(s) (they are shortcuts for$sink\_*() \).$lazy_sink\_*()$collect()
Usage
<LazyFrame>$sink_ipc(
path,
...,
compression = c("uncompressed", "lz4", "zstd"),
compat_level = c("newest", "oldest"),
maintain_order = TRUE,
storage_options = NULL,
sync_on_close = c("none", "data", "all"),
mkdir = FALSE,
engine = c("auto", "in-memory", "streaming"),
optimizations = pl\$QueryOptFlags()
)
lazyframe__lazy_sink_ipc(
path,
...,
compression = c("uncompressed", "lz4", "zstd"),
compat_level = c("newest", "oldest"),
maintain_order = TRUE,
storage_options = NULL,
sync_on_close = c("none", "data", "all"),
mkdir = FALSE
)
Arguments
path
|
A character. File path to which the file should be written. |
…
|
These dots are for future extensions and must be empty. |
compression
|
Determines the compression algorithm. Must be one of:
|
compat_level
|
Determines the compatibility level when exporting Polars’ internal data
structures. When specifying a new compatibility level, Polars exports
its internal data structures that might not be interpretable by other
Arrow implementations. The level can be specified as the name (e.g.,
“newest”) or as a scalar integer (Currently, 0
and 1 are supported).
|
maintain_order
|
Maintain the order in which data is processed. Setting this to
FALSE will be slightly faster.
|
storage_options
|
Named vector containing options that indicate how to connect to a cloud
provider. The cloud providers currently supported are AWS, GCP, and
Azure. See supported keys here:
storage_options is not provided, Polars will try to
infer the information from environment variables.
|
sync_on_close
|
Sync to disk when before closing a file. Must be one of:
|
mkdir
|
Recursively create all the directories in the path. |
engine
|
The engine name to use for processing the query. One of the followings:
|
optimizations
|
|
Value
-
\returns$sink\_\*() NULLinvisibly. -
\returns a new LazyFrame.$lazy_sink\_\*()
Examples
library("polars")
tmpf <- tempfile(fileext = ".arrow")
as_polars_lf(mtcars)$sink_ipc(tmpf, compression = "zstd")
pl$read_ipc(tmpf)
#> shape: (32, 11)
#> ┌──────┬─────┬───────┬───────┬───┬─────┬─────┬──────┬──────┐
#> │ mpg ┆ cyl ┆ disp ┆ hp ┆ … ┆ vs ┆ am ┆ gear ┆ carb │
#> │ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ f64 ┆ f64 ┆ ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
#> ╞══════╪═════╪═══════╪═══════╪═══╪═════╪═════╪══════╪══════╡
#> │ 21.0 ┆ 6.0 ┆ 160.0 ┆ 110.0 ┆ … ┆ 0.0 ┆ 1.0 ┆ 4.0 ┆ 4.0 │
#> │ 21.0 ┆ 6.0 ┆ 160.0 ┆ 110.0 ┆ … ┆ 0.0 ┆ 1.0 ┆ 4.0 ┆ 4.0 │
#> │ 22.8 ┆ 4.0 ┆ 108.0 ┆ 93.0 ┆ … ┆ 1.0 ┆ 1.0 ┆ 4.0 ┆ 1.0 │
#> │ 21.4 ┆ 6.0 ┆ 258.0 ┆ 110.0 ┆ … ┆ 1.0 ┆ 0.0 ┆ 3.0 ┆ 1.0 │
#> │ 18.7 ┆ 8.0 ┆ 360.0 ┆ 175.0 ┆ … ┆ 0.0 ┆ 0.0 ┆ 3.0 ┆ 2.0 │
#> │ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
#> │ 30.4 ┆ 4.0 ┆ 95.1 ┆ 113.0 ┆ … ┆ 1.0 ┆ 1.0 ┆ 5.0 ┆ 2.0 │
#> │ 15.8 ┆ 8.0 ┆ 351.0 ┆ 264.0 ┆ … ┆ 0.0 ┆ 1.0 ┆ 5.0 ┆ 4.0 │
#> │ 19.7 ┆ 6.0 ┆ 145.0 ┆ 175.0 ┆ … ┆ 0.0 ┆ 1.0 ┆ 5.0 ┆ 6.0 │
#> │ 15.0 ┆ 8.0 ┆ 301.0 ┆ 335.0 ┆ … ┆ 0.0 ┆ 1.0 ┆ 5.0 ┆ 8.0 │
#> │ 21.4 ┆ 4.0 ┆ 121.0 ┆ 109.0 ┆ … ┆ 1.0 ┆ 1.0 ┆ 4.0 ┆ 2.0 │
#> └──────┴─────┴───────┴───────┴───┴─────┴─────┴──────┴──────┘