Reading data via bindings
Data bindings allow you to regularly query Yandex Data Streams data without having to specify connection settings and data format in each query.
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 streaming source is delivered as an infinite stream. To prevent infinite streaming and get output in the console, the example uses the LIMIT clause that limits the number of result rows.
Setting up a data binding
To create a binding to read data from Yandex Data Streams:
-
Navigate
to Yandex Query. -
In the left-hand panel, switch to the Bindings tab.
-
Click
Create. -
Under Connection parameters:
- In the Type field, select
Data Streams. - In the Connection field, select the connection you created in the first step.
- In the Type field, select
-
Under Binding parameters:
- In the Name field, specify the binding name.
- In the Stream field, enter the name of the data stream in Yandex Data Streams.
- In the Compression field, specify the data compression method.
- In the Format field, specify the data format.
- In the Columns fields, specify the list of columns and their data types.
-
To validate the data, click Preview.
-
Click Create.
Data model
Data is transmitted via Yandex Data Streams in binary format. To read data using a binding, use an SQL statement of the following format:
SELECT
<expression>
FROM bindings.`<binding_name>`
WHERE
<filter>;
Where:
<statement>: Statement that determines the result of the query.<binding_name>: Name of the data binding you created earlier.<filter>: Data filtering condition.
Data reading example
Query example for reading data from Yandex Data Streams via bindings:
$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 |
|
|
Name of the binding to the data source stream. |
|
|
|
String |
Host name. |
|
|
String |
Number of events. |
|
|
String |
Event tag. |