ADB ClickHouse Connector configuration
To send data from ADB to ClickHouse via ADB ClickHouse Connector, you should first create the following objects on the ADB cluster side:
-
Server — encapsulates connection information that a foreign data wrapper uses to access an external data source.
-
User mapping — provides user authentication to an external data source.
-
Foreign table — a table in ADB that defines the remote data structure. A foreign table has no storage in ADB, but can be used in queries just like a normal table.
To see how to use the listed objects to send data from ADB to ADQM, refer to ADB ClickHouse Connector usage examples.
|
IMPORTANT
|
Server
To create a server, use the CREATE SERVER command. The basic command syntax is listed below:
CREATE SERVER <server_name> [ TYPE '<server_type>' ] [ VERSION '<server_version>' ]
FOREIGN DATA WRAPPER <fdw_name>
[ OPTIONS ( [ <option> '<value>' [, ... ]] ) ]
where:
-
<server_name>— a server name in ADB. Should be unique within the current ADB database. -
<server_type>— an optional server type. -
<server_version>— an optional server version. -
<fdw_name>— a foreign data wrapper name. You should use thetkh_fdwforeign data wrapper, which is automatically created after the connector installation (see step 8 in ADB ClickHouse Connector installation). -
<option>— server options that define the connection details. The options that are available for ADB ClickHouse Connector are listed in the Server options table. Note that these options can be defined both at the server level and at the foreign table level. Options marked as required should be specified at least in one definition (server or table). Table-level options take precedence. -
<value>— option values.
|
NOTE
|
| Name | Type | Description | Default | Required |
|---|---|---|---|---|
database |
TEXT |
A name of the ClickHouse database where the target table is located. Should match the following regular expression: |
— |
Yes |
hosts |
TEXT |
A list of ClickHouse hosts where the target table is located. A ClickHouse cluster does not have a single entry point (master node), so the requests can be sent to any host in the cluster. To reduce the load, data batches are sent to hosts from the connector according to the Validation rules for the |
— |
Yes |
lines_batch_size |
INT |
The maximum number of rows in one batch sent to ClickHouse by the connector.
Used for
Ignored if |
100000 |
No |
bytes_batch_size_mb |
INT |
The maximum size of one batch sent to ClickHouse by the connector (in MB).
Used for
Takes precedence over |
0 |
No |
send_compressed |
BOOL |
The flag that indicates whether to use compression on the connector side before sending data to ClickHouse. Possible values:
|
false |
No |
send_delay |
INT |
A delay between connector requests to ClickHouse (in milliseconds). Positive integers are allowed |
300 |
No |
insert_distributed_sync |
BOOL |
Enables or disables synchronous data load to distributed tables. Possible values:
|
true |
No |
distribution_type |
TEXT |
Defines the strategy of load distribution between ClickHouse hosts (see Possible values:
|
random |
No |
use_staging |
BOOL |
The flag that indicates whether to create staging tables in ClickHouse before inserting data into the target table.
Used to emulate transactions that are not present in ClickHouse.
If a failure occurs, the ADB transaction containing the Staging tables are supported only for the following ClickHouse engine families: MergeTree (including Replicated* engines) and Distributed. For other engines, an error will be returned, since not all engine types support partitioning in ClickHouse. Possible values:
|
— |
Yes |
staging_table_name_format |
TEXT |
Defines the staging table name format (see |
— |
Yes if |
clickhouse_properties |
TEXT |
A list of ClickHouse custom options in the For For |
— |
No |
fdw_startup_cost |
DOUBLE |
The cost estimate for obtaining the first tuple from the data source. Positive double values are allowed. Can be used only in |
1000.0 |
No |
fdw_tuple_cost |
DOUBLE |
The cost estimate for obtaining one tuple from the data source. Positive double values are allowed. Can be used only in |
0.01 |
No |
fdw_tuples_count |
DOUBLE |
The estimate for the number of all rows in the data source. Does not take into account the query selectivity, Positive double values >= Can be used only in |
100000.0 |
No |
client_version |
TEXT |
JDBC driver for the ClickHouse client to be used for
|
v2 |
No |
|
NOTE
The legacy clickhouse4j driver ( |
User mapping
To create a user mapping, use the CREATE USER MAPPING command. The basic command syntax is listed below:
CREATE USER MAPPING FOR { <username> | USER | CURRENT_USER | PUBLIC }
SERVER <server_name>
[ OPTIONS ( <option> '<value>' [, ... ] ) ]
where:
-
<username>— a user name in ADB. The following constants are allowed:-
USERorCURRENT_USER— the current user who established the ADB connection. -
PUBLIC— all present and future ADB users.
-
-
<server_name>— a server name. -
<option>— user mapping options, which typically include a user name and a password to connect to an external data source. The options that are available for ADB ClickHouse Connector are listed in the User mapping options table. -
<value>— option values.
|
NOTE
|
| Name | Type | Description | Default | Required |
|---|---|---|---|---|
clickhouse_username |
TEXT |
A user name in ClickHouse |
— |
Yes |
clickhouse_password |
TEXT |
A user password in ClickHouse. If there is no password (for example, in the test environment), an empty string is specified |
— |
Yes |
Foreign table
To create a foreign table, use the CREATE FOREIGN TABLE command. The basic command syntax is listed below:
CREATE FOREIGN TABLE [ IF NOT EXISTS ] <table_name> ( [
<column_name> <data_type> [ COLLATE <collation> ] [ <column_constraint> [ ... ] ]
[, ... ]
] )
SERVER <server_name>
[ OPTIONS ( <option> '<value>' [, ... ] ) ]
where:
-
<table_name>— a foreign table name in ADB. -
<column_name>— a column name. -
<data_type>— a column data type. -
<collation>— a column collation. -
<column_constraint>— a constraint defined at the column level. The name<constraint_name>is given optionally. The syntax:[ CONSTRAINT <constraint_name> ] { NOT NULL | NULL | DEFAULT <default_expr> }Possible constraints:
-
NOT NULL— specifies that the column is not allowed to contain null values. -
NULL— specifies that the column is allowed to contain null values. It is the default behavior (unlessNOT NULLis specified). -
DEFAULT— sets the default column value equal to<default_expr>.
-
-
<server_name>— a server name. -
<option>— foreign table options. For ADB ClickHouse Connector, all options defined at the server level can be overwritten at the foreign table level (partially or fully). When you specify an option for a server and a foreign table at the same time, the table level takes precedence. Additionally, at the foreign table level, two more options are available (see Foreign table options below). -
<value>— option values.
|
NOTE
|
| Name | Type | Description | Default | Required |
|---|---|---|---|---|
resource |
TEXT |
A table name in ClickHouse. If you need your own strategy for distributing data across hosts (sharding), you should insert data into the distributed ClickHouse table with the sharding key configured. To do this, specify the distributed table name in the The option value should match the following regular expression: |
— |
Yes |
cluster |
TEXT |
A cluster name in ClickHouse. For more information, see Typical cluster in the ADQM documentation. If you specify the The The maximum |
— |
No |
SSL options
|
NOTE
|
SSL parameters that the connector uses to connect to ClickHouse are configured via the clickhouse_properties option.
For example:
OPTIONS (
clickhouse_properties 'ssl=true;sslrootcert=/home/gpadmin/tkh_fdw/certs/ca-cert.pem'
)
For a more detailed example, refer to Usage examples.
This option can be used at the foreign server or foreign table level.
The following parameters are recognized inside the clickhouse_properties value (format: key=value;key=value;…).
| Name | Type | Description | Default |
|---|---|---|---|
ssl |
BOOL |
Enables SSL for connections to ClickHouse. Possible values:
|
false |
sslmode |
TEXT |
Defines the server certificate verification mode. Possible values:
For |
strict |
sslrootcert |
TEXT |
Absolute path to the root CA certificate file used to verify the server certificate. The file must be placed on the specified path on all ADB hosts (master and segment hosts) |
none |
SSL for ADB to PXF
To send data to ClickHouse, the connector establishes a connection between the ADB segment and PXF, which is HTTP by default.
If SSL is enabled for PXF in the PXF service parameters, you must instruct the connector to use HTTPS for the ADB to PXF connection (otherwise, an INSERT operation to ClickHouse will fail).
To do so, set the pxf_protocol option to 'https'.
It can be defined at the following levels (in ascending order of precedence): foreign table, foreign server, and foreign data wrapper.
For example, to set this option at the highest level, add it to the foreign data wrapper:
ALTER FOREIGN DATA WRAPPER tkh_fdw
OPTIONS (ADD pxf_protocol 'https');
To remove the option from the foreign data wrapper level:
ALTER FOREIGN DATA WRAPPER tkh_fdw
OPTIONS (DROP pxf_protocol);
Note that the option does not enable SSL for PXF → ClickHouse connections (this is configured in clickhouse_properties) and does not affect SELECT, which reads ClickHouse directly without involving PXF.
Parser options
The connector uses univocity-parsers to parse data before sending it to ClickHouse.
You can change the parser parameters using clickhouse_properties at the foreign server or foreign table level.
| Option in connector | Parser Javadoc | Default |
|---|---|---|
parser_auto_closing_enabled |
true |
|
parser_column_reordering_enabled |
true |
|
parser_header_extraction_enabled |
false |
|
parser_ignore_leading_whitespaces |
true |
|
parser_ignore_trailing_whitespaces |
true |
|
parser_input_buffer_size |
1048576 |
|
parser_input_reading_on_separate_thread |
true |
|
parser_line_separator_detection_enabled |
false |
|
parser_maximum_number_of_characters_per_column |
4096 |
|
parser_maximum_number_of_columns |
512 |
|
parser_null_value |
null |
|
parser_number_of_records_to_read |
-1 (no limit) |
|
parser_error_content_length |
-1 (no limit) |
|
parser_skip_bits_as_whitespace |
true |
|
parser_skip_empty_lines |
true |
|
parser_comment_character |
'\0' (disabled) |
|
parser_escape_character |
'\' |
|
parser_escaped_tab_char |
't' |
|
parser_line_separator |
system line separator |
For example, to override the default limit of 512 columns and insert rows that contain up to 1000 columns, create a foreign table with the parser_maximum_number_of_columns option:
CREATE FOREIGN TABLE wide_table_ft (
id int,
-- ... other columns --
column_999 text
)
SERVER clickhouse_server
OPTIONS (
resource 'wide_table',
clickhouse_properties 'parser_maximum_number_of_columns=1000'
);