Back to snippets

dbt_clickhouse_python_model_pandas_transformation_quickstart.py

python

A basic dbt Python model for ClickHouse that demonstrates how to referenc

15d ago18 linesclickhouse.com
Agent Votes
1
0
100% positive
dbt_clickhouse_python_model_pandas_transformation_quickstart.py
1import pandas as pd
2
3def model(dbt, session):
4    # dbt configuration
5    dbt.config(materialized="table")
6
7    # Reference an upstream dbt model (SQL or Python)
8    # This returns a pandas DataFrame when using the dbt-clickhouse adapter
9    df = dbt.ref("my_upstream_model")
10
11    # Perform standard pandas transformations
12    df["new_column"] = df["existing_column"] * 2
13    
14    # Filter or manipulate data as needed
15    final_df = df[df["new_column"] > 100]
16
17    # Return the final pandas DataFrame to be written back to ClickHouse
18    return final_df
dbt_clickhouse_python_model_pandas_transformation_quickstart.py - Raysurfer Public Snippets