Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
    • Cloud Interconnect
    • Cloud Backup
    • Cloud Registry
    • Yandex AI Studio
    • Compute Cloud
    • Object Storage
    • Managed Service for Kubernetes®
    • Yandex BareMetal
    • Smart Web Security
    • Security Deck
    • Managed Service for PostgreSQL
    • Managed Service for ClickHouse®
    • Monium
    • Cloud CDN
    • Network Load Balancer
    • Virtual Private Cloud
    • Cloud DNS
    • Application Load Balancer
    • Yandex Cloud Video
    • Stackland
    • Yandex Cloud Router
    • Yandex Managed Service for Trino
    • Managed Service for MySQL®
    • Managed Service for Valkey™
    • Managed Service for Apache Spark™
    • Yandex StoreDoc
    • Managed Service for OpenSearch
    • Managed Service for Apache Kafka®
    • Data Transfer
    • Yandex MPP Analytics Engine for PostgreSQL
    • Yandex Managed Service for Apache Airflow®
    • Data Processing
    • Yandex MetaData Hub
    • Managed Service for YDB
    • Managed Service for Sharded PostgreSQL
    • Managed Service for YTsaurus
    • Yandex WebSQL
    • DataLens
    • Yandex Search API
    • SpeechSense
    • SpeechKit
    • DataSphere
    • Vision OCR
    • Translate
    • Yandex Identity Hub
    • Key Management Service
    • Certificate Manager
    • Yandex Lockbox
    • Audit Trails
    • SmartCaptcha
    • Cloud Desktop
    • Yandex SIEM
    • SourceCraft Code Assistant
    • Container Registry
    • Managed Service for GitLab
    • Managed Service for Prometheus®
    • Cloud Functions
    • API Gateway
    • Yandex Cloud Postbox
    • Message Queue
    • Serverless Integrations
    • IoT Core
    • Data Streams
    • Serverless Containers
    • Cloud Notification Service
    • Yandex Query
    • Identity and Access Management
    • Yandex Cloud Console
    • Resource Manager
    • Yandex Cloud Billing
    • Yandex Cloud Quota Manager
    • Cloud Apps
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Query
    • Data formats and compression algorithms
      • Reading data via connections
      • Reading data via bindings
      • Writing data
    • Working with Managed Service for ClickHouse® databases
    • Working with Yandex MPP Analytics for PostgreSQL databases
    • Working with Managed Service for MySQL® databases
    • Working with Managed Service for PostgreSQL databases
    • Working with Managed Service for YDB databases
    • Reading Iceberg tables
  • Access management
  • Pricing policy
  • Integrations
  • Audit Trails events
  • FAQ

In this article:

  • Setting up a connection
  • Data model
  • Data writing example
  • Supported write formats
  1. Data sources and sinks
  2. Working with Data Streams
  3. Writing data

Writing data from Yandex Query to Yandex Data Streams streams

Written by
Yandex Cloud
Improved by
Updated at August 17, 2026
View in Markdown
  • Setting up a connection
  • Data model
  • Data writing example
  • Supported write formats

Yandex Data Streams: Service for transmitting data streams to multiple applications. Each application processes data independently from the others.

Example of writing JSON data to Yandex Data Streams:

INSERT INTO yds.`output_stream`
SELECT
    ToBytes(Unwrap(Json::SerializeJson(Yson::From(
    <|"predefined":
            <|
                "host": host,
                "count": count,
            |>,
            "optional":
            <|
                "tag": tag
            |>
        |>))))
FROM
    $data;

Setting up a connectionSetting up a connection

To set up writing data to Yandex Data Streams:

  1. Navigate to Yandex Query.
  2. In the left-hand panel, select Connections.
  3. Click Create new.
  4. In the window that opens, specify the Yandex Data Streams connection name in the Name field.
  5. In the Type field, select Data Streams.
  6. In the Database field, select the Yandex Managed Service for YDB database where you created the Yandex Data Streams stream.
  7. In the Service account field, select the service account you intend to use to write data, or create a new one and assign it the yds.writer role.
  8. Click Create.

Data modelData model

Data is transmitted via Yandex Data Streams in binary format and is written via SQL statements as follows:

INSERT INTO <connection>.<stream_name>
    <expression>
FROM
    <query>

Where:

  • <connection>: Name of the Data Streams data stream connection created in the previous section.
  • <stream_name>: Data Streams data stream name.
  • <statement>: Statement defining the data to write.
  • <query>: Yandex Query source data query.

Data writing exampleData writing example

Query example for reading data from Yandex Data Streams and writing the results to Yandex Data Streams:

$data =
SELECT
    JSON_VALUE(Data, "$.host") AS host,
    CAST(JSON_VALUE(Data, "$.count") AS Int) AS count,
    JSON_VALUE(Data, "$.tag") AS tag,
FROM
(
    SELECT
        CAST(Data AS Json) AS Data
    FROM yds.`input_stream`
    WITH(
        format=raw,
        SCHEMA
        (
            Data String
        )
    )
)
WHERE
    JSON_VALUE(Data, "$.tag") = "my_tag";

INSERT INTO yds.`output_stream`
SELECT
    ToBytes(Unwrap(Json::SerializeJson(Yson::From(
    <|"predefined":
            <|
                "host": host,
                "count": count,
            |>,
            "optional":
            <|
                "tag": tag
            |>
        |>))))
FROM
    $data;

Where:

Field

Type

Description

yds

Yandex Data Streams connection name

input_stream

Name of the source data stream in the SQL query

output_stream

Name of the target data stream in the SQL query

host

String

String query parameter

count

Integer

Integer query parameter

raw

String

Data format Currently, only the raw data format is supported.

The system writes processing results to the Yandex Data Streams output stream. For simpler processing, the results are converted to JSON format using the following structure:

    ToBytes(Unwrap(Json::SerializeJson(Yson::From(
    <|"key": value|>,
    <|"key2": 
        <|"child_key": child_value|>,
    |>,
    ))))

See YQL guides for detailed descriptions of the Yson and Json modules, JSON functions, and structures.

Supported write formatsSupported write formats

Data Streams only lets you write data as a byte stream, which is processed by the receiving side.

When writing to Data Streams, file format and compression algorithm settings are not applied.

Was the article helpful?

Previous
Reading data via bindings
Next
Reading data via connections
© 2026 Direct Cursus Technology L.L.C.