PipelineNode
laktory.models.pipeline.PipelineNode
¤
Bases: BaseModel, PipelineChild
Pipeline base component generating a DataFrame by reading a data source and applying a transformer (chain of dataframe transformations). Optional output to a data sink.
Examples:
A node reading stock prices data from a CSV file and writing a DataFrame as a parquet file.
import io
import laktory as lk
node_yaml = '''
name: brz_stock_prices
source:
path: "./events/stock_prices/"
format: JSON
sinks:
- path: ./tables/brz_stock_prices/
format: PARQUET
'''
node = lk.models.PipelineNode.model_validate_yaml(io.StringIO(node_yaml))
# node.execute()
A node reading stock prices from an upstream node and writing a DataFrame to a data table.
import io
import laktory as lk
node_yaml = '''
name: slv_stock_prices
source:
node_name: brz_stock_prices
sinks:
- schema_name: finance
table_name: slv_stock_prices
transformer:
nodes:
- expr: |
SELECT
data.created_at AS created_at,
data.symbol AS symbol,
data.open AS open,
data.close AS close,
data.high AS high,
data.low AS low,
data.volume AS volume
FROM
{df}
- func_name: drop_duplicates
func_kwargs:
subset:
- symbol
- timestamp
'''
node = lk.models.PipelineNode.model_validate_yaml(io.StringIO(node_yaml))
# node.execute()
| PARAMETER | DESCRIPTION |
|---|---|
comment
|
Comment for the associated table or view
TYPE:
|
dlt_template
|
Specify which template (notebook) to use when Databricks pipeline is selected as the orchestrator.
TYPE:
|
execution_task_name_
|
Execution task name when orchestrator (such as Databricks Jobs and Airflow) supports multi-tasks execution.
Nodes with the same task name will be executed together in a single task. If
TYPE:
|
expectations
|
List of data expectations. Can trigger warnings, drop invalid records or fail a pipeline.
TYPE:
|
expectations_checkpoint_path_
|
Path to which the checkpoint file for which expectations on a streaming dataframe should be written.
TYPE:
|
name
|
Name given to the node.
TYPE:
|
primary_keys
|
A list of column names that uniquely identify each row in the
DataFrame. These columns are used to:
- Document the uniqueness constraints of the node's output data.
- Define the default primary keys for sinks CDC merge operations
- Referenced in expectations and unit tests.
While optional, specifying
TYPE:
|
root_path_
|
Location of the pipeline node root used to store logs, metrics and checkpoints.
TYPE:
|
sinks
|
Definition of the data sink(s). Set
TYPE:
|
source
|
Definition of the data source(s)
TYPE:
|
tags
|
Node tags for selective execution.
TYPE:
|
time_column
|
The name of the column that represents the timestamp or temporal dimension in the DataFrame. This column is used to: - Document the time-based ordering and filtering semantics of the node’s output data. - Enable time-aware operations such as point-in-time joins, incremental processing, and time-series analysis. - Serve as a reference in expectations, unit tests, and feature engineering workflows. While optional, specifying time_column helps ensure consistency in time-based logic and improves the reliability of downstream operations that depend on temporal alignment.
TYPE:
|
transformer
|
Data transformations applied between the source and the sink(s).
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
check_expectations |
Check expectations, raise errors, warnings where required and build |
execute |
Execute pipeline node by: |
| ATTRIBUTE | DESCRIPTION |
|---|---|
all_sinks |
List of all sinks (output and quarantine).
|
data_sources |
Get all sources feeding the pipeline node
TYPE:
|
has_output_sinks |
TYPE:
|
has_sinks |
TYPE:
|
is_orchestrator_dlt |
If
TYPE:
|
is_sql_expressible |
TYPE:
|
output_df |
Dataframe resulting from reading source, applying transformer and dropping rows not meeting data quality
TYPE:
|
output_sinks |
List of sinks writing the output DataFrame
TYPE:
|
primary_sink |
Primary output sink used as a source for downstream nodes.
TYPE:
|
quarantine_df |
DataFrame storing
TYPE:
|
quarantine_sinks |
List of sinks writing the quarantine DataFrame
TYPE:
|
sinks_count |
Total number of sinks.
TYPE:
|
sql_statements |
Generate one SQL statement per sink, suitable for execution on a SQL warehouse.
TYPE:
|
stage_df |
Dataframe resulting from reading source and applying transformer, before data quality checks are applied.
TYPE:
|
upstream_node_names |
Pipeline node names required to execute current node.
TYPE:
|
view_definition |
Transformer View Definition (when applicable)
|
all_sinks
property
¤
List of all sinks (output and quarantine).
data_sources
property
¤
Get all sources feeding the pipeline node
has_output_sinks
property
¤
True if node has at least one output sink.
has_sinks
property
¤
True if node has at least one sink.
is_orchestrator_dlt
property
¤
If True, pipeline node is used in the context of a DLT pipeline
is_sql_expressible
property
¤
True if the node can be executed on a SQL warehouse.
output_df
property
¤
Dataframe resulting from reading source, applying transformer and dropping rows not meeting data quality expectations.
output_sinks
property
¤
List of sinks writing the output DataFrame
primary_sink
property
¤
Primary output sink used as a source for downstream nodes.
quarantine_df
property
¤
DataFrame storing stage_df rows not meeting data quality expectations.
quarantine_sinks
property
¤
List of sinks writing the quarantine DataFrame
sinks_count
property
¤
Total number of sinks.
sql_statements
property
¤
Generate one SQL statement per sink, suitable for execution on a SQL warehouse.
Raises ValueError if the node is not SQL-expressible.
stage_df
property
¤
Dataframe resulting from reading source and applying transformer, before data quality checks are applied.
upstream_node_names
property
¤
Pipeline node names required to execute current node.
view_definition
property
¤
Transformer View Definition (when applicable)
check_expectations()
¤
Check expectations, raise errors, warnings where required and build filtered and quarantine DataFrames.
Some actions have to be disabled when selected orchestrator is Databricks DLT:
- Raising error on Failure when expectation is supported by DLT
- Dropping rows when expectation is supported by DLT
Source code in laktory/models/pipeline/pipelinenode.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
execute(apply_transformer=True, write_sinks=True, full_refresh=False, named_dfs=None, update_tables_metadata=True)
¤
Execute pipeline node by:
- Reading the source
- Applying the user defined (and layer-specific if applicable) transformations
- Checking expectations
- Writing the sinks
| PARAMETER | DESCRIPTION |
|---|---|
apply_transformer
|
Flag to apply transformer in the execution
TYPE:
|
write_sinks
|
Flag to include writing sink in the execution
TYPE:
|
full_refresh
|
If
TYPE:
|
named_dfs
|
Named DataFrame passed to transformer nodes
TYPE:
|
update_tables_metadata
|
Update tables metadata
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnyFrame
|
output Spark DataFrame |
Source code in laktory/models/pipeline/pipelinenode.py
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 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |