Working with Managed Service for ClickHouse® databases
This section provides the basic information about working with Managed Service for ClickHouse®.
To work with a Managed Service for ClickHouse® database, follow these steps:
- Create a connection containing your database connection credentials.
- Run a query to the database.
Example of a query for reading data from Managed Service for ClickHouse®:
SELECT * FROM clickhouse_mdb_connection.my_table
Where:
clickhouse_mdb_connection
: Name of the DB connection you created.my_table
: Name of the table in the database.
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. -
In the list of services, select Yandex Query.
-
In the left-hand panel, go to the Connections tab.
-
Click
Create new. -
Specify the connection parameters:
-
Under General parameters:
- Name: Name of the connection to Managed Service for ClickHouse®.
- 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 with the
managed-clickhouse.viewer
role, and use it to connect toManaged Service for ClickHouse®
clusters.To use a service account, the
iam.serviceAccounts.user
role is required. -
Database: Select the database you will use when working with the ClickHouse® cluster.
-
Login: Username to use when connecting to ClickHouse® databases.
-
Password: User password to use when connecting to ClickHouse® databases.
-
-
-
Click Create.
You need a service account to detect Managed Service for ClickHouse® cluster connection points inside Yandex Cloud. You need a separate login/password pair to access data.
Warning
First, allow network access from Yandex Query to Managed Service for ClickHouse® clusters. To do this, enable Yandex Query access in the settings of the database to which you are connecting.
Query syntax
Here is the SQL query format used to access ClickHouse®:
SELECT * FROM <connection>.<table_name>
Where:
<connection>
: Name of the DB connection you created.<table_name>
: Name of the table in the database.
Limitations
Some limitations apply when working with ClickHouse® clusters.
Limitations:
-
External sources are only available for data reading through
SELECT
requests. Yandex Query does not currently support requests that modify tables in external sources. - YQ uses the Yandex Managed Service for YDB type system
. However, the ranges of acceptable values for types used in YDB for date and time operations (Date
,Datetime
, andTimestamp
) are often not wide enough to cover the values of the relevant ClickHouse® types (Date
,Date32
,Datetime
, andDatetime64
).
Therefore, YQ returns date and time values read from ClickHouse® as plain strings (typeUtf8
for regular columns orOptional<Utf8>
for nullable columns) in ISO-8601 format.
Filter pushdown
Yandex Query can transfer processing of request parts to the data source system. This means that filter expressions are provided through Yandex Query directly to the database for processing; these are typically the query conditions specified in WHERE
. This kind of processing is called filter pushdown
.
Filter pushdown is possible when using:
Description | Example |
---|---|
Filters like IS NULL /IS NOT NULL |
WHERE column1 IS NULL or WHERE column1 IS NOT NULL |
Logical conditions OR , NOT , or AND |
WHERE column IS NULL OR column2 is NOT NULL |
Conditions = , <> , < , <= , > , >= for comparison with other columns or constants |
WHERE column3 > column4 OR column5 <= 10 |
Supported data types for filter pushdown:
Data type Yandex Query |
---|
Bool |
Int8 |
Uint8 |
Int16 |
Uint16 |
Int32 |
Uint32 |
Int64 |
Uint64 |
Float |
Double |
Supported data types
In ClickHouse®, columns cannot physically contain the NULL
value by default; however, the user can create a table with columns of optional or nullable
The tables below show how ClickHouse® and Yandex Query types map. All other data types except those listed are not supported.
Primitive data types
Data type ClickHouse® | Data type Yandex Query | Notes |
---|---|---|
Bool |
Bool |
|
Int8 |
Int8 |
|
UInt8 |
Uint8 |
|
Int16 |
Int16 |
|
UInt16 |
Uint16 |
|
Int32 |
Int32 |
|
UInt32 |
Uint32 |
|
Int64 |
Int64 |
|
UInt64 |
Uint64 |
|
Float32 |
Float |
|
Float64 |
Double |
|
Date |
Utf8 |
|
Date32 |
Utf8 |
|
DateTime |
Utf8 |
|
DateTime64 |
Utf8 |
|
String |
String |
|
FixedString |
String |
Null FixedString bytes are transferred to String without changes. |
Optional data types
Data type ClickHouse® | Data type Yandex Query | Notes |
---|---|---|
Nullable(Bool) |
Optional<Bool> |
|
Nullable(Int8) |
Optional<Int8> |
|
Nullable(UInt8) |
Optional<Uint8> |
|
Nullable(Int16) |
Optional<Int16> |
|
Nullable(UInt16) |
Optional<Uint16> |
|
Nullable(Int32) |
Optional<Int32> |
|
Nullable(UInt32) |
Optional<Uint32> |
|
Nullable(Int64) |
Optional<Int64> |
|
Nullable(UInt64) |
Optional<Uint64> |
|
Nullable(Float32) |
Optional<Float> |
|
Nullable(Float64) |
Optional<Double> |
|
Nullable(Date) |
Optional<Utf8> |
|
Nullable(Date32) |
Optional<Utf8> |
|
Nullable(DateTime) |
Optional<Utf8> |
|
Nullable(DateTime64) |
Optional<Utf8> |
|
Nullable(String) |
Optional<String> |
|
Nullable(FixedString) |
Optional<String> |
Null FixedString bytes are transferred to String without changes. |
ClickHouse® is a registered trademark of ClickHouse, Inc