Connecting external dictionaries in Managed Service for ClickHouse®
You can connect external dictionaries to your cluster and disconnect them. For more information about dictionaries, see this ClickHouse® article
Managed Service for ClickHouse® supports the following types of dictionary sources:
- ClickHouse®
- HTTP(s)
- Yandex StoreDoc
- MySQL®
- PostgreSQL
You can manage dictionaries either via SQL (recommended) or via Yandex Cloud cloud interfaces.
Note
The number of dictionaries you can connect to a cluster is limited. To learn more about limits, see Quotas and limits.
Getting a list of dictionaries
- In the management console
, go to the folder dashboard and select Managed Service for ClickHouse. - Click the name of your cluster and open the Dictionaries tab.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To get a list of external dictionaries in a ClickHouse® cluster:
-
See the description of the CLI command for getting detailed cluster information:
yc managed-clickhouse cluster get --help -
Run this command:
yc managed-clickhouse cluster get <cluster_name>
You can find the connected dictionaries in the dictionaries: section of the command output.
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Cluster.ListExternalDictionaries method and send the following request, e.g., via cURL
:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/externalDictionaries'You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure your request was successful.
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the ClusterService.ListExternalDictionaries call and send the following request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.ListExternalDictionariesYou can get the cluster ID with the list of clusters in the folder.
-
View the server response to make sure your request was successful.
Creating a dictionary
Note
- Dictionaries created through the Yandex Cloud interfaces are located in the ClickHouse® cluster's global namespace. When using SQL, you can only create a dictionary in the specified database and resides in that database's namespace.
- When creating an external dictionary via SQL, more sources and settings are available. For example, dictionaries with a Redis or Cassandra source can only be created via SQL.
Warning
If you create a dictionary in the console, you cannot manage it via SQL.
- In the management console
, go to the folder dashboard and select Managed Service for ClickHouse. - Click the name of your cluster and open the Dictionaries tab.
- In the top-right corner, click Create dictionary.
- Specify the dictionary settings.
- Click Save.
Warning
If you add a dictionary via the CLI, you cannot manage it via SQL.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To create an external dictionary in a ClickHouse® cluster:
-
See the description of the CLI command for adding dictionaries:
yc managed-clickhouse cluster add-external-dictionary --help -
Run the command to add a dictionary and specify the dictionary settings:
yc managed-clickhouse cluster add-external-dictionary \ --name=<ClickHouse®>_cluster_name \ --dict-name=<dictionary_name> \ ...
Warning
If you add a dictionary via the API, you cannot manage it via SQL.
To create an external dictionary in a ClickHouse® cluster:
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Cluster.CreateExternalDictionary method and send the following request, e.g., via cURL
:-
Create a file named
body.jsonand paste the following code into it:{ "externalDictionary": { "name": "<dictionary_name>", "structure": { "id": { "name": "<dictionary_key_column_name>" }, "key": { "attributes": [ <dictionary_data_column_array> ] }, "rangeMin": {<RANGE_HASHED_initial_column>}, "rangeMax": {<RANGE_HASHED_final_column>}, "attributes": [ <field_description_array> ] }, "layout": {<memory_layout>}, "fixedLifetime": "<fixed_update_interval>", "lifetimeRange": {<range_for_selecting_update_interval>}, "httpSource": {<HTTP(s)_source_settings>}, "mysqlSource": {<MySQL®>_source_settings}, "clickhouseSource": {<ClickHouse®>_source_settings}, "mongodbSource": {<Yandex_StoreDoc_source_settings>}, "postgresqlSource": {<PostgreSQL>_source_settings} } }Where:
-
externalDictionary.name: Dictionary name. -
externalDictionary.structure: Dictionary structure:id.name: Dictionary key column name.key.attributes: Array describing the dictionary's composite key.rangeMin: Description of the initial column required when using theRANGE_HASHEDmemory layout.rangeMax: Description of the final column required when using theRANGE_HASHEDmemory layout.attributes: Array describing the fields available for database queries.
Warning
The
structure.id.nameandstructure.key.attributesfields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
externalDictionary.layout: Memory layout for the dictionary. -
externalDictionary.fixedLifetime: Fixed interval between dictionary updates, in seconds. -
externalDictionary.lifetimeRange: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers.Warning
The
fixedLifetimeandlifetimeRangefields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
externalDictionary.***Source: Dictionary data source settings. Select one of the following sources and specify its settings:httpSource: HTTP(s) source.mysqlSource: MySQL® source.clickhouseSource: ClickHouse® source.mongodbSource: Yandex StoreDoc source.postgresqlSource: PostgreSQL source.
For a detailed description of the dictionary attributes and other settings, see below.
-
-
Run this request:
curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>:createExternalDictionary' \ --data '@body.json'You can get the cluster ID with the list of clusters in the folder.
-
-
View the server response to make sure your request was successful.
Warning
If you add a dictionary via the API, you cannot manage it via SQL.
To create an external dictionary in a ClickHouse® cluster:
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the ClusterService.CreateExternalDictionary call and send the following request, e.g., via gRPCurl
:-
Create a file named
body.jsonand paste the following code into it:{ "cluster_id": "<cluster_ID>", "external_dictionary": { "name": "<dictionary_name>", "structure": { "id": { "name": "<dictionary_key_column_name>" }, "key": { "attributes": [<dictionary_data_column_array>] }, "range_min": {<RANGE_HASHED_initial_column>}, "range_max": {<RANGE_HASHED_final_column>}, "attributes": [<field_description_array>] }, "layout": {<memory_layout>}, "fixed_lifetime": "<fixed_update_interval>", "lifetime_range": {<range_for_selecting_update_interval>}, "http_source": {<HTTP(s)_source_settings>}, "mysql_source": {<MySQL®>_source_settings}, "clickhouse_source": {<ClickHouse®>_source_settings}, "mongodb_source": {<Yandex_StoreDoc_source_settings>}, "postgresql_source": {<PostgreSQL>_source_settings} } }Where:
-
external_dictionary.name: Dictionary name. -
external_dictionary.structure: Dictionary structure.id.name: Dictionary key column name.key.attributes: Array describing columns with dictionary data.range_min: Description of the initial column required when using theRANGE_HASHEDmemory layout.range_max: Description of the final column required when using theRANGE_HASHEDmemory layout.attributes: Array describing the fields available for database queries.
Warning
The
structure.id.nameandstructure.key.attributesfields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
external_dictionary.layout: Memory layout for the dictionary. -
external_dictionary.fixed_lifetime: Fixed interval between dictionary updates, in seconds. -
external_dictionary.lifetime_range: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers.Warning
The
fixed_lifetimeandlifetime_rangefields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
external_dictionary.***_source: Dictionary data source settings. Select one of the following sources and specify its settings:http_source: HTTP(s) source.mysql_source: MySQL® source.clickhouse_source: ClickHouse® source.mongodb_source: Yandex StoreDoc source.postgresql_source: PostgreSQL source.
For a detailed description of the dictionary attributes and other settings, see below.
You can get the cluster ID with the list of clusters in the folder.
-
-
Run this query:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.CreateExternalDictionary \ < body.json
-
-
View the server response to make sure your request was successful.
Warning
If you add a dictionary via SQL, you cannot manage it via the console, CLI, or API.
-
Connect to the required database of the Managed Service for ClickHouse® cluster using
clickhouse-client. -
Run this DDL query
:CREATE DICTIONARY <dictionary_name>( <data_columns> ) PRIMARY KEY <name_of_column_with_keys> SOURCE(<source>(<source_configuration>)) LIFETIME(<update_interval>) LAYOUT(<memory_layout>());Where:
<dictionary_name>: Name of the new dictionary.<data_columns>: List of columns with dictionary entries and their type.PRIMARY KEY: Dictionary key column name.SOURCE: Source and its parameters.LIFETIME: Dictionary update interval.LAYOUT: Memory layout for the dictionary. The supported layout types include:flathashedcacherange_hashedcomplex_key_hashedcomplex_key_cache
For more information about the settings, see this ClickHouse® article
Updating a dictionary
- In the management console
, go to the folder dashboard and select Managed Service for ClickHouse. - Click the name of your cluster and open the Dictionaries tab.
- Click
next to the dictionary in question and select Edit. - Change the dictionary settings as needed.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To update an external dictionary in a ClickHouse® cluster, do the following:
-
View the description of the CLI command for updating dictionaries:
yc managed-clickhouse cluster update-external-dictionary --help -
Run the command to add a dictionary and specify the dictionary settings:
yc managed-clickhouse cluster update-external-dictionary \ --name <ClickHouse®_cluster_name> \ --dict-name <dictionary_name> \ ...
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Cluster.UpdateExternalDictionary method and send the following request, e.g., via cURL
:-
Create a file named
body.jsonand paste the following code into it:{ "externalDictionary": { "name": "<dictionary_name>", "structure": { "id": { "name": "<dictionary_key_column_name>" }, "key": { "attributes": [ <dictionary_data_column_array> ] }, "rangeMin": {<RANGE_HASHED_initial_column>}, "rangeMax": {<RANGE_HASHED_final_column>}, "attributes": [ <field_description_array> ] }, "layout": {<memory_layout>}, "fixedLifetime": "<fixed_update_interval>", "lifetimeRange": {<range_for_selecting_update_interval>}, "httpSource": {<HTTP(s)_source_settings>}, "mysqlSource": {<MySQL®>_source_settings}, "clickhouseSource": {<ClickHouse®>_source_settings}, "mongodbSource": {<Yandex_StoreDoc_source_settings>}, "postgresqlSource": {<PostgreSQL>_source_settings} }, "updateMask": "externalDictionary.<setting_1>,...,externalDictionary.<setting_N>" }Where:
-
updateMask: List of parameters to update as a single string, separated by commas.In this case, list all the dictionary settings to update.
-
externalDictionary.name: Dictionary name. -
externalDictionary.structure: Dictionary structure:id.name: Dictionary key column name.key.attributes: Array describing the dictionary's composite key.rangeMin: Description of the initial column required when using theRANGE_HASHEDmemory layout.rangeMax: Description of the final column required when using theRANGE_HASHEDmemory layout.attributes: Array describing the fields available for database queries.
Warning
The
structure.id.nameandstructure.key.attributesfields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
externalDictionary.layout: Memory layout for the dictionary. -
externalDictionary.fixedLifetime: Fixed interval between dictionary updates, in seconds. -
externalDictionary.lifetimeRange: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers.Warning
The
fixedLifetimeandlifetimeRangefields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
externalDictionary.***Source: Dictionary data source settings. Select one of the following sources and specify its settings:httpSource: HTTP(s) source.mysqlSource: MySQL® source.clickhouseSource: ClickHouse® source.mongodbSource: Yandex StoreDoc source.postgresqlSource: PostgreSQL source.
For a detailed description of the dictionary attributes and other settings, see below.
-
-
Run this request:
curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>:updateExternalDictionary' \ --data '@body.json'You can get the cluster ID with the list of clusters in the folder.
-
-
View the server response to make sure your request was successful.
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the ClusterService.UpdateExternalDictionary call and send the following request, e.g., via gRPCurl
:-
Create a file named
body.jsonand paste the following code into it:{ "cluster_id": "<cluster_ID>", "external_dictionary": { "name": "<dictionary_name>", "structure": { "id": { "name": "<dictionary_key_column_name>" }, "key": { "attributes": [<dictionary_data_column_array>] }, "range_min": {<RANGE_HASHED_initial_column>}, "range_max": {<RANGE_HASHED_final_column>}, "attributes": [<field_description_array>] }, "layout": {<memory_layout>}, "fixed_lifetime": "<fixed_update_interval>", "lifetime_range": {<range_for_selecting_update_interval>}, "http_source": {<HTTP(s)_source_settings>}, "mysql_source": {<MySQL®>_source_settings}, "clickhouse_source": {<ClickHouse®>_source_settings}, "mongodb_source": {<Yandex_StoreDoc_source_settings>}, "postgresql_source": {<PostgreSQL_source_settings>} }, "update_mask": "externalDictionary.<setting_1>,...,externalDictionary.<setting_N>" }Where:
-
update_mask: List of parameters to update as a single string, separated by commas.In this case, list all the dictionary settings to update.
-
external_dictionary.name: Dictionary name. -
external_dictionary.structure: Dictionary structure.id.name: Dictionary key column name.key.attributes: Array describing columns with dictionary data.range_min: Description of the initial column required when using theRANGE_HASHEDmemory layout.range_max: Description of the final column required when using theRANGE_HASHEDmemory layout.attributes: Array describing the fields available for database queries.
Warning
The
structure.id.nameandstructure.key.attributesfields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
external_dictionary.layout: Memory layout for the dictionary. -
external_dictionary.fixed_lifetime: Fixed interval between dictionary updates, in seconds. -
external_dictionary.lifetime_range: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers.Warning
The
fixed_lifetimeandlifetime_rangefields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
external_dictionary.***_source: Dictionary data source settings. Select one of the following sources and specify its settings:http_source: HTTP(s) source.mysql_source: MySQL® source.clickhouse_source: ClickHouse® source.mongodb_source: Yandex StoreDoc source.postgresql_source: PostgreSQL source.
For a detailed description of the dictionary attributes and other settings, see below.
You can get the cluster ID with the list of clusters in the folder.
-
-
Run this query:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.UpdateExternalDictionary \ < body.json
-
-
View the server response to make sure your request was successful.
Deleting a dictionary
- In the management console
, go to the folder dashboard and select Managed Service for ClickHouse. - Click the name of your cluster and open the Dictionaries tab.
- Click
next to the dictionary in question and select Delete dictionary.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To delete an external dictionary:
-
See the description of the CLI command for deleting a dictionary:
yc managed-clickhouse cluster remove-external-dictionary --help -
Run this command to delete a dictionary:
yc managed-clickhouse cluster remove-external-dictionary \ --name=<cluster_name> \ --dict-name=<dictionary_name>
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Cluster.DeleteExternalDictionary method and send the following request, e.g., via cURL
:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>:deleteExternalDictionary' \ --data '{ "externalDictionaryName": "<dictionary_name>" }'Where
externalDictionaryNameis the name of the dictionary you need to delete. You can request the dictionary name with a list of external dictionaries in the cluster.You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure your request was successful.
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the ClusterService.DeleteExternalDictionary call and send the following request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "external_dictionary_name": "<dictionary_name>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.DeleteExternalDictionaryWhere
external_dictionary_nameis the name of the dictionary you need to delete. You can request the dictionary name with a list of external dictionaries in the cluster.You can get the cluster ID with the list of clusters in the folder.
-
View the server response to make sure your request was successful.
Dictionary settings
Warning
Changing dictionary settings will restart ClickHouse® servers on the cluster hosts.
-
Name: Name of the new dictionary. Once a dictionary is created, you cannot change its name.
-
Source: Dictionary source settings. Select one of the listed sources and specify its settings:
ClickHouse®
-
Host: ClickHouse® host name. This is an optional setting.
The host must be in the same network as the ClickHouse® cluster.
-
Port: Port for connecting to the source. This is an optional parameter.
-
User: Source database username.
-
Password: Password to access the source database.
-
Database: Source database name.
-
Table: Source table name.
-
Selection condition: Condition for selecting rows to build a dictionary from. For example, the
id=10selection condition is the same as theWHERE id=10SQL clause. -
Check dictionary status (optional setting): SQL query to check for dictionary changes. ClickHouse® will update the dictionary only if the results of this query change.
Yandex StoreDoc
- Host: Yandex StoreDoc host name. The host must be in the same network as the ClickHouse® cluster.
- Port: Port for connecting to the source.
- User: Source database username.
- Password: Password to access the source database.
- Database: Source database name.
- Collection: Yandex StoreDoc collection name.
MySQL®
- Replicas: List of MySQL® replicas that will be used as the dictionary source.
For replicas, you can set general connection settings or set up a port, username, and password. - Port: Port for connecting to the source.
- User: Source database username.
- Password: Password to access the source database.
- Database: Source database name.
- Table: Source table name.
- Selection condition: Condition for selecting rows to build a dictionary from. For example, the
id=10selection condition is the same as theWHERE id=10SQL clause. - Check dictionary status (optional setting): SQL query to check for dictionary changes. ClickHouse® will update the dictionary only if the results of this query change.
PostgreSQL
- Hosts: Names of the PostgreSQL master host and its replicas that will be used as dictionary sources. The hosts must be in the same network as the ClickHouse® cluster.
- Port: Port for connecting to the source.
- User: Source database username.
- Password: Password to access the source database.
- Database: Source database name.
- Table: Source table name.
- Check dictionary status (optional setting): SQL query to check for dictionary changes. ClickHouse® will update the dictionary only if the results of this query change.
- SSL mode: Mode of secure SSL TCP/IP connection to the PostgreSQL database. For more information, see this PostgreSQL article
.
HTTP(s)
- URL: HTTP(s) source URL.
- File format: File format
for the HTTP(s) source. Read more about formats in this ClickHouse® article .
For more information about dictionary sources and their connection parameters, see this ClickHouse® article
. -
-
Memory storage: Memory layout for the dictionary. The supported layout types include
flat,hashed,complex_key_hashed,range_hashed,cache,complex_key_cache,sparse_hashed,complex_key_sparse_hashed,complex_key_range_hashed,direct,complex_key_direct, andip_trie. For more information about dictionary layouts, see the this ClickHouse® article . -
Cache size: Number of cache cells for the
cacheandcomplex_key_cachelayouts. For more information, see this ClickHouse® article . -
Allow read expired keys: Determines whether to allow reading expired keys. Used for the
cacheandcomplex_key_cachelayouts. For more information, see this ClickHouse® article . -
Settings of the update queue for cache update issues, if keys are not found in the dictionary. The settings are used for the
cacheandcomplex_key_cachelayouts.- Max update queue size: Maximum number of update issues per queue. The default value is
100000. - Update queue push timeout: Maximum update issue queuing timeout, in milliseconds. The default value is
10. - Query wait timeout: Maximum update issue completion timeout, in milliseconds. The default value is
60000(one minute). - Max threads for updates: Maximum number of threads for cache dictionary update. The default value is
4.
For more information, see this ClickHouse® article
. - Max update queue size: Maximum number of update issues per queue. The default value is
-
Flat array size settings. They are used for the
flatlayout.- Initial array size: Initial dictionary key size. The default value is
1024. - Max array size: Maximum dictionary key size. It determines the memory size used by the dictionary, this size being proportional to the largest key value. The default value is
500000.
For more information, see this ClickHouse® article
. - Initial array size: Initial dictionary key size. The default value is
-
Access to key from attributes: Gets the name of the composite key using the
dictGetStringfunction. This setting is used for theip_trielayout. With this setting enabled, you get higher load on RAM. -
Numeric key: Dictionary key column name. The key column must have the
UInt64data type. This setting is used for theflat,hashed,range_hashed,cache,sparse_hashed, anddirectlayouts: For more information, see this ClickHouse® article . -
Data column: Description of the dictionary's composite key. The key may consist of one or more elements. This setting is used for the
complex_key_*andip_trielayouts.- Name: Column name.
- Data type: Column data type.
- Default value (optional setting): Default value for an empty element. When loading a dictionary, all empty elements are replaced with this value. You cannot put
NULLin this field. - Expression (optional setting): Expression
ClickHouse® applies to the column value. - Hierarchical: Hierarchical support flag.
- Injective: Injective
id→attributemapping flag.
For more information about composite key settings, see this ClickHouse® article
. -
Memory storage: Dictionary update rate settings:
-
Period: Dictionary update frequency. Select the update interval type and settings:
-
fixed: Fixed period between dictionary updates:
- Period duration: Dictionary data update interval, in seconds.
-
variable: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers:
- Minimum: Minimum interval between dictionary updates, in seconds.
- Maximum: Maximum interval between dictionary updates, in seconds.
-
For more information about updating dictionaries, see this ClickHouse® article
. -
-
--dict-name: Name of the new dictionary. -
--***-source: Dictionary source settings. Select one of the listed sources and specify its settings:--clickhouse-source: ClickHouse® source-
host: Source host name. This is an optional parameter.The host must be in the same network as the ClickHouse® cluster.
-
port: Port for connecting to the source. This is an optional parameter. -
db: Source database name. -
user: Source database username. -
password: Password to access the source database. -
table: Source table name. -
where: Condition for selecting rows to build a dictionary from. For example, theid=10selection condition is the same as theWHERE id=10SQL clause. -
secure: Whether to use SSL to establish a connection.
--mongodb-source: Yandex StoreDoc sourcehost: Source host name. The host must be in the same network as the ClickHouse® cluster.port: Port for connecting to the source.db: Source database name.user: Source database username.password: Password to access the source database.connection: Source collection name.
--mysql-source: MySQL® sourcedb: Source database name.user: Source database username.password: Password to access the source database.table: Source table name.where: Condition for selecting rows to build a dictionary from. For example, theid=10selection condition is the same as theWHERE id=10SQL clause.share-connection: Determines whether to share the connection between multiple queries.close-connection: Determines whether to close the connection after each query.
--postgresql-source: PostgreSQL sourcetable: Source table name.ssl-mode: Mode of secure SSL TCP/IP connection to the PostgreSQL database. You can set it todisable,allow,prefer,verify-ca, orverify-full.
--http-source: HTTP(s) sourceurl: HTTP(s) source URL.format: File format for the HTTP(s) source. Read more about formats in this ClickHouse® article .
-
-
--http-header: Special HTTP header for the request to the HTTP(s) source:name: Header name.value: Header value.
-
--mysql-replica: Settings of MySQL® source replicas:host: Replica host name.priority: Replica priority. When attempting to connect, ClickHouse® follows the replica priority order. The lower the number, the higher the priority.port: Port for connecting to the replica.user: DB username.password: Password to access the database.
-
--mysql-invalidate-query: Query to check for MySQL® dictionary changes. ClickHouse® will update the dictionary only if the results of this query change. -
--postgresql-source-hosts: Names of the PostgreSQL master host and its replicas that will be used as PostgreSQL sources. The hosts must be in the same network as the ClickHouse® cluster. -
--postgresql-invalidate-query: Query to check for PostgreSQL dictionary changes. ClickHouse® will update the dictionary only if the results of this query change. -
--layout-type: Memory layout for the dictionary. The supported layout types includeflat,hashed,complex_key_hashed,range_hashed,cache,complex_key_cache,sparse_hashed,complex_key_sparse_hashed,complex_key_range_hashed,direct,complex_key_direct, andip_trie. For more information about dictionary layouts, see the this ClickHouse® article . -
--layout-size-in-cells: Number of cache cells for thecacheandcomplex_key_cachelayouts. For more information about cache, see this ClickHouse® article . -
--layout-allow-read-expired-keys: Determines whether to allow reading expired keys. This setting is used for thecacheandcomplex_key_cachelayouts. For more information, see this ClickHouse® article . -
Settings of the update queue for cache update issues, if keys are not found in the dictionary. The settings are used for the
cacheandcomplex_key_cachelayouts.--layout-max-update-queue-size: Maximum number of update issues per queue. The default value is100000.--layout-update-queue-push-timeout-milliseconds: Maximum update issue queuing timeout, in milliseconds. The default value is10.--layout-query-wait-timeout-milliseconds: Maximum update issue completion timeout, in milliseconds. The default value is60000(one minute).--layout-max-threads-for-updates: Maximum number of threads for a cache dictionary update. The default value is4.
For more information, see this ClickHouse® article
. -
Flat array size settings. They are used for the
flatlayout.--layout-initial-array-size: Initial dictionary key size. The default value is1024.--layout-max-array-size: Maximum dictionary key size. It determines the memory size used by the dictionary, this size being proportional to the largest key value. The default value is500000.
For more information, see this ClickHouse® article
. -
--layout-access-to-key-from-attributes: Gets the name of the composite key using thedictGetStringfunction. This setting is used for theip_trielayout. With this setting enabled, you get higher load on RAM. -
--structure-id: Dictionary key column name. The key column must have theUInt64data type. This setting is used for theflat,hashed,range_hashed,cache,sparse_hashed, anddirectlayouts: For more information about keys, see this ClickHouse® article . -
--structure-key: Description of the dictionary's composite key. The key may consist of one or more elements. This setting is used for thecomplex_key_*andip_trielayouts.name: Column name.type: Column data type.null-value: Default value for an empty element. When loading a dictionary, all empty elements are replaced with this value. You cannot putNULLin this field.expression: Expression ClickHouse® applies to the column value.hierarchical: Hierarchical support flag.injective: Injectiveid→attributemapping flag.
For more information about composite key parameters, see the ClickHouse® documentation
.Warning
The
--structure-idand--structure-keysettings are mutually exclusive, so using one means you cannot use the other. -
--structure-attribute: Description of the fields available for database queries:name: Column name.type: Column data type.null-value: Default value for an empty element. When loading a dictionary, all empty elements are replaced with this value. You cannot putNULLin this field.expression: Expression ClickHouse® applies to the column value.hierarchical: Hierarchical support flag.injective: Injectiveid→attributemapping flag.
-
--fixed-lifetime: Fixed interval between dictionary updates, in seconds. -
--lifetime-range: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers.min: Minimum interval between dictionary updates, in seconds.max: Maximum interval between dictionary updates, in seconds.
Warning
The
--fixed-lifetimeand--lifetime-rangesettings are mutually exclusive, so using one means you cannot use the other.
-
externalDictionary: New dictionary settings:-
name: Name of the new dictionary. -
***Source: Dictionary data source. Select one of the listed sources and specify its settings:clickhouseSource: ClickHouse® source-
db: Source database name. -
table: Source table name. -
where: Condition for selecting rows to build a dictionary from. For example, theid=10selection condition is the same as theWHERE id=10SQL clause. -
host: Source host name. This is an optional parameter.The host must be in the same network as the ClickHouse® cluster.
-
port: Port for connecting to the source. This is an optional parameter. -
user: Source database username. -
password: Password to access the source database. -
secure: Whether to use SSL to establish a connection.
mongodbSource: Yandex StoreDoc sourcedb: Source database name.host: Source host name. The host must be in the same network as the ClickHouse® cluster.port: Port for connecting to the source.user: Source database username.password: Password to access the source database.collection: Source collection name.
mysqlSource: MySQL® sourcedb: Source database name.table: Source table name.where: Condition for selecting rows to build a dictionary from. For example, theid=10selection condition is the same as theWHERE id=10SQL clause.user: Source database username.password: Password to access the source database.replicas: Source replica settings:host: Replica host name. The host must be in the same network as the ClickHouse® cluster.priority: Replica priority. When attempting to connect, ClickHouse® follows the replica priority order. The lower the number, the higher the priority.port: Port for connecting to the replica.user: DB username.password: Password to access the database.
invalidateQuery: Query to check for MySQL® dictionary changes. ClickHouse® will update the dictionary only if the results of this query change.shareConnection: Determines whether to share the connection between multiple queries.closeConnection: Determines whether to close the connection after each query.
postgresqlSource: PostgreSQL sourcedb: Source database name.table: Source table name.port: Port for connecting to the source.user: Source database username.password: Password to access the source database.sslMode: Mode of secure SSL TCP/IP connection to the PostgreSQL database. You can set it toDISABLE,ALLOW,PREFER,VERIFY_CA, orVERIFY_FULL.hosts: Names of the PostgreSQL master host and its replicas that will be used as dictionary sources. The hosts must be in the same network as the ClickHouse® cluster.invalidateQuery: Query to check for dictionary changes. ClickHouse® will update the dictionary only if the results of this query change.
httpSource: HTTP(s) sourceurl: HTTP(s) source URL.format: File format for the HTTP(s) source. Read more about formats in this ClickHouse® article .headers: Special HTTP headers for the request to the source:name: Header name.value: Header value.
-
-
layout.type: Memory layout for the dictionary. The supported layout types includeFLAT,HASHED,COMPLEX_KEY_HASHED,RANGE_HASHED,CACHE,COMPLEX_KEY_CACHE,SPARSE_HASHED,COMPLEX_KEY_SPARSE_HASHED,COMPLEX_KEY_RANGE_HASHED,DIRECT,COMPLEX_KEY_DIRECT, andIP_TRIE. For more information about dictionary layouts, see the this ClickHouse® article . -
layout.sizeInCells: Number of cache cells for theCACHEandCOMPLEX_KEY_CACHElayouts. For more information about cache, see this ClickHouse® article . -
layout.allowReadExpiredKeys: Determines whether to allow reading expired keys. This setting is used for theCACHEandCOMPLEX_KEY_CACHElayouts. For more information, see this ClickHouse® article . -
Settings of the update queue for cache update issues, if keys are not found in the dictionary. They are used for the
CACHEandCOMPLEX_KEY_CACHElayouts.layout.maxUpdateQueueSize: Maximum number of update issues per queue. The default value is100000.layout.updateQueuePushTimeoutMilliseconds: Maximum update issue queuing timeout, in milliseconds. The default value is10.layout.queryWaitTimeoutMilliseconds: Maximum update issue completion timeout, in milliseconds. The default value is60000(one minute).layout.maxThreadsForUpdates: Maximum number of threads for a cache dictionary update. The default value is4.
For more information, see this ClickHouse® article
. -
Flat array size settings. They are used for the
FLATlayout.layout.initialArraySize: Initial dictionary key size. The default value is1024.layout.maxArraySize: Maximum dictionary key size. It determines the memory size used by the dictionary, this size being proportional to the largest key value. The default value is500000.
For more information, see this ClickHouse® article
. -
layout.accessToKeyFromAttributes: Gets the name of the composite key using thedictGetStringfunction. This setting is used for theIP_TRIElayout. With this setting enabled, you get higher load on RAM. -
structure.id.name: Dictionary key column name. The key column must have theUInt64data type. This setting is used for theFLAT,HASHED,RANGE_HASHED,CACHE,SPARSE_HASHED, andDIRECTlayouts: For more information about keys, see the this ClickHouse® article . -
structure.key.attributes: Description of the dictionary's composite key. The key may consist of one or more elements. This setting is used for theCOMPLEX_KEY_*andIP_TRIElayouts.name: Column name.type: Column data type.nullValue: Default value for an empty element. When loading a dictionary, all empty elements are replaced with this value. You cannot putNULLin this field.expression: Expression ClickHouse® applies to the column value.hierarchical: Hierarchical support flag.injective: Injectiveid→attributemapping flag.
For more information about composite key settings, see this ClickHouse® article
.Warning
The
structure.id.nameandstructure.key.attributesfields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
structure.attributes: Description of the fields available for database queries:name: Column name.type: Column data type.nullValue: Default value for an empty element. When loading a dictionary, all empty elements are replaced with this value. You cannot putNULLin this field.expression: Expression ClickHouse® applies to the column value.hierarchical: Hierarchical support flag.injective: Injectiveid→attributemapping flag.
-
fixedLifetime: Fixed interval between dictionary updates, in seconds. -
lifetimeRange: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers. To specify the range boundaries, use these settings:min: Minimum interval between dictionary updates, in seconds.max: Maximum interval between dictionary updates, in seconds.
Warning
The
fixedLifetimeandlifetimeRangefields are mutually exclusive, i.e., the use of one makes it impossible to use the other.
-
-
external_dictionary: New dictionary settings:-
name: Name of the new dictionary. -
***_source: Dictionary data source. Select one of the listed sources and specify its settings:clickhouse_source: ClickHouse® source-
db: Source database name. -
table: Source table name. -
where: Condition for selecting rows to build a dictionary from. For example, theid=10selection condition is the same as theWHERE id=10SQL clause. -
host: Source host name. This is an optional parameter.The host must be in the same network as the ClickHouse® cluster.
-
port: Port for connecting to the source. This is an optional parameter. -
user: Source database username. -
password: Password to access the source database. -
secure: Whether to use SSL to establish a connection.
mongodb_source: Yandex StoreDoc sourcedb: Source database name.host: Source host name. The host must be in the same network as the ClickHouse® cluster.port: Port for connecting to the source.user: Source database username.password: Password to access the source database.collection: Source collection name.
mysql_source: MySQL® sourcedb: Source database name.table: Source table name.where: Condition for selecting rows to build a dictionary from. For example, theid=10selection condition is the same as theWHERE id=10SQL clause.user: Source database username.password: Password to access the source database.replicas: Source replica settings:host: Replica host name. The host must be in the same network as the ClickHouse® cluster.priority: Replica priority. When attempting to connect, ClickHouse® follows the replica priority order. The lower the number, the higher the priority.port: Port for connecting to the replica.user: DB username.password: Password to access the database.
invalidate_query: Query to check for MySQL® dictionary changes. ClickHouse® will update the dictionary only if the results of this query change.share_connection: Determines whether to share the connection between multiple queries.close_connection: Determines whether to close the connection after each query.
postgresql_source: PostgreSQL sourcedb: Source database name.table: Source table name.port: Port for connecting to the source.user: Source database username.password: Password to access the source database.ssl_mode: Mode of secure SSL TCP/IP connection to the PostgreSQL database. You can set it toDISABLE,ALLOW,PREFER,VERIFY_CA, orVERIFY_FULL.hosts: Names of the PostgreSQL master host and its replicas that will be used as dictionary sources. The hosts must be in the same network as the ClickHouse® cluster.invalidate_query: Query to check for dictionary changes. ClickHouse® will update the dictionary only if the results of this query change.
http_source: HTTP(s) sourceurl: HTTP(s) source URL.format: File format for the HTTP(s) source. Read more about formats in this ClickHouse® article .headers: Special HTTP headers for the request to the source:name: Header name.value: Header value.
-
-
layout.type: Memory layout for the dictionary. The supported layout types includeFLAT,HASHED,COMPLEX_KEY_HASHED,RANGE_HASHED,CACHE,COMPLEX_KEY_CACHE,SPARSE_HASHED,COMPLEX_KEY_SPARSE_HASHED,COMPLEX_KEY_RANGE_HASHED,DIRECT,COMPLEX_KEY_DIRECT, andIP_TRIE. For more information about dictionary layouts, see the this ClickHouse® article . -
layout.size_in_cells: Number of cache cells for theCACHEandCOMPLEX_KEY_CACHElayouts. For more information about cache, see this ClickHouse® article . -
layout.allow_read_expired_keys: Determines whether to allow reading expired keys. This setting is used for theCACHEandCOMPLEX_KEY_CACHElayouts. For more information, see this ClickHouse® article . -
Settings of the update queue for cache update issues, if keys are not found in the dictionary. The settings are used for the
CACHEandCOMPLEX_KEY_CACHElayouts.layout.max_update_queue_size: Maximum number of update issues per queue. The default value is100000.layout.update_queue_push_timeout_milliseconds: Maximum update issue queuing timeout, in milliseconds. The default value is10.layout.query_wait_timeout_milliseconds: Maximum update issue completion timeout, in milliseconds. The default value is60000(one minute).layout.max_threads_for_updates: Maximum number of threads for a cache dictionary update. The default value is4.
For more information, see this ClickHouse® article
. -
Flat array size settings. They are used for the
FLATlayout.layout.initial_array_size: Initial dictionary key size. The default value is1024.layout.max_array_size: Maximum dictionary key size. It determines the memory size used by the dictionary, this size being proportional to the largest key value. The default value is500000.
For more information, see this ClickHouse® article
. -
layout.access_to_key_from_attributes: Gets the name of the composite key using thedictGetStringfunction. This setting is used for theIP_TRIElayout. With this setting enabled, you get higher load on RAM. -
structure.id.name: Dictionary key column name. The key column must have theUInt64data type. This setting is used for theFLAT,HASHED,RANGE_HASHED,CACHE,SPARSE_HASHED, andDIRECTlayouts: For more information about keys, see the this ClickHouse® article . -
structure.key.attributes: Description of the dictionary's composite key. The key may consist of one or more elements. This setting is used for theCOMPLEX_KEY_*andIP_TRIElayouts.name: Column name.type: Column data type.null_value: Default value for an empty element. When loading a dictionary, all empty elements are replaced with this value. You cannot putNULLin this field.expression: Expression ClickHouse® applies to the column value.hierarchical: Hierarchical support flag.injective: Injectiveid→attributemapping flag.
For more information about composite key settings, see this ClickHouse® article
.Warning
The
structure.id.nameandstructure.key.attributesfields are mutually exclusive, i.e., the use of one makes it impossible to use the other. -
structure.attributes: Description of the fields available for database queries:name: Column name.type: Column data type.null_value: Default value for an empty element. When loading a dictionary, all empty elements are replaced with this value. You cannot putNULLin this field.expression: Expression ClickHouse® applies to the column value.hierarchical: Hierarchical support flag.injective: Injectiveid→attributemapping flag.
-
fixed_lifetime: Fixed interval between dictionary updates, in seconds. -
lifetime_range: Time range for ClickHouse® to randomly select the time for update. This helps distribute the dictionary source load when updating across many servers. To specify the range boundaries, use these settings:min: Minimum interval between dictionary updates, in seconds.max: Maximum interval between dictionary updates, in seconds.
Warning
The
fixed_lifetimeandlifetime_rangefields are mutually exclusive, i.e., the use of one makes it impossible to use the other.
-
Examples
Let's assume there is a ClickHouse® cluster named mych with the cat0adul1fj0******** ID, and you need to connect a dictionary with the following test settings to it:
- Dictionary name:
mychdict. - Key column name:
id. - Fields available for database queries:
id,UInt64type.field1,Stringtype.
- Fixed interval between dictionary updates: 300 seconds.
- Memory layout for the dictionary:
cachewith cache size of 1,024 cells. - PostgreSQL source:
- Database:
db1. - Table name:
table1. - Port for connection:
6432. - DB username:
user1. - DB access password:
user1user1. - Mode of secure SSL TCP/IP connection to the database:
verify-full. - Master host's special FQDN:
c-c9qash3nb1v9********.rw.mdb.yandexcloud.net.
- Database:
Run this command:
yc managed-clickhouse cluster add-external-dictionary \
--name=mych \
--dict-name=mychdict \
--structure-id=id \
--structure-attribute name=id,`
`type=UInt64,`
`name=field1,`
`type=String \
--fixed-lifetime=300 \
--layout-type=cache \
--layout-size-in-cells 1024 \
--postgresql-source db=db1,`
`table=table1,`
`port=6432,`
`user=user1,`
`password=user1user1,`
`ssl-mode=verify-full \
--postgresql-source-hosts=c-c9qash3nb1v9********.rw.mdb.yandexcloud.net
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Create a file named
body.jsonand paste the following code into it:{ "externalDictionary": { "name": "mychdict", "structure": { "id": { "name": "id" }, "attributes": [ { "name": "id", "type": "UInt64" }, { "name": "field1", "type": "String" } ] }, "layout": { "type": "CACHE", "sizeInCells": "1024" }, "fixedLifetime": "300", "postgresqlSource": { "db": "db1", "table": "table1", "port": "5432", "user": "user1", "password": "user1user1", "sslMode": "VERIFY_FULL", "hosts": ["c-c9qash3nb1v9********.rw.mdb.yandexcloud.net"] } } } -
Run this request using cURL
:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/cat0adul1fj0********:createExternalDictionary' \ --data '@body.json'
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Create a file named
body.jsonand paste the following code into it:{ "cluster_id": "cat0adul1fj0********", "external_dictionary": { "name": "mychdict", "structure": { "id": { "name": "id" }, "attributes": [ { "name": "id", "type": "UInt64" }, { "name": "field1", "type": "String" } ] }, "layout": { "type": "CACHE", "size_in_cells": "1024" }, "fixed_lifetime": "300", "postgresql_source": { "db": "db1", "table": "table1", "port": "5432", "user": "user1", "password": "user1user1", "ssl_mode": "VERIFY_FULL", "hosts": ["c-c9qash3nb1v9********.rw.mdb.yandexcloud.net"] } } } -
Run this request using gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.CreateExternalDictionary \ < body.json
-
Connect to the required database of the Managed Service for ClickHouse® cluster using
clickhouse-client. -
Run this DDL query
:CREATE DICTIONARY mychdict( `id` UInt64, `field1` String ) PRIMARY KEY id SOURCE(POSTGRESQL( port 5432 host 'c-c9qash3nb1v9********.rw.mdb.yandexcloud.net' user 'user1' password 'user1user1' db 'db1' table 'table1' )) LIFETIME(300) LAYOUT(CASHE(SIZE_IN_CELLS 1024));
ClickHouse® is a registered trademark of ClickHouse, Inc