FileDataSink
laktory.models.datasinks.FileDataSink
¤
Bases: BaseDataSink
Data sink writing to disk file(s) as csv, parquet or Delta Table.
Examples:
Write polars DataFrame as CSV
import polars as pl
import laktory as lk
df = pl.DataFrame({"x": [0, 1]})
sink = lk.models.FileDataSink(
path="./dataframe.csv", format="CSV", writer_kwargs={"separator": ";"}
)
sink.write(df)
Write Spark Streaming DataFrame as Delta ```python tag:skip-run from laktory import models
df = spark.readStream(...) # skip
sink = models.FileDataSink( path="./delta_table/", format="DELTA", mode="APPEND", checkpoint_path="./delta_table/checkpoint/", ) sink.write(df) ``` References
| PARAMETER | DESCRIPTION |
|---|---|
as_stream
|
If
TYPE:
|
checkpoint_path_
|
Path to which the checkpoint file for which a streaming dataframe should be written.
TYPE:
|
custom_writer
|
Custom writer that fully replaces Laktory's built-in write logic. Laktory manages the streaming query lifecycle (foreachBatch, trigger, checkpoint, start/await). Can be set as a plain string (func_name only) or a full CustomWriter object with func_name, func_args, and func_kwargs. Mutually exclusive with
TYPE:
|
databricks_data_profiling_config
|
Databricks Data Quality Monitor data profiling configuration
TYPE:
|
format
|
Format of the data files.
TYPE:
|
is_quarantine
|
Sink used to store quarantined results from a pipeline node expectations.
TYPE:
|
merge_cdc_options
|
Merge options to handle input DataFrames that are Change Data Capture (CDC). Only used when
TYPE:
|
metadata
|
Table and columns metadata.
TYPE:
|
mode
|
Write mode. Spark¤
Spark Streaming¤
Polars Delta¤
Laktory¤
TYPE:
|
path
|
File path on a local disk, remote storage or Databricks volume.
TYPE:
|
reset_mode
|
Strategy used to reset this sink's data on a full refresh or a reset run.
Ignored by shared sinks (
TYPE:
|
schema_definition
|
Explicit table schema used when creating the table. If not set, schema is inferred from the transformer output DataFrame.
TYPE:
|
shared
|
Options for a sink written by multiple writers: each writer owns its rows, identified
by a writer column or a SQL predicate, and a full refresh of a writer only deletes its
own rows. Required on every sink of a target written by several nodes or pipelines.
TYPE:
|
type
|
Source Type
TYPE:
|
writer_kwargs
|
Keyword arguments passed directly to dataframe backend writer. Passed to
TYPE:
|
writer_methods
|
DataFrame backend writer methods.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
as_source |
Generate a file data source with the same path as the sink. |
create |
Creates an empty Delta table at |
filter_writer_rows |
Keep the rows written by the writer of a shared sink - matching its writer |
is_streaming |
Return |
purge |
Delete sink data and checkpoints |
read |
Read dataframe from sink. |
with_writer_column |
Add the writer identifier column to a DataFrame written by a shared sink, as the |
write |
Write dataframe into sink. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
ldp_auto_cdc_flow_kwargs |
Keyword arguments for dp.create_auto_cdc_flow function
TYPE:
|
sdp_pre_merge_view_name |
SPD view applying node transformer prior to applying CDC changes.
|
ldp_auto_cdc_flow_kwargs
property
¤
Keyword arguments for dp.create_auto_cdc_flow function
sdp_pre_merge_view_name
property
¤
SPD view applying node transformer prior to applying CDC changes.
as_source(as_stream=None, reader_kwargs=None, reader_methods=None)
¤
Generate a file data source with the same path as the sink.
| PARAMETER | DESCRIPTION |
|---|---|
as_stream
|
If
TYPE:
|
reader_kwargs
|
Keyword arguments passed to the dataframe backend reader.
DEFAULT:
|
reader_methods
|
DataFrame backend reader methods.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
FileDataSource
|
File Data Source |
Source code in laktory/models/datasinks/filedatasink.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
create(df=None)
¤
Creates an empty Delta table at self.path if the path does not already exist.
Returns True if the table was created, False otherwise.
Schema is taken from schema_definition if set, otherwise inferred from df.
Source code in laktory/models/datasinks/filedatasink.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
filter_writer_rows(df)
¤
Keep the rows written by the writer of a shared sink - matching its writer
identifier or shared.where - without the writer column: the output of the writer
read back from the shared target. Returns the DataFrame unchanged if the sink is not
shared.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
DataFrame read from the sink
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnyFrame
|
DataFrame with the rows of the writer |
Source code in laktory/models/datasinks/basedatasink.py
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | |
is_streaming(df=None)
¤
Return True if the write should use Spark Structured Streaming.
Resolution order:
1. If a Narwhals-wrapped PySpark DataFrame is provided, read its native
isStreaming attribute.
2. Fall back to self.as_stream (explicit sink configuration).
3. Fall back to the parent node's source as_stream flag.
4. Default to False (static write).
If both the DataFrame state and the configuration are set and they
disagree, a TypeError is raised to surface the misconfiguration
early.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Optional Narwhals DataFrame or LazyFrame. Must be passed before
calling
DEFAULT:
|
Source code in laktory/models/datasinks/basedatasink.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
purge(mode=None)
¤
Delete sink data and checkpoints
| PARAMETER | DESCRIPTION |
|---|---|
mode
|
Optional override for
TYPE:
|
Source code in laktory/models/datasinks/filedatasink.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
read(as_stream=None, reader_kwargs=None, reader_methods=None)
¤
Read dataframe from sink.
| PARAMETER | DESCRIPTION |
|---|---|
as_stream
|
If
DEFAULT:
|
reader_kwargs
|
Keyword arguments passed to the dataframe backend reader.
DEFAULT:
|
reader_methods
|
DataFrame backend reader methods.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AnyFrame
|
DataFrame |
Source code in laktory/models/datasinks/basedatasink.py
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 | |
with_writer_column(df)
¤
Add the writer identifier column to a DataFrame written by a shared sink, as the
first column so that its statistics are collected. Returns the DataFrame unchanged
if the sink is not shared or identifies its rows with shared.where.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
DataFrame to be written
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnyFrame
|
DataFrame with writer identifier column |
Source code in laktory/models/datasinks/basedatasink.py
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | |
write(df=None, view_definition=None, mode=None)
¤
Write dataframe into sink.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Input dataframe.
TYPE:
|
mode
|
Write mode overwrite of the sink default mode.
TYPE:
|
view_definition
|
View definition for table data sinks of
TYPE:
|
Source code in laktory/models/datasinks/basedatasink.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |