Working with Managed Service for YDB databases
This section covers the basics of working with Managed Service for YDB.
To start working with a Managed Service for YDB database, follow these steps:
- Create a connection containing your database access credentials.
- Run a query against the database.
Query example for reading data from Managed Service for YDB:
SELECT * FROM ydb_connection.my_table
Where:
ydb_connection: Your database connection name.my_table: Database table name.
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. -
Navigate to Yandex Query.
-
In the left-hand panel, switch to the Connections tab.
-
Click
Create new. -
Specify the connection settings:
-
Under General parameters:
- Name: Managed Service for YDB connection name.
- 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 you will use for
Managed Service for YDBcluster connections 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
Managed Service for YDB uses the following SQL syntax:
SELECT * FROM <connection>.<table_name>
Where:
<connection>: Your database connection name.<table_name>: Database table name.
Limits
External sources are available for read-only access via SELECT queries. Yandex Query does not currently support data-modifying queries against external sources.
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 | Limitation |
|---|---|---|
IS NULL and IS NOT NULL filters |
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. |
|
LIKE string pattern matching operator |
WHERE column1 LIKE '_abc%' |
Currently, filter pushdown only supports patterns based on prefixes, e.g., 'abc_' or 'abc%', suffixes, e.g., '_abc' or '%abc', and substring matches, e.g., '_abc_', '%abc%', '_abc%', or '%abc_'. To push down more complex patterns, you can use the REGEXP operator. |
REGEXP pattern-matching operator |
WHERE column1 REGEXP '.*abc.*' |
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 |
|---|
Bool |
Int8 |
Uint8 |
Int16 |
Uint16 |
Int32 |
Uint32 |
Int64 |
Uint64 |
Float |
Double |
String |
Utf8 |
Supported data types
The tables below show type mapping between Managed Service for YDB and Yandex Query. Only the listed types are supported.
Primitive data types
| Managed Service for YDB data type | Yandex Query data type |
|---|---|
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
| Managed Service for YDB data type | Yandex Query data type |
|---|---|
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> |