Setup details
User and role management
Consider not using thedefault user; instead, create a dedicated one to use it with this Fivetran
destination only. The following commands, executed with the default user, will create a new fivetran_user with the
required privileges.
fivetran_user.
For example, by executing the following statement, we restrict access to the default database:
Advanced configuration
The ClickHouse Cloud destination supports an optional JSON configuration file for advanced use cases. This file allows you to fine-tune destination behavior by overriding the default settings that control batch sizes, parallelism, connection pools, and request timeouts.This configuration is entirely optional. If no file is uploaded, the destination uses sensible defaults that work well for most use cases.
All fields are optional. If a field is not specified, the default value is used.
If a value is outside the allowed range, the destination will report an error during sync.
Unknown fields are silently ignored (a warning is logged) and do not cause errors, which allows forward compatibility when new settings are added.
Example:
Type transformation mapping
The Fivetran ClickHouse destination maps Fivetran data types to ClickHouse types as follows:* BINARY, XML, LOCALTIME, and JSON are stored as String because ClickHouse’s
String type can represent an arbitrary set of bytes. The destination adds a column comment to indicate the original data type. The ClickHouse JSON data type is not used as it was marked as obsolete and never recommended for production usage.
** NOTE: Issue to track the support for LOCALTIME type: clickhouse-fivetran-destination #15.Date and time value ranges
Fivetran sources can send date and time values in the range 0001-01-01, 9999-12-31. ClickHouse Cloud date types have narrower ranges, so values outside the supported range are silently clamped to the nearest boundary:- The INSTANT upper bound is 2262-04-11 23:47:16 because DateTime64(9) stores nanoseconds since epoch as int64, and 2^63 - 1 nanoseconds corresponds to this date. ClickHouse itself supports DateTime64 with precision <= 9 up to 2299-12-31 23:59:59.
- The LOCALDATETIME upper bound is also limited to 2262-04-11 23:47:16 due to a known bug in the Go ClickHouse driver, where
time.Time.UnixNano()is called for all DateTime64 precisions before scaling, causing int64 overflow for dates beyond 2262 even at precision 0.
Destination tables
The ClickHouse Cloud destination uses Replacing engine type of SharedMergeTree family (specifically,SharedReplacingMergeTree), versioned by the _fivetran_synced column.
Every column except primary (ordering) keys and Fivetran metadata columns is created
as Nullable(T), where T is a
ClickHouse Cloud type based on the data types mapping.
The table structure varies depending on the Fivetran
sync mode
configured for the connector: soft delete (default) or history mode (SCD Type 2).
Soft delete mode
In soft delete mode, every destination table includes the following metadata columns:Single primary key in the source table
For example, source tableusers has a primary key column id (INT) and a regular column name (STRING).
The destination table will be defined as follows:
id column is chosen as a table sorting key.
Multiple primary keys in the source table
If the source table has multiple primary keys, they are used in order of their appearance in the Fivetran source table definition. For example, there is a source tableitems with primary key columns id (INT) and name (STRING), plus an
additional regular column description (STRING). The destination table will be defined as follows:
id and name columns are chosen as table sorting keys.
No primary keys in the source table
If the source table has no primary keys, a unique identifier will be added by Fivetran as a_fivetran_id column.
Consider an events table that only has the event (STRING) and timestamp (LOCALDATETIME) columns in the source.
The destination table in that case is as follows:
_fivetran_id is unique and there are no other primary key options, it is used as a table sorting key.
History mode (SCD Type 2)
When history mode is enabled, the destination preserves every version of each record rather than overwriting previous values. This implements Slowly Changing Dimension Type 2 (SCD Type 2), maintaining a complete audit trail of all changes. In history mode, every destination table includes the following metadata columns:
The
_fivetran_start column is always included in the ORDER BY clause as the last element of the compound sorting key.
This allows multiple versions of the same record (with different start times) to coexist in the table.
When a record is updated:
- The previous version’s
_fivetran_endis set to the new version’s_fivetran_startminus one nanosecond, and_fivetran_activeis set tofalse. - The new version is inserted with
_fivetran_activeset totrueand_fivetran_endset to2262-04-11 23:47:16.000000000(the maximumDateTime64(9)value).
Single primary key in the source table
For example, source tableusers has a primary key column id (INT) and regular columns name (STRING) and status (STRING).
The destination table in history mode will be defined as follows:
id and _fivetran_start form the compound sorting key.
After a few syncs, the table might contain the following data:
Record
id=1 has two versions: the original (name 1, inactive) and the updated one (name 11, active).
Record id=2 has only one version, which is currently active.
Multiple primary keys in the source table
If the source table has multiple primary keys, they are all included in theORDER BY together with _fivetran_start as the last element.
For example, there is a source table items with primary key columns id (INT) and name (STRING), plus an
additional regular column description (STRING). The destination table in history mode will be defined as follows:
id, name, and _fivetran_start form the compound sorting key.
No primary keys in the source table
If the source table has no primary keys, a unique identifier will be added by Fivetran as a_fivetran_id column,
and _fivetran_start is appended to the sorting key.
Consider an events table that only has the event (STRING) and timestamp (LOCALDATETIME) columns in the source.
The destination table in history mode is as follows:
_fivetran_id and _fivetran_start form the compound sorting key.
Selecting the latest version of the data without duplicates
SharedReplacingMergeTree performs background data deduplication
only during merges at an unknown time.
However, selecting the latest version of the data without duplicates ad-hoc is possible with the FINAL keyword:
Retries on network failures
The ClickHouse Cloud destination retries transient network errors using the exponential backoff algorithm. This is safe even when the destination inserts the data, as any potential duplicates are handled by theSharedReplacingMergeTree table engine.