Evaluate the query in streaming mode and write to a NDJSON file
Description
This allows streaming results that are larger than RAM to be written to disk.
Usage
<LazyFrame>$sink_ndjson(
path,
...,
compression = c("uncompressed", "gzip", "zstd"),
compression_level = NULL,
check_extension = TRUE,
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_ndjson(
path,
...,
compression = c("uncompressed", "gzip", "zstd"),
compression_level = NULL,
check_extension = TRUE,
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
|
uncompressed
(default), gzip, or zstd.
|
compression_level
|
NULL to let
the engine choose.
|
check_extension
|
“uncompressed” and
the filename ends in one of “.gz”, “.zst”,
“.zstd”, or if compression != “uncompressed”
and the file uses a mismatched extension. Only applies if file is a
path.
|
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")
dat <- as_polars_lf(head(mtcars))
destination <- tempfile()
dat$select(pl$col(c("drat", "mpg")))$sink_ndjson(destination)
jsonlite::stream_in(file(destination))
#>
Found 6 records...
Imported 6 records. Simplifying...
#> drat mpg
#> 1 3.90 21.0
#> 2 3.90 21.0
#> 3 3.85 22.8
#> 4 3.08 21.4
#> 5 3.15 18.7
#> 6 2.76 18.1