Working with Managed Service for YDB databases
This section provides the basic information about working with Managed Service for YDB.
To work with a Managed Service for YDB database from Yandex Query, 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 YDB:
SELECT * FROM ydb_connection.my_table
Where:
ydb_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 YDB:
-
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 YDB.
- Type:
Managed Service for YDB.
-
Under Connection type parameters:
-
Cluster: Select an existing Managed Service for YDB database or create a new one.
-
Service account: Select the Managed Service for YDB service account to use for connecting to
Managed Service for YDBclusters and database authentication. If you do not have a service account, create one and assign theydb.viewerrole to it.To use a service account, the
iam.serviceAccounts.userrole is required.
-
-
-
Click Create.
Query syntax
Here is the SQL query format used to access Managed Service for YDB:
SELECT * FROM <connection>.<table_name>
Where:
<connection>: Name of the DB connection you created.<table_name>: Name of the table in the database.
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.
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 | I/O |
|---|---|---|
Filters like IS NULL/IS NOT NULL |
WHERE column1 IS NULL or WHERE column1 IS NOT NULL |
|
The OR, NOT, or AND logical conditions or parentheses to prioritize calculations |
WHERE column1 IS NULL OR (column2 IS NOT NULL AND column3 > 10). |
|
Comparison operators (=, ==, !=, <>, >, <, >=, or <=) against other columns or constants |
WHERE column1 > column2 OR column3 <= 10. |
|
The LIKE string pattern matching operator |
WHERE column1 LIKE '_abc%' |
Currently, pushdown only supports simple patterns based on prefixes ('abc_' or 'abc%'), suffixes ('_abc' or '%abc'), or searching for a substring in a string ('_abc_', '%abc%', '_abc%', or '%abc_'). Use REGEXP to push down more complex patterns. |
The REGEXP string pattern matching operator |
WHERE column1 REGEXP '.*abc.*' |
Other filter types do not support any pushdown on the source side: the external table rows will be 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:
| Data type Yandex Query |
|---|
Bool |
Int8 |
Uint8 |
Int16 |
Uint16 |
Int32 |
Uint32 |
Int64 |
Uint64 |
Float |
Double |
String |
Utf8 |
Supported data types
The tables below show how Managed Service for YDB and Yandex Query data types map. Data types not listed in the tables are not supported.
Primitive data types
| Data type Managed Service for YDB | Data type Yandex Query |
|---|---|
Bool |
Bool |
Int8 |
Int8 |
Uint8 |
Uint8 |
Int16 |
Int16 |
Uint16 |
Uint16 |
Int32 |
Int32 |
Uint32 |
Uint32 |
Int64 |
Int64 |
Uint64 |
Uint64 |
Float |
Float |
Double |
Double |
Date |
Date |
Datetime |
Datetime |
Timestamp |
Timestamp |
String |
String |
Utf8 |
Utf8 |
Json |
Json |
JsonDocument |
Json |
Optional data types
| Data type Managed Service for YDB | Data type Yandex Query |
|---|---|
Optional<Bool> |
Optional<Bool> |
Optional<Int8> |
Optional<Int8> |
Optional<Uint8> |
Optional<Uint8> |
Optional<Int16> |
Optional<Int16> |
Optional<Uint16> |
Optional<Uint16> |
Optional<Int32> |
Optional<Int32> |
Optional<Uint32> |
Optional<Uint32> |
Optional<Int64> |
Optional<Int64> |
Optional<Uint64> |
Optional<Uint64> |
Optional<Float> |
Optional<Float> |
Optional<Double> |
Optional<Double> |
Optional<Date> |
Optional<Date> |
Optional<Datetime> |
Optional<Datetime> |
Optional<Timestamp> |
Optional<Timestamp> |
Optional<String> |
Optional<String> |
Optional<Utf8> |
Optional<Utf8> |
Optional<Json> |
Optional<Json> |
Optional<JsonDocument> |
Optional<Json> |