Reading data using Query bindings
Written by
Updated at June 25, 2024
When working with Yandex Data Streams, bindings help you run regular queries to stored data with no need to specify all details of operations with this data.
Example of reading data using bindings:
SELECT
JSON_VALUE(CAST(Data AS Json), "$.action") AS action
FROM bindings.`input_stream`
LIMIT 10;
Note
Data from a stream source is transferred as an infinite stream. To stop data processing and output the result to the console, the data in the example is limited with the LIMIT
operator that sets the number of rows in the result.
Setting up a data binding
To read data from Yandex Data Streams using bindings:
- Setting up a data connection.
- In the Type field, select
Data Streams
. - In the drop-down list of the Connection field, select the connection you created in the first step.
- Specify a name for the data binding in the Name field.
- Specify a name for a Yandex Data Streams stream in the Stream field.
- Specify the data compression method in the Compression field.
- Specify the format of transferred data in the Format field.
- List data columns and their data types in the Columns fields.
- To check the data, click Preview.
- Click Create to create a binding.
Data model
Data is sent via Yandex Data Streams in binary form. Data is read using SQL statements.
SELECT
<expression>
FROM
<connection>.<stream_name>
WITH
(
format=raw,
SCHEMA
(
Data String
)
)
WHERE <filter>;
Where:
<connection>
: Name of the Data Streams data stream connection created in the previous step.<stream_name>
: Name of the data stream in Data Streams.
Example of reading data
Sample query for reading data from Yandex Data Streams and writing the results to Yandex Data Streams
$data =
SELECT
JSON_VALUE(Data, "$.host") AS host,
JSON_VALUE(Data, "$.count") AS count,
JSON_VALUE(Data, "$.tag") AS tag,
FROM
(
SELECT
CAST(Data AS Json) AS Data
FROM bindings.`binding_name`
)
WHERE
JSON_VALUE(Data, "$.tag") = "my_tag";
SELECT
*
FROM
$data
LIMIT 10;
Where:
Field | Type | Description |
---|---|---|
binding_name |
Name of binding to source data stream in SQL query | |
host |
String | Query string parameter |