@@ -11,7 +11,7 @@ import {
11
11
} from "../utils" ;
12
12
import { _LazyGroupBy , LazyGroupBy } from "./groupby" ;
13
13
import { Deserialize , GroupByOps , Serialize } from "../shared_traits" ;
14
- import { LazyOptions , LazyJoinOptions } from "../types" ;
14
+ import { LazyOptions , LazyJoinOptions , SinkCsvOptions } from "../types" ;
15
15
import { Series } from "../series" ;
16
16
17
17
const inspect = Symbol . for ( "nodejs.util.inspect.custom" ) ;
@@ -457,6 +457,63 @@ export interface LazyDataFrame extends Serialize, GroupByOps<LazyGroupBy> {
457
457
* @see {@link DataFrame.withRowCount }
458
458
*/
459
459
withRowCount ( ) ;
460
+ /***
461
+ *
462
+ * Evaluate the query in streaming mode and write to a CSV file.
463
+
464
+ .. warning::
465
+ Streaming mode is considered **unstable**. It may be changed
466
+ at any point without it being considered a breaking change.
467
+
468
+ This allows streaming results that are larger than RAM to be written to disk.
469
+
470
+ Parameters
471
+ ----------
472
+ @param path - File path to which the file should be written.
473
+ @param includeBom - Whether to include UTF-8 BOM in the CSV output.
474
+ @param includeHeader - Whether to include header in the CSV output.
475
+ @param separator - Separate CSV fields with this symbol.
476
+ @param lineTerminator - String used to end each row.
477
+ @param quoteChar - Byte to use as quoting character.
478
+ @param batchSize - Number of rows that will be processed per thread. Default - 1024
479
+ @param datetimeFormat - A format string, with the specifiers defined by the
480
+ `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
481
+ Rust crate. If no format specified, the default fractional-second
482
+ precision is inferred from the maximum timeunit found in the frame's
483
+ Datetime cols (if any).
484
+ @param dateFormat - A format string, with the specifiers defined by the
485
+ `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
486
+ Rust crate.
487
+ @param timeFormat A format string, with the specifiers defined by the
488
+ `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
489
+ Rust crate.
490
+ @param floatPrecision - Number of decimal places to write, applied to both `Float32` and `Float64` datatypes.
491
+ @param nullValue - A string representing null values (defaulting to the empty string).
492
+ @param quoteStyle - Determines the quoting strategy used. : {'necessary', 'always', 'non_numeric', 'never'}
493
+ - necessary (default): This puts quotes around fields only when necessary.
494
+ They are necessary when fields contain a quote,
495
+ delimiter or record terminator.
496
+ Quotes are also necessary when writing an empty record
497
+ (which is indistinguishable from a record with one empty field).
498
+ This is the default.
499
+ - always: This puts quotes around every field. Always.
500
+ - never: This never puts quotes around fields, even if that results in
501
+ invalid CSV data (e.g.: by not quoting strings containing the
502
+ separator).
503
+ - non_numeric: This puts quotes around all fields that are non-numeric.
504
+ Namely, when writing a field that does not parse as a valid float
505
+ or integer, then quotes will be used even if they aren`t strictly
506
+ necessary.
507
+ @param maintainOrder - Maintain the order in which data is processed.
508
+ Setting this to `False` will be slightly faster.
509
+
510
+ Examples
511
+ --------
512
+ >>> const lf = pl.scanCsv("/path/to/my_larger_than_ram_file.csv")
513
+ >>> lf.sinkCsv("out.csv")
514
+ */
515
+
516
+ sinkCSV ( dest : string , options ?: SinkCsvOptions ) : void ;
460
517
}
461
518
462
519
const prepareGroupbyInputs = ( by ) => {
@@ -899,6 +956,14 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => {
899
956
withRowCount ( name = "row_nr" ) {
900
957
return _LazyDataFrame ( _ldf . withRowCount ( name ) ) ;
901
958
} ,
959
+ sinkCSV ( dest ?, options = { } ) {
960
+ options . maintainOrder = options . maintainOrder ?? false ;
961
+ if ( typeof dest === "string" ) {
962
+ _ldf . sinkCsv ( dest , options ) ;
963
+ } else {
964
+ throw new TypeError ( "Expected a string destination" ) ;
965
+ }
966
+ } ,
902
967
} ;
903
968
} ;
904
969
0 commit comments