Working with Managed Service for ClickHouse® databases
This section covers the basics of working with Managed Service for ClickHouse®.
To start working with a Managed Service for ClickHouse® database, follow these steps:
- Create a connection containing your database access credentials.
- Run a query to the database.
Query example for reading data from Managed Service for ClickHouse®:
SELECT * FROM clickhouse_mdb_connection.my_table
Where:
clickhouse_mdb_connection: Your database connection name.my_table: Database table name.
Setting up a connection
To create a connection to Managed Service for ClickHouse®:
-
In the management console
, select the folder where you want to create a connection. -
Navigate
to Yandex Query. -
In the left-hand panel, select Connections.
-
Click
Create new. -
Specify the connection settings:
-
Under General parameters:
- Name: Managed Service for ClickHouse® connection name.
- Type:
Managed Service for ClickHouse.
-
Under Connection type parameters:
-
Cluster: Select an existing Managed Service for ClickHouse® cluster or create a new one.
-
Service account: Select an existing Managed Service for ClickHouse® service account or create a new one. Assign it the
managed-clickhouse.viewerrole allowing it to connect to Managed Service for ClickHouse® clusters.To use the service account on your behalf, you need the
iam.serviceAccounts.userrole. -
Database: Select the database you will use to work with the ClickHouse® cluster.
-
Login: Username you will use to connect to ClickHouse® databases.
-
Password: Password you will use to connect to ClickHouse® databases.
-
-
-
Click Create.
You need a service account to detect Managed Service for ClickHouse® cluster connection endpoints inside Yandex Cloud. To work with data, set a username and password separately.
Warning
Allow network access from Yandex Query to Managed Service for ClickHouse® clusters. Do it by enabling Yandex Query access in the target database settings.
Query syntax
ClickHouse® uses the following SQL syntax:
SELECT * FROM <connection>.<table_name>
Where:
<connection>: Your database connection name.<table_name>: Database table name.
Limits
ClickHouse® clusters are subject to the following restrictions:
-
External sources are available for read-only access via
SELECTqueries. Yandex Query does not currently support data-modifying queries against external sources. -
YQ uses the Yandex Managed Service for YDB type system
. The available value ranges of YDB date and time types (Date,Datetime,Timestamp) do not allow storing all values of relevant ClickHouse® types (Date,Date32,DateTime,DateTime64).Therefore, YQ returns the date and time values read from ClickHouse® as strings in ISO-8601
format. Regular columns use typeUtf8; nullable columns useOptional<Utf8>.
Filter pushdown
Yandex Query can push parts of query processing down to the source data system by sending filter expressions, e.g., WHERE conditions, directly to the database. This approach is known as filter pushdown.
Filter pushdown is possible when using:
| Description | Example |
|---|---|
NULL check |
WHERE column1 IS NULL or WHERE column1 IS NOT NULL |
Logical operators AND, OR, NOT, and parentheses to control operator precedence |
WHERE column1 IS NULL OR (column2 IS NOT NULL AND column3 > 10). |
Comparison operators =, ==, !=, <>, >, <, >=, and <= that compare a column with other columns or constants |
WHERE column1 > column2 OR column3 <= 10, WHERE column1 + column2 > 10, WHERE column1 = (10 + 10) |
Other filter types do not support source pushdown: the external table rows are filtered on the federated Yandex Query side, i.e., Yandex Query will perform a full scan of the external table when processing the query.
Supported data types for filter pushdown:
|
Yandex Query data type |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Supported data types
By default, ClickHouse® columns cannot contain NULL. However, you can create a table with columns of optional (nullable)
The tables below show type mapping between ClickHouse® and Yandex Query. Only the listed types are supported.
Primitive data types
|
ClickHouse® data type |
Yandex Query data type |
Notes |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Null |
Optional data types
|
ClickHouse® data type |
Yandex Query data type |
Notes |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Null |
ClickHouse® is a registered trademark of ClickHouse, Inc