Skip to main content

CDC_STREAM

Description​

Warning:

Continuous Load is experimental. Confirm availability and required connector provisioning for your warehouse with VeloDB Cloud support before using this reference. For established loading workflows, see Load Overview.

The CDC Stream table-valued-function (TVF) enables users to read change data from relational databases (such as MySQL, PostgreSQL) via CDC. By integrating Flink CDC reading capabilities, it supports full and incremental data synchronization.

It is typically used with CREATE JOB ON STREAMING to achieve continuous single-table data synchronization with SQL mapping. For detailed usage, see MySQL CDC with SQL Mapping and PostgreSQL CDC with SQL Mapping.

Syntax​

cdc_stream(
"type" = "<source_type>",
"jdbc_url" = "<jdbc_url>",
"driver_url" = "<driver_url>",
"driver_class" = "<driver_class>",
"user" = "<user>",
"password" = "<password>",
"database" = "<database>",
"table" = "<table>"
[, "<optional_property_key>" = "<optional_property_value>" [, ...] ]
)

Required parameters​

ParameterDescription
typeData source type, currently supports mysql and postgres
jdbc_urlJDBC connection string, e.g. jdbc:mysql://<mysql-host>:<mysql-port> or jdbc:postgresql://<postgres-host>:<postgres-port>/postgres
driver_urlJDBC driver jar path
driver_classJDBC driver class name. com.mysql.cj.jdbc.Driver for MySQL, org.postgresql.Driver for PostgreSQL
userDatabase username
passwordDatabase password
databaseDatabase name
tableTable name to synchronize

Optional parameters​

ParameterDefaultDescription
schema-Schema name, required for PostgreSQL
offsetlatestlatest: incremental only; initial: full + incremental; also supports snapshot, earliest (MySQL only), or a JSON binlog/LSN position
snapshot_split_sizeUpstream reference: 40960Split size in rows for full synchronization. The upstream Apache Doris reference reports 8096 before 4.1.4. Confirm the default for the CDC connector deployed with your warehouse before relying on either value.
snapshot_parallelism1Parallelism during full sync phase, i.e., max splits per task

Notes​

  1. CDC Stream TVF is typically used with CREATE JOB ON STREAMING and is not recommended for use in regular queries.
  2. When using the MySQL type, Binlog must be enabled on MySQL (binlog_format=ROW).
  3. When using the PostgreSQL type, logical replication must be enabled (wal_level=logical).
  4. Check the source connector and streaming-job transaction requirements before relying on exactly-once processing. Provider failures and source retention can affect recovery.

Starting with Core 26.1.3, CDC operations run with the identity of the user who created the streaming job. Check that this user has the required target-table privileges. The upstream reference also describes a later change that skips ordinary task retries for CDC-backed Streaming INSERT tasks; this retry change is not established for Core 26.1.3. Inspect the job state and task errors before choosing recovery steps. See Continuous Load Identity and Failure Handling.

Examples​

  • Continuously synchronize a single table from MySQL

    CREATE JOB mysql_cdc_job
    ON STREAMING
    DO
    INSERT INTO db1.target_table
    SELECT * FROM cdc_stream(
    "type" = "mysql",
    "jdbc_url" = "jdbc:mysql://<mysql-host>:<mysql-port>",
    "driver_url" = "mysql-connector-java-8.0.25.jar",
    "driver_class" = "com.mysql.cj.jdbc.Driver",
    "user" = "<source-user>",
    "password" = "<source-password>",
    "database" = "source_db",
    "table" = "source_table",
    "offset" = "initial"
    )
  • Continuously synchronize a single table from PostgreSQL

    CREATE JOB pg_cdc_job
    ON STREAMING
    DO
    INSERT INTO db1.target_table
    SELECT * FROM cdc_stream(
    "type" = "postgres",
    "jdbc_url" = "jdbc:postgresql://<postgres-host>:<postgres-port>/postgres",
    "driver_url" = "postgresql-42.5.1.jar",
    "driver_class" = "org.postgresql.Driver",
    "user" = "<source-user>",
    "password" = "<source-password>",
    "database" = "postgres",
    "schema" = "public",
    "table" = "source_table",
    "offset" = "initial"
    )
  • Incremental sync only (skip full snapshot)

    CREATE JOB mysql_incremental_job
    ON STREAMING
    DO
    INSERT INTO db1.target_table
    SELECT * FROM cdc_stream(
    "type" = "mysql",
    "jdbc_url" = "jdbc:mysql://<mysql-host>:<mysql-port>",
    "driver_url" = "mysql-connector-java-8.0.25.jar",
    "driver_class" = "com.mysql.cj.jdbc.Driver",
    "user" = "<source-user>",
    "password" = "<source-password>",
    "database" = "source_db",
    "table" = "source_table",
    "offset" = "latest"
    )
  • Column mapping and data transformation

    CREATE JOB mysql_cdc_transform_job
    ON STREAMING
    DO
    INSERT INTO db1.target_table (id, name, age)
    SELECT id, name, cast(age as INT) as age
    FROM cdc_stream(
    "type" = "mysql",
    "jdbc_url" = "jdbc:mysql://<mysql-host>:<mysql-port>",
    "driver_url" = "mysql-connector-java-8.0.25.jar",
    "driver_class" = "com.mysql.cj.jdbc.Driver",
    "user" = "<source-user>",
    "password" = "<source-password>",
    "database" = "source_db",
    "table" = "source_table",
    "offset" = "initial"
    )