dbt Adapter Reference for Confluent Cloud for Apache Flink

The dbt-confluent adapter runs dbt models as Flink SQL statements in Confluent Cloud for Apache Flink®. This page describes every profile setting, materialization, and model configuration that the adapter supports, how to manage user-defined functions with dbt, and how the adapter behaves when you re-run, change, or rebuild a model.

If you’re new to the adapter, start with the end-to-end tutorial, Build a Streaming Pipeline with dbt and Confluent Cloud for Apache Flink.

Version compatibility

Adapter version

dbt Core

Python

Notes

0.6.x

1.12.x

3.10 to 3.13

Adds the function materialization for user-defined functions (UDFs), name_prefix, and inferred organization and region settings. view models update in place with ALTER VIEW. Requires dbt Core 1.12. dbt Core 1.11 is no longer supported.

0.5.x

1.11.x

3.10 to 3.13

Adds OAuth sign-in and faster schema drift checks. A streaming_table model’s INSERT statement writes columns by name, and dbt’s contract check now runs before the adapter resubmits the statement. Before you upgrade, see Columns and the contract check.

0.4.x

1.11.x

3.10 to 3.13

Adds materialized_table, tableflow, statement_properties, and configuration validation.

0.3.2

1.11.x

3.10 to 3.13

Pins dbt Core to 1.11.x.

0.3.0, 0.3.1

1.11.x

3.10 to 3.13

These versions also allow dbt Core 1.12 to install, which isn’t compatible. Version 0.3.0 also allows Python 3.14, which isn’t supported. Pin dbt Core yourself with pip install "dbt-core~=1.11.0", or upgrade the adapter.

The adapter installs the dbt Core version it supports. Don’t install or upgrade dbt-core separately. To check your versions, run dbt --version.

How dbt concepts map to Flink

Confluent Cloud for Apache Flink uses different terms than the databases that dbt traditionally targets:

dbt concept

Flink SQL concept

Confluent Cloud entity

database

Catalog

Environment

schema

Database

Kafka cluster

Model

Table or view, plus the statements that maintain it

Kafka topic, except for views, ephemeral models, and faker tables

These mappings determine two required profile fields:

  • environment_id is the Confluent Cloud environment ID, in the form env-xxxxxx.

  • dbname is the name of the Kafka cluster, not the cluster ID (lkc-xxxxxx). A model-level schema configuration must also be a cluster name. The adapter uses a custom schema value as-is, instead of appending it to the target schema the way dbt does by default.

The adapter can’t create, rename, or drop Kafka clusters. Every cluster that a profile or model references must already exist.

Profile configuration

Define a connection profile in profiles.yml, which is by default at ~/.dbt/profiles.yml. dbt init creates one for you.

my_project:
  target: dev
  outputs:
    dev:
      type: confluent
      cloud_provider: aws
      cloud_region: us-east-2
      organization_id: <your-organization-id>
      environment_id: <your-environment-id>
      compute_pool_id: <your-compute-pool-id>
      dbname: <your-kafka-cluster-name>
      global_api_key: "{{ env_var('CONFLUENT_GLOBAL_API_KEY') }}"
      global_api_secret: "{{ env_var('CONFLUENT_GLOBAL_API_SECRET') }}"
      threads: 1

Setting

Description

type

Required. Always confluent.

organization_id

Your Confluent Cloud organization ID. Required with a Flink API key. With auth: oauth or a global API key, you can omit it. See Omit the organization, cloud provider, and region.

environment_id

Required. The environment ID, for example env-xxxxxx.

dbname

Required. The name of the Kafka cluster that models are created in.

database_kafka_cluster_id

Optional. The ID (lkc-xxxxxx) of the dbname cluster. Set it when more than one cluster in the environment has that name, or when you use a Tableflow API key.

cloud_provider, cloud_region

The cloud provider and region of your Flink endpoint, for example aws and us-east-2. With a Flink API key, required unless you set endpoint. With auth: oauth or a global API key, you can omit them. For more information, see Omit the organization, cloud provider, and region.

endpoint

A full Flink endpoint URL, for a private network or another non-standard endpoint, for example https://flink.us-east-2.aws.private.confluent.cloud. Requests go to this URL. If you also set cloud_provider and cloud_region, the adapter uses them only for function artifacts. Set them if you use functions with an endpoint that doesn’t have the form https://flink.<region>.<cloud>[.private].confluent.cloud. For more information, see Connection fails with endpoint and cloud region both set.

auth

Optional. How the adapter authenticates: api_key or oauth. Default: api_key. With oauth, you sign in to Confluent Cloud in your browser and don’t set any API keys. For setup details, see Sign in with OAuth.

global_api_key, global_api_secret

A global API key. Works for Flink and Tableflow.

flink_api_key, flink_api_secret

A Flink API key, which is scoped to one environment and region. With auth: api_key, supply one complete key pair, either global or Flink. If you supply both, the adapter uses the global key.

cloud_api_key, cloud_api_secret

A Cloud resource management API key. With a Flink API key, the function materialization needs it to use the artifact API. Create the key with confluent api-key create --resource cloud, and add it to the profile yourself, because dbt init doesn’t prompt for it. Not needed with auth: oauth or a global API key. For the key types, see Resource scopes.

tableflow_api_key, tableflow_api_secret

A Tableflow API key. With a Flink API key, the tableflow configuration needs it. Create the key with confluent api-key create --resource tableflow, and add it to the profile yourself, because dbt init doesn’t prompt for it. Also set database_kafka_cluster_id. Not needed with auth: oauth or a global API key.

compute_pool_id

Optional. The default compute pool for every model. If you omit it, Flink runs statements in the environment’s default compute pool for the region. Models can override it; see compute_pool_id.

execution_mode

Optional. The default execution mode for statements that don’t set their own. Default: streaming_query. Materializations set their own mode, so you rarely need to change this.

statement_name_prefix

Optional. The prefix for generated statement names. Default: dbt-. See Statement names.

name_prefix

Optional. A prefix that keeps your tables, functions, and statements apart from other users’ in a shared environment. Default: none. See Share an environment with name_prefix.

statement_label

Optional. A label applied to every statement that the adapter submits. Default: dbt-confluent.

threads

The number of models that dbt builds in parallel.

Store secrets in environment variables and read them with env_var(), as in the preceding example. To confirm that the profile works, run dbt debug, which also reports the configured compute pool.

Sign in with OAuth

Starting with adapter version 0.5.0, you can sign in to Confluent Cloud in your browser instead of using an API key. Set auth: oauth in the profile, and leave out global_api_key, global_api_secret, flink_api_key, and flink_api_secret:

my_project:
  target: dev
  outputs:
    dev:
      type: confluent
      auth: oauth
      cloud_provider: aws
      cloud_region: us-east-2
      organization_id: <your-organization-id>
      environment_id: <your-environment-id>
      compute_pool_id: <your-compute-pool-id>
      dbname: <your-kafka-cluster-name>
      threads: 1

When dbt init asks for credentials, choose Use OAuth (interactive Confluent Cloud sign-in, no API key) to create this profile.

When a dbt command first connects to Confluent Cloud, the adapter opens your browser so that you can sign in. The sign-in isn’t saved between commands, so each command that connects, such as dbt debug or dbt run, asks you to sign in again. Within one long-running command, the session can expire, as described in the following Session length item.

  • Permissions: dbt acts with your user account’s permissions, including for Tableflow, so you don’t need a global API key.

  • Callback port: While you sign in, the adapter listens on 127.0.0.1:26642 for the browser’s redirect. Sign in with a browser on the machine that runs dbt, because the browser redirects to 127.0.0.1. This matters if you run dbt over SSH or in a remote development container. You can’t change this port. If another process is using it, the sign-in fails with PORT_IN_USE. Because of the fixed port, only one sign-in can run on a machine at a time.

  • Timeout: If you don’t finish signing in within five minutes, the sign-in fails with TIMED_OUT.

  • Session length: A session lasts up to about eight hours, or less if the session is idle or revoked. When the session ends, the adapter opens your browser again and retries the request. Sign in as the same user. If you sign in as a different user, the sign-in fails with USER_MISMATCH.

Signing in requires someone at a browser, so use an API key for CI/CD pipelines and other unattended runs. For more information, see CI/CD.

Omit the organization, cloud provider, and region

Starting with adapter version 0.6.0, you can leave organization_id, cloud_provider, and cloud_region out of the profile when you use auth: oauth or a global API key:

my_project:
  target: dev
  outputs:
    dev:
      type: confluent
      auth: oauth
      environment_id: <your-environment-id>
      dbname: <your-kafka-cluster-name>
      threads: 1
  • organization_id: The adapter uses the organization that your credentials can reach. If they can reach more than one, the connection fails and lists the organizations. Set organization_id to one of them.

  • cloud_provider and cloud_region: The adapter reads them from the Kafka cluster named by dbname, or by database_kafka_cluster_id if you set it. If you set only one of them, the adapter fills in the other and checks the one you set. If you set both, the adapter uses them as given and doesn’t check them against the cluster. If more than one cluster in the environment has the dbname name, set database_kafka_cluster_id.

The adapter can’t infer an endpoint, so keep setting it for private networking. With a Flink API key, organization_id and either cloud_provider and cloud_region or endpoint are required, and every dbt command reports a missing setting when it loads the profile.

When dbt init asks for credentials, the global API key and OAuth options let you leave organization_id blank and infer the cloud provider and region.

Share an environment with name_prefix

Statement names are unique in an environment, and table names are unique in a Kafka cluster. When several people build the same project into one environment, their statements collide, and if they also share a cluster, they write to the same tables. To keep your resources apart, set name_prefix in your own profile:

my_project:
  target: dev
  outputs:
    dev:
      type: confluent
      # ...
      name_prefix: alice-

Resource

Without name_prefix

With name_prefix: alice-

Statement

dbt-my-project-orders-2bce76

alice-dbt-my-project-orders-f94953

Table or function

orders

alice_orders

In table and function names, hyphens in the prefix become underscores. The prefix also applies to alias and statement_name configurations. Sources aren’t prefixed. A prefix can contain only lowercase letters, digits, and hyphens, must start with a letter or digit, and can be up to 60 characters long.

statement_name_prefix is a separate setting that changes only statement names. It leaves table and function names alone, so it doesn’t keep your tables and functions apart from other users’ in a shared cluster.

Changing name_prefix or statement_name_prefix on a target with running statements starts new statements under the new names, and the old ones keep running. Stop the old statements first. If your project overrides the generate_alias_name macro, prepend target.name_prefix | replace('-', '_') to the alias yourself, or tables don’t get the prefix.

Materializations

A materialization determines what the adapter creates for a model and which Flink SQL statements it submits.

Materialization

Use it for

Execution

materialized_table

Continuously maintained results. Use it for most streaming pipelines, because changes evolve in place.

Streaming. Flink maintains the table.

streaming_table

Continuously maintained results with an explicit table and a separate INSERT statement, or adopting a pipeline that you deployed outside dbt.

Streaming. A long-running INSERT INTO ... SELECT.

streaming_source

A table with a declared schema, backed by the faker or confluent Flink SQL connector.

Depends on the connector. A faker table generates data for each statement that reads it. A confluent table stores data in a Kafka topic.

table

A one-time, point-in-time result, like a batch warehouse table.

Snapshot. The query runs once and completes.

view

Reusable query logic that stores no data. This is the default.

Runs inside each statement that reads it.

ephemeral

Query logic that dbt inlines as a common table expression (CTE).

Runs inside each statement that reads it.

function

A Java or Python user-defined function (UDF) that models call with {{ function() }}. Declare it in the functions/ directory.

Registers the function. Runs inside each statement that calls it.

The following dbt materializations aren’t supported:

Materialization

Alternative

materialized_view

Use materialized_table for continuously maintained results, or table for a one-time result.

incremental

dbt’s batch-incremental model doesn’t map to continuous processing. Use materialized_table.

snapshot

dbt snapshots require MERGE and UPDATE operations that Flink SQL doesn’t support. See Limitations.

Set a materialization in a model’s config() block or for a whole directory in dbt_project.yml:

models:
  my_project:
    staging:
      +materialized: view
    marts:
      +materialized: materialized_table

materialized_table

A materialized_table model submits a CREATE OR ALTER MATERIALIZED TABLE statement with the model’s SELECT query. Flink then maintains the table continuously. For how materialized tables work, see Materialized Tables in Confluent Cloud for Apache Flink.

{{ config(
    materialized='materialized_table',
    distributed_by={'columns': ['customer_id'], 'buckets': 4},
    start_mode='RESUME_OR_FROM_BEGINNING',
) }}

SELECT
    customer_id,
    COUNT(*) AS order_count,
    SUM(price) AS lifetime_value
FROM {{ ref('orders') }}
GROUP BY customer_id

materialized_table is declarative. Every run submits the same statement, whether the table doesn’t exist yet, exists unchanged, or exists with a different definition. Flink treats an unchanged definition as a no-op and evolves a changed definition in place. This model doesn’t use schema drift detection.

Supported configuration: with, distributed_by, start_mode, statement_properties, tableflow, statement_name, compute_pool_id, and ignore_unsupported_config. You can also enforce a dbt model contract. See Contracts and primary keys. materialized_table also rejects the open source Flink options freshness_interval, refresh_mode, and partition_by, which Confluent Cloud doesn’t support. Setting any of them fails the run.

Start mode

start_mode controls where the query starts reading when the table is created, and where it restarts after the table evolves. Default: RESUME_OR_FROM_BEGINNING.

Value

Starts reading from

FROM_BEGINNING

The beginning of each source topic.

FROM_NOW

The current offset.

FROM_TIMESTAMP(TIMESTAMP '<yyyy-MM-dd HH:mm:ss>')

The given timestamp.

FROM_NOW(INTERVAL '<n>' <unit>)

<n> <unit> before now.

RESUME_OR_FROM_BEGINNING

Saved offsets if they exist, otherwise the beginning.

RESUME_OR_FROM_NOW

Saved offsets if they exist, otherwise the current offset.

RESUME_OR_FROM_TIMESTAMP(TIMESTAMP '<yyyy-MM-dd HH:mm:ss>')

Saved offsets if they exist, otherwise the given timestamp.

RESUME_OR_FROM_NOW(INTERVAL '<n>' <unit>)

Saved offsets if they exist, otherwise <n> <unit> before now.

Evolution and state

When you change a materialized_table model and run dbt run, Flink evolves the table in place. During an evolution, the query’s internal state, such as aggregations, joins, and windows, is discarded, and processing restarts according to start_mode:

  • Stateless queries, such as projections and filters, evolve without reprocessing or duplicates under a RESUME_* start mode, which includes the default. This works only when Flink can resume from the previous job’s position. If it can’t, the query starts from the start mode’s fallback position instead. For the default, that’s the beginning of each source topic, so an append-only table receives duplicates of the reprocessed records.

  • Stateful queries recalculate their results from empty state instead of adjusting the previous results. Under a RESUME_* start mode, the new results cover only records that arrive after the change, so aggregates can look undercounted.

To recompute a stateful query’s results from the beginning without deleting the table’s topic:

  1. Change the model’s query, and in the same edit, set start_mode='FROM_BEGINNING' in the model’s config.

  2. Run the model with dbt run.

    On a table that updates by key, the reprocessed results overwrite the old rows.

  3. After the run, set start_mode back to RESUME_OR_FROM_BEGINNING so that later changes don’t reprocess all history.

Warning

On an append-only table, reprocessing writes every reprocessed record to the table again, so the table contains duplicate records. Before you use FROM_BEGINNING on an append-only table, make sure that downstream consumers can handle the duplicates.

Running the model with --full-refresh also recomputes the result, but it deletes the table’s topic. For more information, see Full refresh.

For more information, see How to evolve materialized tables.

Some changes can’t evolve in place. Dropping a column that isn’t nullable, or changing distributed_by, fails the run. To apply these changes, run with --full-refresh.

Full refresh

--full-refresh drops and recreates the materialized table. This deletes the backing Kafka topic, all of its records, and its Schema Registry schema versions, and the new topic has a new identity even though its name is the same. Consumers of the topic, including other Flink SQL statements, can break. Coordinate full refreshes with downstream consumers.

Contracts and primary keys

To declare columns and a primary key, enforce a dbt model contract and add a model-level primary_key constraint in the model’s YAML file:

models:
  - name: customer_order_stats
    config:
      contract:
        enforced: true
    constraints:
      - type: primary_key
        columns: [customer_id]
        expression: "NOT ENFORCED"
    columns:
      - name: customer_id
        data_type: bigint
      - name: order_count
        data_type: bigint
      - name: lifetime_value
        data_type: decimal(38, 2)

Flink SQL requires primary keys to be NOT ENFORCED, so always set expression: "NOT ENFORCED" on the constraint. The adapter renders the columns and a PRIMARY KEY (...) NOT ENFORCED clause in the CREATE OR ALTER MATERIALIZED TABLE statement. Without an enforced contract, Flink infers the columns from the SELECT query.

Switch to or from materialized_table

The adapter doesn’t convert an existing table or view to a materialized table, or convert a materialized table in place to another materialization, even though Flink SQL can adopt an existing table as a materialized table. To switch, run the model with --full-refresh, which drops the existing table and its data. Without --full-refresh, the result depends on the direction of the switch:

  • To materialized_table from table, view, streaming_table, or streaming_source: the run fails with guidance.

  • From materialized_table to table, streaming_table, or streaming_source: schema drift detection fails the run with guidance. With on_schema_drift='ignore', the result depends on the new materialization:

    • table or streaming_source: drift detection doesn’t run, so the model is skipped and the materialized table keeps running.

    • streaming_table: the run still fails with guidance. The adapter never submits an INSERT statement into the materialized table.

  • From materialized_table to view: the run drops the materialized table, including its topic and data, and creates the view. Check a model’s downstream consumers before you make this change.

streaming_table

A streaming_table model submits two statements: a CREATE TABLE statement, and a long-running INSERT INTO ... SELECT statement that populates the table. Use it to adopt a pipeline that you deployed outside dbt, or when you need a separate INSERT statement. For other streaming pipelines, use materialized_table.

{{ config(
    materialized='streaming_table',
    distributed_by={'columns': ['customer_id'], 'buckets': 4},
    with={'changelog.mode': 'append'},
) }}

SELECT customer_id, order_id, price
FROM {{ ref('orders') }}
WHERE price > 0

Supported configuration: with, distributed_by, on_schema_drift, statement_properties, tableflow, statement_name, compute_pool_id, and ignore_unsupported_config.

Columns and the contract check

A streaming_table model takes its table’s columns from the columns list in the model’s YAML file. List every column that the SELECT query returns, with its data_type:

models:
  - name: large_orders
    columns:
      - name: customer_id
        data_type: bigint
      - name: order_id
        data_type: string
      - name: price
        data_type: decimal(10, 2)

Before the adapter creates the table, and before it resubmits a missing or terminal INSERT statement, dbt runs its contract check. The check runs whether or not the model enforces a contract. If the query doesn’t return exactly the listed columns, with the same names and data types, the run fails. dbt compares only the base data types, not precision, scale, or length, so a DECIMAL(10, 2) query column passes the check for a decimal(12, 2) YAML column. The adapter still creates the table with the YAML type, so schema drift detection reports drift and fails every later run. Make each query type match its YAML type exactly, for example with CAST(price AS DECIMAL(12, 2)).

Flink types a string literal, such as 'large', as CHAR(n) and a binary literal, such as x'0102', as BINARY(n). Starting with adapter version 0.6.0, these pass the check, and schema drift detection, for string or varchar and bytes or varbinary columns. Earlier versions needed a cast, for example CAST('large' AS STRING). A literal for a varchar(n) or varbinary(n) column with a length below the maximum still fails, because the check doesn’t compare lengths and Flink truncates longer values.

The INSERT statement names the listed columns and selects them from the query by name. Each value goes into the column with the same name, whatever order the query returns the columns in.

Important

In adapter versions earlier than 0.5.0, the contract check ran only before CREATE TABLE, and the INSERT statement wrote columns by position. If the query returned columns in a different order from the table, and the swapped columns had compatible types, the INSERT statement wrote values into the wrong columns without an error. This could happen when the YAML column order differed from the query’s, or when you reordered the query’s columns later. Writing by name in 0.5.0 prevents this for new statements, but it doesn’t fix data that’s already written.

Starting with 0.5.0, a restart also fails if the model’s YAML file doesn’t list every column with its data type. Models that adopt a pipeline from outside dbt are the most likely to be missing columns. Before you upgrade:

  • Add any missing columns to the YAML file.

  • If a model’s YAML column order didn’t match its query’s, check the table’s data. To discard values written to the wrong columns, run the model with --full-refresh, which drops the table and deletes all of its data.

Re-run behavior

When the table already exists and you run without --full-refresh:

  1. The adapter runs schema drift detection. If the model no longer matches the table, the run fails.

  2. The adapter checks the INSERT statement. If the statement is missing, or is in a terminal phase (COMPLETED, STOPPED, or FAILED), dbt runs its contract check, and then the adapter resubmits only the INSERT statement, under the same name. The table and its data are kept.

  3. A statement that is RUNNING, DEGRADED, or in transition (PENDING, STOPPING, or DELETING) is left alone.

Because a healthy statement is left alone, a change to a model’s query logic, statement_properties, or compute_pool_id takes effect only when you run with --full-refresh or the adapter resubmits a missing or terminal statement.

Adopt an existing pipeline

You can bring a pipeline that you deployed outside dbt under dbt management without recreating it. Point a streaming_table model at the existing table with dbt’s alias configuration, and at the existing INSERT statement with statement_name:

{{ config(
    materialized='streaming_table',
    alias='orders_enriched',
    statement_name='orders-enriched-insert',
    with={'changelog.mode': 'append'},
) }}

SELECT order_id, price FROM {{ ref('orders') }}

On the next dbt run without --full-refresh, the adapter looks up the table and statement by name. It adopts a healthy statement as-is, resubmits a missing or terminal one under the same name, and never drops the table.

  • The model’s schema must match the existing table. Under the default on_schema_drift='fail', any mismatch fails the run.

  • The model’s YAML file must list every column with its data type, or the adapter can’t resubmit the statement. For details, see Columns and the contract check.

  • The statement name must match exactly after the adapter normalizes it. For the normalization rules, see Statement names.

streaming_source

A streaming_source model creates a table with a Flink SQL connector. The model body is the table’s column list, not a SELECT query. The connector configuration is required and sets the connector option of the table’s CREATE TABLE statement. These are Flink SQL table connectors, not Kafka Connect connectors.

The adapter supports two connectors:

Connector

Creates

faker

A table that generates sample data. For options, see Generate Custom Sample Data with Confluent Cloud for Apache Flink.

confluent

A table backed by a Kafka topic, with the schema that the model declares. Use it when other applications produce to the topic and you want dbt to own the table’s schema. Running this model with --full-refresh deletes the topic and every record that other applications produced to it.

The following model creates a faker table:

{{ config(
    materialized='streaming_source',
    connector='faker',
    with={
        'rows-per-second': '1',
        'fields.order_id.expression': "#{number.numberBetween '1','1000000'}",
    },
) }}

order_id BIGINT,
price DECIMAL(10, 2),
order_time TIMESTAMP(3),
WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND

The following model creates a confluent table:

{{ config(
    materialized='streaming_source',
    connector='confluent',
) }}

order_id BIGINT,
status STRING

The adapter merges connector into the table’s WITH options and escapes single quotes in keys and values, so write quotes as-is.

Supported configuration: connector, with, distributed_by, on_schema_drift, tableflow, statement_name, compute_pool_id, and ignore_unsupported_config. distributed_by and tableflow apply only to confluent tables, because a faker table has no topic.

A Faker table doesn’t store data. Flink generates rows separately for each statement that reads the table, so two models that read the same Faker table get different data. To give several models the same data, or to let Flink reprocess it later, read the Faker table from one materialized_table model, which stores the rows in a topic, and have the other models read from that model.

When the table already exists, the adapter runs schema drift detection and skips the model. Drift detection includes connector and the with options, so to change them, run the model with --full-refresh, which drops and recreates the table.

table

A table model submits a CREATE TABLE ... AS SELECT statement in snapshot mode. The query reads a point-in-time view of its sources, writes the result, and completes. Use it for batch-style results and as a first model when you learn the adapter.

{{ config(materialized='table') }}

SELECT customer_id, COUNT(*) AS order_count
FROM {{ ref('orders') }}
GROUP BY customer_id

Supported configuration: distributed_by, on_schema_drift, tableflow, statement_name, compute_pool_id, and ignore_unsupported_config.

When the table already exists, the adapter runs schema drift detection and skips the model. To recompute the result, run with --full-refresh, which drops the table and its data and runs the query again.

view

A view model submits a CREATE VIEW statement. A view stores no data. Flink inlines the view’s query into each statement that reads from it.

Supported configuration: statement_name, compute_pool_id, and ignore_unsupported_config.

When the view already exists, the adapter updates it in place with an ALTER VIEW ... AS statement on every run. The adapter doesn’t check for drift or skip an unchanged view: every run submits the statement. If Flink rejects the new SQL, or the model’s enforced contract no longer matches, the run fails and the existing view keeps working. Starting with adapter version 0.6.0, this replaces the earlier behavior of dropping and recreating the view, which left no view when the new SQL failed.

Flink doesn’t check an altered view’s columns against the old ones. A downstream view that uses a column that the new SQL removes or retypes fails when it’s queried, until you rebuild it.

With --full-refresh, the adapter drops the view and creates it again. This gives up the protection of ALTER VIEW: if the CREATE VIEW statement fails after the drop, no view exists until you fix the model and run it again. The model’s full_refresh configuration has the same effect as the flag and takes precedence over it. For example, with full_refresh: false, the adapter alters the view even when you pass --full-refresh.

If something other than a view exists under the model’s name, for example a table from an earlier table model, the adapter drops it and creates the view, with or without --full-refresh.

ephemeral

An ephemeral model behaves as in any other dbt adapter. dbt inlines the model’s SQL as a CTE in every model that references it, and the adapter creates nothing. The adapter doesn’t validate configuration keys on ephemeral models. If several models reference the same ephemeral model, each statement reads the underlying source separately.

function

Starting with adapter version 0.6.0, a function registers a Java or Python user-defined function (UDF) in Flink from an artifact: a JAR file for Java or a ZIP file for Python. Models call the function with {{ function('<name>') }}, and dbt builds the function before any model that calls it.

Declare each function in its own file in the project’s functions/ directory. The adapter generates the CREATE FUNCTION statement, and the function’s code is in the artifact, so the file contains only a config() block:

-- functions/product_slug.sql
{{ config(
    language='python',
    artifact_path='udfs/product_udfs/dist/product_udfs-0.1.0.zip',
    path='product_udfs.slug.product_slug',
) }}
-- models/marts/products.sql
SELECT
    product_name,
    {{ function('product_slug') }}(product_name) AS product_slug
FROM {{ ref('stg_orders') }}

Flink reads the function’s argument and return types from the function’s code, so you don’t need dbt’s arguments and returns properties.

Build functions with dbt build. dbt run doesn’t create or update functions, so a model that calls a new function fails with Function '<name>' does not exist. To build a function and everything that calls it, run:

dbt build --select product_slug+

For a complete example that builds the Python package, see Step 9: (Optional) Add a user-defined function.

Configuration

Description

language

Required. java or python.

artifact_path

A package for the adapter to upload, relative to the project root: a .jar file for java or a .zip file for python. To build a package, see Step 1: Build the artifact. Set either artifact_path or artifact_id.

artifact_id

The ID of an artifact that you already uploaded to the environment, for example cfa-xxxxxx. See Step 2: Upload the UDF as a Flink artifact.

path

Required. For Java, the class name, for example com.example.TShirtSizingIsSmaller. For Python, the module path and function name, for example product_udfs.slug.product_slug.

connections

Optional. A list of connection names that the function can call, for external connectivity. A name that isn’t fully qualified resolves against the function’s own environment and cluster.

on_configuration_change

Optional. What to do when the existing function differs from the configuration: apply, continue, or fail. Default: apply. For more information, see Change a function.

statement_name, compute_pool_id, ignore_unsupported_config

See Statement names, compute_pool_id, and Configuration validation.

Credentials

Every function needs credentials that can use the artifact API, whether it sets artifact_path or artifact_id: auth: oauth, a global API key, or a Flink API key together with cloud_api_key and cloud_api_secret. With only a Flink API key, the function fails with a compilation error before the adapter submits anything.

To upload artifacts and register functions, your account also needs one of these roles: FlinkDeveloper bound at the environment level or higher, FlinkFunctionDeveloper, FlinkAdmin, EnvironmentAdmin, or OrganizationAdmin. A FlinkDeveloper role binding scoped to a compute pool has no access to artifacts or functions. With that binding, also grant FlinkFunctionDeveloper. For more information, see Grant Role-Based Access in Confluent Cloud for Apache Flink.

Upload the artifact

With artifact_path, the adapter uploads the package and names the artifact after the project, the filename, and a hash of the package’s content, for example orders_pipeline-product_udfs-0_1_0-84351515.

  • An unchanged package reuses its artifact, and the adapter leaves the function as it is.

  • A changed package is uploaded as a new artifact, and the adapter replaces the function to use it. The adapter compares the package’s bytes, so rebuilding the package from unchanged code can produce a new artifact, for example because of file timestamps.

  • Functions that use the same package file share one artifact.

Build the package before you run dbt, and don’t change it while dbt runs. The adapter hashes the file at the start of the run and uploads it later.

The adapter finds its artifacts by their description, which records that dbt manages the artifact, the project, the filename, and the full SHA-256 hash. If another artifact already has the name, for example one that you created yourself, the upload fails. Delete that artifact or rename the package file.

Change a function

Flink functions can’t be altered, so a change means dropping the function and creating it again. On every run, the adapter describes the existing function and compares its path, language, artifact, and connections with the configuration:

  • If the function doesn’t exist, the adapter creates it.

  • If the function matches, the adapter submits nothing else.

  • If the function differs, on_configuration_change decides what happens. Each option names what differs:

    Value

    Behavior

    apply

    The default. Warns, drops the function, and creates it again.

    continue

    Warns and keeps the existing function.

    fail

    Fails the run without changing anything.

With --full-refresh, the adapter always drops the function and creates it again, even if it matches, and on_configuration_change doesn’t apply.

Before it drops a function that sets artifact_id, the adapter checks that the new artifact exists. If creating the function fails after the drop, the adapter tries to create the previous function again. If the run is stopped between the drop and the create, no function is left. Run the build again.

Statements that are already running keep the function version that they started with, and stay bound to its artifact. Models that call the function use the new version only after you rebuild them, for example with --full-refresh. Because apply is the default, set on_configuration_change to fail or continue for functions whose callers you can’t rebuild at the same time, for example for every function in the project:

# dbt_project.yml
functions:
  +on_configuration_change: fail

Update a function and delete old artifacts

The adapter never deletes artifacts, because running and stopped statements stay bound to the artifact that they started with. Each organization, cloud, region, and environment can have at most 100 artifacts. For this and other limits, see UDF limitations. If every statement that uses your functions belongs to the dbt project, update the functions and delete the old artifacts like this:

  1. Build the new package, and point the function’s artifact_path at it.

  2. Replace every function and rebuild everything downstream of the functions:

    dbt build --select "resource_type:function+" --full-refresh
    

    --full-refresh drops and recreates the downstream tables, which deletes their topics and data, so their results start over. Select every function, not only the changed ones, because the next step considers the whole project.

  3. List and then delete the artifacts that this project uploaded and that no function uses:

    Important

    Before you delete artifacts, make sure that no stopped or failed statement still uses an old version of a function, including statements outside this dbt project. A statement can’t resume after its artifact is deleted, and resuming it fails with an artifact-not-found error.

    dbt run-operation sweep_function_artifacts
    dbt run-operation sweep_function_artifacts --args '{delete: true}'
    

    The operation finds unused artifacts with INFORMATION_SCHEMA and can’t see statements. Run it only after the previous step recreated the statements, and never while a dbt run or dbt build is in progress. It never lists or deletes artifacts that another project or a user uploaded.

To limit the sweep to artifacts that existed before a deployment, list them first. list_function_artifacts writes the project’s artifacts, and the functions that use them, to target/confluent_function_artifacts.json:

dbt run-operation list_function_artifacts
dbt build --select "resource_type:function+" --full-refresh
dbt run-operation sweep_function_artifacts \
  --args '{delete: true, list_file: target/confluent_function_artifacts.json}'

For artifacts that you manage outside dbt with artifact_id, follow the same order by hand: upload the new artifact, resubmit the statements that use the function, and delete the old artifact only after that. For more information, see Update a UDF safely.

Statements

When the adapter creates or replaces a function, it submits one CREATE FUNCTION statement. The statement names the path and the artifact, confluent-artifact://<artifact-id>, and adds LANGUAGE PYTHON for a Python function and USING CONNECTIONS when you set connections. A replacement is preceded by DROP FUNCTION. Every run first submits DESCRIBE FUNCTION, so an unchanged function costs one short statement. These statements complete immediately.

Model configuration

The following table shows which adapter-specific configuration keys each materialization accepts. If you set a key on a materialization that doesn’t accept it, the run fails with an error instead of ignoring the key, unless you list the key in ignore_unsupported_config. For more information, see Configuration validation. Functions accept their own keys, listed in function.

Configuration key

materialized_table

streaming_table

streaming_source

table

view

with

Yes

Yes

Yes

No

No

distributed_by

Yes

Yes

Yes

Yes

No

tableflow

Yes

Yes

Yes

Yes

No

start_mode

Yes

No

No

No

No

statement_properties

Yes

Yes

No

No

No

on_schema_drift

No

Yes

Yes

Yes

No

connector

No

No

Required

No

No

statement_name, compute_pool_id, ignore_unsupported_config

Yes

Yes

Yes

Yes

Yes

with

A dictionary of table options that the adapter renders in the table’s WITH clause, for example {'changelog.mode': 'append'} or {'value.format': 'avro-registry'}. For available options, see CREATE TABLE Statement in Confluent Cloud for Apache Flink.

distributed_by

Controls how rows are distributed across the partitions of the backing Kafka topic. The adapter renders a DISTRIBUTED BY HASH(...) INTO <n> BUCKETS clause.

{{ config(distributed_by={'columns': ['order_id'], 'buckets': 4}) }}

SELECT order_id, customer_id, price FROM {{ ref('orders') }}

Field

Description

columns

Required. A non-empty list of column names to hash.

buckets

Optional. A positive integer. If you omit it, Confluent Cloud chooses the number of buckets.

The distribution columns must be the first columns of the table, in the same order as columns. In a SELECT model, list them first. In a streaming_source model, declare them first. Otherwise, Flink rejects the statement. You can’t change distributed_by on an existing table without --full-refresh.

statement_properties

A dictionary of statement properties, the same properties that you set with the SET statement, for example {'sql.tables.scan.idle-timeout': '30 s'}. Values can be strings, integers, or Booleans.

{{ config(
    materialized='materialized_table',
    statement_properties={'sql.tables.scan.idle-timeout': '30 s'},
) }}

For materialized_table, the next run applies changed properties to the materialized table, even when the query is unchanged. Treat this like any other change to the model: the query restarts, which can reset a stateful model’s results. See Evolution and state.

For streaming_table, the properties apply only to the INSERT statement and take effect only when the adapter resubmits a missing or terminal statement, or when you run with --full-refresh. To set table options, use with instead.

You can’t set sql.current-catalog, sql.current-database, or sql.snapshot.mode, because the adapter manages them.

compute_pool_id

Runs a model’s statements on a specific compute pool instead of the profile default, for example to isolate a heavy model:

{{ config(compute_pool_id='lfcp-abc123') }}

The pool must be in the same environment and region as the profile, and your API key must have access to it. To use a different pool in each environment, read the ID from an environment variable:

{{ config(compute_pool_id=env_var('FLINK_COMPUTE_POOL')) }}

How a changed pool takes effect depends on the materialization:

  • view: the next run uses the new pool.

  • materialized_table: changing only compute_pool_id doesn’t move an existing materialized table to the new pool. Its query keeps running on the pool where the table was created. To move it and keep its data, update the materialized table with the REST API. Or run the model with --full-refresh, which drops the table and its data.

  • streaming_table: a running INSERT statement doesn’t move. The adapter uses the new pool when it resubmits a missing or terminal statement, or when you run with --full-refresh.

  • streaming_source and table: the new pool is used the next time you run the model with --full-refresh.

tableflow

Enables Tableflow on the Kafka topic behind a model, which materializes the topic as an Apache Iceberg™ table, a Delta Lake table, or both. You can query the result from analytics engines or from Flink with a snapshot query.

{{ config(
    materialized='materialized_table',
    tableflow={
        'table_formats': ['ICEBERG'],
        'storage': {'kind': 'Managed'},
        'config': {
            'retention_ms': 604800000,
            'error_handling': {'mode': 'LOG', 'target': 'error_log'},
        },
    },
) }}

Field

Description

table_formats

Required. 'ICEBERG', 'DELTA', or a list with one or both.

storage

Required. Where Tableflow writes the tables. Set kind to one of the following:

  • {'kind': 'Managed'} for Confluent-managed storage.

  • {'kind': 'ByobAws', 'bucket_name': '...', 'provider_integration_id': '...'} for your own Amazon S3 bucket.

  • {'kind': 'AzureDataLakeStorageGen2', 'storage_account_name': '...', 'container_name': '...', 'provider_integration_id': '...'} for your own Azure Data Lake Storage Gen2 container.

  • {'kind': 'GoogleCloudStorage', 'bucket_name': '...', 'provider_integration_id': '...'} for your own Google Cloud Storage bucket.

For more information, see Storage with Tableflow in Confluent Cloud.

config

Optional. Topic-level Tableflow settings:

  • retention_ms: How long to keep table snapshots, in milliseconds.

  • data_retention_ms: How long to keep table data, in milliseconds.

  • error_handling: What to do when a record can’t be materialized. {'mode': 'SUSPEND'} suspends Tableflow, which is the default. {'mode': 'SKIP'} skips the record. {'mode': 'LOG', 'target': '<topic>'} writes the record to a dead letter queue (DLQ) topic, error_log by default, and continues. For more information, see Error-handling mode.

The adapter reconciles Tableflow on every run:

  • If Tableflow isn’t enabled, the adapter enables it.

  • If you changed table_formats or config, the adapter updates Tableflow in place. If nothing changed, it sends no update.

  • If you changed storage, the adapter disables Tableflow and enables it again with the new storage.

  • If Tableflow is in a FAILED state and there is nothing to update, the run reports a warning.

The adapter changes only the settings that the model sets. Removing retention_ms, data_retention_ms, or error_handling from the configuration doesn’t reset them, and removing the tableflow configuration from a model doesn’t disable Tableflow. To disable Tableflow or reset a setting, use the Cloud Console.

When you run with --full-refresh, the adapter disables Tableflow before it drops the table only if the model still sets tableflow. If you removed the configuration, disable Tableflow in the Cloud Console before you run with --full-refresh.

Tableflow requirements and limitations:

  • Tableflow requires a global API key or auth: oauth in the profile. For OAuth, see Sign in with OAuth. A Flink API key can’t reach the Tableflow APIs. A global API key works for Flink too, so you don’t need both keys.

  • For Tableflow permissions, see Grant Role-Based Access for Tableflow in Confluent Cloud.

  • A storage change turns Tableflow off for the topic until the adapter enables it again, and Confluent Cloud can reject enabling Tableflow on the same topic for a while after it’s disabled. Until the run succeeds, the Tableflow table stops updating and dbt run fails for that model. For how disabling works, see Disable Tableflow. To rebuild immediately instead, run with --full-refresh, which also deletes the topic’s data.

Configuration validation

If you set an adapter-specific configuration key on a materialization that doesn’t use it, for example statement_properties on a table model, the run fails with an error that names the key. The check covers only the adapter’s own keys, which are listed in Model configuration, and the open source options that materialized_table rejects. It never inspects other configuration keys, including keys that your own macros read.

If one of your own keys has the same name as an adapter key, exclude it from the check for that model:

{{ config(
    materialized='table',
    statement_properties={'my_custom_key': 'value'},
    ignore_unsupported_config=['statement_properties'],
) }}

Schema drift detection

table, streaming_table, and streaming_source models skip creation when their table already exists. Before skipping, the adapter checks whether the existing table still matches the model, and fails the run if it doesn’t. materialized_table models don’t use drift detection, because Flink reconciles their definition on every run.

For table and streaming_table models, the adapter submits two dry-run statements: the model’s SELECT query, and SELECT * from the existing table. Flink plans each query and returns its result schema without running it, so nothing is left to clean up. The adapter then compares the two schemas. It runs the dry runs in the mode that the model is built in: snapshot for table and streaming for streaming_table. As a result, a table model whose query works only as a streaming query fails the check. If a dry run fails, for example because the SQL is invalid, the run fails.

The check compares:

  • Columns: names and data types. Added, removed, renamed, or retyped columns are drift. Column order doesn’t matter. The check ignores top-level nullability in both directions. For example, a NOT NULL column in the existing table isn’t drift when the query returns a nullable column for it.

  • distributed_by: the column list, column order, and bucket count, if you set buckets. If you don’t set distributed_by, the adapter doesn’t check distribution.

  • WITH options for streaming_table and streaming_source: every option that you set must have the same value on the table. For streaming_source, this includes connector. Starting with adapter version 0.6.0, the check compares durations and sizes by value and ignores case, because Flink can report a value in a different form than the model wrote it. For example, 'kafka.retention.time': '7 days' matches 7 d, and 'COMPACT' matches compact. As a result, a change that only alters a value’s case, or rewrites the same duration or size, such as '1 h' to '60 min', isn’t detected. Earlier versions reported drift on every run for these values.

The run reports every mismatch in a single error. To apply the model’s current definition, run with --full-refresh, which drops and recreates the table and deletes its data.

Drift detection doesn’t catch everything:

  • Removed WITH options aren’t detected, because connectors add their own options that the adapter can’t tell apart from yours.

  • Query logic changes that keep the same column names and types aren’t detected. For example, changing ROUND(price, 2) to ROUND(price, 4) isn’t drift. Run with --full-refresh to apply the change.

  • YAML data types aren’t compared. For a streaming_table model, or a table model with an enforced contract, the check compares the query’s column types with the table’s, not with the data_type values in the YAML file. If a query type differs from the YAML type, for example a DECIMAL(10, 2) expression for a decimal(12, 2) column, every re-run reports drift.

To turn off drift detection for a model, set on_schema_drift='ignore'. The adapter then skips the model whenever its table exists. The default is 'fail'. For streaming_table, the adapter still resubmits a missing or terminal INSERT statement, and before it does, it still checks that the columns match, because Flink would reject the statement otherwise.

{{ config(materialized='streaming_table', on_schema_drift='ignore') }}

For streaming_source models, whose body is a column list and not a query, the adapter creates a temporary table named __dbt_tmp_schema_check_<model> from the column list and compares its columns with the existing table’s. It also falls back to a temporary table for table and streaming_table models when a dry run doesn’t return a usable schema. The adapter drops the temporary table when the model finishes, even if the run fails.

In adapter versions earlier than 0.5.0, every drift check used a temporary table, which made re-runs slower.

Statement names

The adapter gives each statement a predictable name: <statement_name_prefix><project>-<model>, for example dbt-my-project-stg-orders-a1b2c3. If you set name_prefix, it comes first. The six-character hash at the end appears whenever the name contains characters that the adapter replaces, which includes the underscores in most dbt project and model names. The prefix defaults to dbt-. Other statements use suffixes:

  • A streaming_table model’s CREATE TABLE statement has a -ddl suffix.

  • A materialized_table model’s statement has a unique suffix for each run, because the statement completes as soon as Flink accepts the definition. If the statement fails, it’s kept for debugging.

To choose a name, set the statement_name configuration. The adapter uses it in place of the generated name, without statement_name_prefix. It still adds the suffixes in the preceding list, so a materialized_table statement always gets a per-run suffix. For an exact name, as when you adopt an existing pipeline, use streaming_table.

Statement names can contain only lowercase letters, digits, and hyphens, must start and end with a letter or digit, and can be up to 100 characters long. The adapter replaces other characters, including underscores, with hyphens and appends a six-character hash so that names stay unique. Names longer than 100 characters are shortened and get a hash.

When you run with --full-refresh, the adapter deletes a model’s statements before it drops and recreates the table.

Reference existing topics with sources

To read from a table that already exists in Flink, such as a topic that another application or team produces, declare it as a dbt source. A source creates nothing; it lets dbt resolve the table by name and show it in the lineage graph. This is different from streaming_source, which creates a new table.

# models/sources.yml
version: 2

sources:
  - name: marketplace
    database: examples
    tables:
      - name: orders
      - name: clicks

A source’s database is the Flink SQL catalog, which is a Confluent Cloud environment or the read-only examples catalog. Its schema is the Flink SQL database, which is a Kafka cluster name. If you omit schema, dbt uses the source name, so the preceding example resolves to examples.``marketplace``. For your own topics, set database to your environment ID and schema to your cluster name. Reference the source with {{ source() }}:

SELECT
    `order_id`,
    `customer_id`,
    `price`,
    `$rowtime` AS order_time
FROM {{ source('marketplace', 'orders') }}

Flink SQL quotes identifiers with backticks. Use backticks for names with special characters, such as the $rowtime system column.

Testing

The adapter supports dbt unit tests and data tests. For a worked example, see Step 6: Test the pipeline.

  • For each unit test, the adapter creates temporary tables with CREATE TABLE ... LIKE for the model’s inputs, inserts the mock rows, runs the model, and compares the output with the expected rows. It drops the temporary tables afterward. The model and its inputs must already exist in the target, so deploy with dbt run before you run unit tests. The adapter finds the tested model’s table by the model’s name, so unit tests don’t support models whose table name differs from the model name, such as models that set alias or projects that override generate_alias_name.

  • Data tests run as queries against the deployed models. A test passes when its query returns no rows. A data test checks every row that is in the table when the test runs, including tables that are still receiving data. Rows that arrive later are checked the next time you run dbt test.

  • Don’t use --store-failures or the store_failures configuration. By default, dbt stores failures in a dbt_test__audit schema, which fails the run unless a Kafka cluster with that name exists. If you point the failures at an existing cluster, a failing test can report PASS, because the adapter counts the stored failures before Flink writes them.

In streaming mode, COUNT(*) over an empty result returns no rows instead of one row with the value 0. The adapter accounts for this in test assertions.

Manage deployments

Dependencies and selective deployment

{{ ref() }} and {{ source() }} define your pipeline’s dependency graph. dbt deploys models in dependency order, so upstream models exist before the models that read from them. Use dbt’s node selection syntax to list or deploy part of the graph:

# List stg_orders and everything downstream of it
dbt ls --select stg_orders+

# Deploy fct_revenue and everything upstream of it
dbt run --select +fct_revenue

# Deploy only models that changed since the last deployment
dbt run --select state:modified --defer --state <path-to-previous-artifacts>

For streaming_table, table, and streaming_source models, state:modified selects a changed model, but the adapter doesn’t apply query changes to an existing table. Rebuild those models with --full-refresh.

{{ function() }} adds a function to the graph in the same way. If your project has functions, deploy with dbt build instead of dbt run, because dbt run doesn’t create or update functions. dbt build also runs the tests of the models that it builds.

Before you rebuild a model with --full-refresh, list its downstream models. Rebuilding a table gives its topic a new identity, so statements that read from it can also need a rebuild. To explore the lineage graph, run dbt docs generate and dbt docs serve.

For schema compatibility and statement evolution beyond what the adapter manages, see Schema and Statement Evolution with Confluent Cloud for Apache Flink and Carry-over Offsets in Confluent Cloud for Apache Flink.

CI/CD

Run dbt from your CI/CD system to test and deploy on every merge. Unit tests need the tested models and their inputs to exist, so deploy to a CI environment first, test there, and then deploy to production. The following GitHub Actions workflow uses the ci and prod targets from the profiles.yml file in Multiple environments. It expects that file at the root of your repository, which is what --profiles-dir . points to. The file reads every credential with env_var(), so it contains no secrets and is safe to commit. Use an API key in CI/CD targets, not auth: oauth, because OAuth sign-in requires someone at a browser.

on:
  push:
    branches:
      - main

jobs:
  dbt_deploy:
    name: "Deploy Flink SQL with dbt"
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Install dependencies
        run: pip install "dbt-confluent==<adapter-version>"

      - name: Deploy to CI
        run: dbt run --target ci --profiles-dir .
        env:
          CI_CONFLUENT_GLOBAL_API_KEY: ${{ secrets.CI_CONFLUENT_GLOBAL_API_KEY }}
          CI_CONFLUENT_GLOBAL_API_SECRET: ${{ secrets.CI_CONFLUENT_GLOBAL_API_SECRET }}

      - name: Test in CI
        run: dbt test --target ci --profiles-dir .
        env:
          CI_CONFLUENT_GLOBAL_API_KEY: ${{ secrets.CI_CONFLUENT_GLOBAL_API_KEY }}
          CI_CONFLUENT_GLOBAL_API_SECRET: ${{ secrets.CI_CONFLUENT_GLOBAL_API_SECRET }}

      - name: Deploy to production
        run: dbt run --target prod --profiles-dir .
        env:
          PROD_CONFLUENT_GLOBAL_API_KEY: ${{ secrets.PROD_CONFLUENT_GLOBAL_API_KEY }}
          PROD_CONFLUENT_GLOBAL_API_SECRET: ${{ secrets.PROD_CONFLUENT_GLOBAL_API_SECRET }}

Each step gets only the credentials for its own target, so the CI steps can’t read the production key. Store the API keys and secrets for both environments as GitHub Actions secrets, and pin the adapter version so that every run uses the same adapter. To require approval before production deployments, run the production step in a GitHub environment with required reviewers.

If the project has functions, change the workflow as follows:

  • Replace dbt run with dbt build in the deploy steps, because dbt run doesn’t create or update functions.

  • Make each package that an artifact_path names available before the deploy steps. The adapter uploads the file at that path, so either commit the package to the repository, or add a step that builds the package or downloads it from where you publish it.

The adapter compares the package’s bytes, not its source code. If the pipeline builds the package on every run and the bytes differ each time, every deploy uploads a new artifact and, with the default on_configuration_change: apply, drops and recreates the function. The adapter never deletes artifacts, so repeated deploys approach the limit of 100 artifacts. For more information, see Update a function and delete old artifacts.

The build commands in Step 9: (Optional) Add a user-defined function produce a different ZIP file on each run. uv build --sdist writes an identical .tar.gz file each time, but zip stores the .tar.gz file’s modification time. To produce identical bytes when the code doesn’t change, set a fixed modification time on the .tar.gz file, and pass -X so that zip doesn’t store extra file attributes:

uv build --sdist
touch -t 202001010000 dist/product_udfs-0.1.0.tar.gz
zip -X -r dist/product_udfs-0.1.0.zip dist/product_udfs-0.1.0.tar.gz

Alternatively, upload the artifact outside dbt, and set artifact_id instead of artifact_path. For more information, see Step 2: Upload the UDF as a Flink artifact.

Multiple environments

To deploy to more than one environment, for example a CI environment and production, define a target for each in profiles.yml and choose one with --target:

my_project:
  target: ci
  outputs:
    ci:
      type: confluent
      cloud_provider: aws
      cloud_region: us-east-2
      organization_id: <your-organization-id>
      environment_id: <ci-environment-id>
      compute_pool_id: <ci-compute-pool-id>
      dbname: <ci-kafka-cluster-name>
      global_api_key: "{{ env_var('CI_CONFLUENT_GLOBAL_API_KEY') }}"
      global_api_secret: "{{ env_var('CI_CONFLUENT_GLOBAL_API_SECRET') }}"
      threads: 1
    prod:
      type: confluent
      cloud_provider: aws
      cloud_region: us-east-2
      organization_id: <your-organization-id>
      environment_id: <prod-environment-id>
      compute_pool_id: <prod-compute-pool-id>
      dbname: <prod-kafka-cluster-name>
      global_api_key: "{{ env_var('PROD_CONFLUENT_GLOBAL_API_KEY') }}"
      global_api_secret: "{{ env_var('PROD_CONFLUENT_GLOBAL_API_SECRET') }}"
      threads: 4
dbt run --target prod

Troubleshooting

dbt run fails on the example models

The example models that dbt init creates in models/example/ select an untyped NULL (select null as id), which Flink SQL rejects. Delete the models/example/ directory and the example entry under models: in dbt_project.yml.

macro ‘dbt_macro__statement’ takes no keyword argument ‘hidden’

dbt Core 1.12 is installed with an adapter version earlier than 0.6.0, which supports only dbt Core 1.11. Upgrade the adapter, which installs the dbt Core version that it supports:

pip install --upgrade dbt-confluent

To stay on an earlier adapter version, install dbt Core 1.11 instead with pip install "dbt-core~=1.11.0". Adapter versions 0.3.2 and later pin the dbt Core version that they support. See Version compatibility.

Credentials can reach several organizations

With auth: oauth or a global API key and no organization_id, the connection fails with Your credentials can reach several Confluent Cloud organizations, and the error lists the organizations’ IDs and names. Set organization_id in the profile to one of them. For more information, see Omit the organization, cloud provider, and region.

403 “You don’t have the required permissions” without a compute pool

If you omit compute_pool_id, Flink runs statements in the default compute pool, and it returns a 403 error when your principal can’t use it. This happens when default compute pools are disabled for your organization, or when your FlinkDeveloper role binding is scoped to a specific compute pool. Set compute_pool_id in the profile to a pool that your principal can use. For more information, see Compute Pools in Confluent Cloud for Apache Flink and Grant Role-Based Access in Confluent Cloud for Apache Flink.

Connection fails with endpoint and cloud region both set

Older installs reject a profile that sets endpoint together with cloud_provider or cloud_region, because confluent-sql versions earlier than 0.5.5 don’t allow it. Upgrade the adapter, which also upgrades confluent-sql, or remove cloud_provider and cloud_region. Adapter versions earlier than 0.3.1 report every connection failure as a generic confluent_sql connection error. Upgrade to see the underlying cause.

Current versions accept all three settings. Requests go to endpoint, and the adapter uses cloud_provider and cloud_region only for function artifacts. With endpoint set, the adapter doesn’t infer the cloud provider and region. It reads them from the endpoint URL when the URL has the form https://flink.<region>.<cloud>.confluent.cloud or https://flink.<region>.<cloud>.private.confluent.cloud. For any other endpoint, a function fails with an Artifacts are scoped to a cloud and region error. To fix it, set cloud_provider and cloud_region next to endpoint.

Tableflow fails with an authentication error

Tableflow requires a global API key or auth: oauth in the profile, or, starting with adapter version 0.6.0, tableflow_api_key and tableflow_api_secret together with database_kafka_cluster_id. If the profile has only a Flink API key, replace it with a global API key, which also works for Flink, set auth: oauth, or add the Tableflow key. For more information, see Profile configuration and Sign in with OAuth.

A function fails with “needs credentials that can use the artifact API”

The profile has only a Flink API key, which can’t use the artifact API. Set auth: oauth, replace the key with a global API key, or add cloud_api_key and cloud_api_secret. For more information, see Credentials.

A model fails with “Function … does not exist”

The model calls {{ function() }}, but the function hasn’t been created. dbt run doesn’t create or update functions. Run dbt build, for example dbt build --select <function-name>+ to build the function and the models that call it.

OAuth sign-in fails with PORT_IN_USE or TIMED_OUT

  • PORT_IN_USE: Another process is using port 26642, which the adapter needs while you sign in. This might be another dbt command that’s waiting for you to sign in. Finish or stop that process, and run the command again.

  • TIMED_OUT: You didn’t finish signing in within five minutes. Run the command again. Sign in with a browser on the machine that runs dbt, because the sign-in redirects to 127.0.0.1 on that machine.

streaming_table restart fails the contract check

Starting with adapter version 0.5.0, dbt runs its contract check before the adapter resubmits a stopped or missing INSERT statement. If the model’s YAML file doesn’t list every column that the query returns, with its data type, the run fails. Add the missing columns, and run the model again. For more information, see Columns and the contract check.

Certificate errors behind a TLS inspection proxy

If your network inspects TLS traffic with a proxy, such as Zscaler, pip install or dbt debug can fail with CERTIFICATE_VERIFY_FAILED. On Python 3.13, the error can include Basic Constraints of CA cert not marked critical.

These errors have two causes:

  • The adapter verifies server certificates against the certifi CA bundle, not your operating system’s truststore. It doesn’t trust your proxy’s certificate authority (CA) unless you set the SSL_CERT_FILE or SSL_CERT_DIR environment variable, even when your browser works.

  • Python 3.13 and later check certificates strictly by default and reject CA certificates that don’t follow RFC 5280. Some proxy root CAs fail this check.

To fix the errors without turning off certificate verification:

  1. Get your proxy’s CA certificates in PEM format from your IT team. Include the proxy’s intermediate CA certificate. Python 3.13 accepts a trusted intermediate certificate without checking the root above it, which avoids the strict-mode failure.

  2. Create a bundle that contains the public CAs and your proxy’s CAs:

    mkdir -p ~/.config/certs
    cat "$(python3 -m pip._vendor.certifi)" proxy-ca.pem > ~/.config/certs/ca-bundle.pem
    
  3. Point Python at the bundle. Set the variable in your shell profile, because you need it both when you install the adapter and when you run dbt:

    export SSL_CERT_FILE=~/.config/certs/ca-bundle.pem
    

    For pip, also pass the bundle with --cert or set PIP_CERT to the same path.

Limitations

  • No dbt snapshots: Flink SQL doesn’t support the MERGE and UPDATE operations that dbt’s snapshot resource type needs to track slowly changing dimensions. This is unrelated to Flink SQL snapshot queries, which the adapter uses for table models and unit tests.

  • No incremental models: Use materialized_table instead.

  • No schema management: The adapter can’t create, rename, or drop Kafka clusters. See How dbt concepts map to Flink.

  • No renames: Flink SQL doesn’t support renaming tables. Renaming a model makes dbt create a new table under the new name. The old table, its topic, and any statement that writes to it keep running, so remove them yourself. Drop the old table with DROP MATERIALIZED TABLE or DROP TABLE. For a streaming_table model, also delete its old INSERT statement.

  • Not transactional: If a dbt run fails partway through, the models that already ran stay deployed.

  • No stored test failures: --store-failures and the store_failures configuration don’t work reliably. See Testing.

  • Functions need dbt build: dbt run doesn’t create or update functions. Flink UDF limits also apply, for example at most 10 UDFs in a statement and 100 artifacts in an environment.