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 |
|---|---|
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_quality_monitor
|
Databricks Quality Monitor
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:
|
schema_definition
|
Explicit table schema used when creating the table. If not set, schema is inferred from the transformer output DataFrame.
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 |
purge |
Delete sink data and checkpoints |
read |
Read dataframe from sink. |
write |
Write dataframe into sink. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
dlt_apply_changes_kwargs |
Keyword arguments for dlt.apply_changes function
TYPE:
|
dlt_pre_merge_view_name |
DLT view applying node transformer prior to applying CDC changes.
|
dlt_apply_changes_kwargs
property
¤
Keyword arguments for dlt.apply_changes function
dlt_pre_merge_view_name
property
¤
DLT 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
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
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
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 | |
purge()
¤
Delete sink data and checkpoints
Source code in laktory/models/datasinks/filedatasink.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
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
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
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
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 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 408 409 410 411 412 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 | |