---
metadata:
  - name: generator
    content: Diplodoc Platform v5.64.2
alternate:
  - https://ytsaurus.tech/docs/en/flow/python/examples/external_state_join.md
  - https://ytsaurus.tech/docs/ru/flow/python/examples/external_state_join.md
  - href: https://ytsaurus.tech/docs/ru/flow/python/examples/external_state_join.md
    type: text/markdown
    title: Markdown version
  - href: https://ytsaurus.tech/docs/ru/llms.txt?revision=c426f39927f2807c73168512150ef54f4b741847
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://ytsaurus.tech/docs/ru/llms.txt?revision=c426f39927f2807c73168512150ef54f4b741847

<!-- source: ru/_includes/flow/python/examples/external_state_join.md -->
# External State Join в YTsaurus Flow (Python)

Пайплайн обогащает события из очереди данными из заранее созданной динамической таблицы через read-only external state joiner.

[Исходники](https://github.com/ytsaurus/ytsaurus/tree/main/yt/yt/flow/examples/python/external_state_join)

## Структура пайплайна {#structure}

`event_reader` публикует стрим `event`. Компаньонский компьютейшен `lookup_join` группирует сообщения по `key`, читает `/reference` через `external_state_joiners` и передаёт успешные совпадения в `enriched`. Queue-sink сохраняет выходные сообщения. `path` joiner-а может указывать на Cypress-ссылку, чтобы переключать справочник без перезапуска пайплайна.

См. [спеку пайплайна](https://github.com/ytsaurus/ytsaurus/tree/main/yt/yt/flow/examples/python/external_state_join/pipeline.yson).

## Чтение присоединённого стейта {#lookup}

`ctx.joined_external_state("/reference", message)` выбирает строку по ключу сообщения. Возвращаемый аксессор доступен только для чтения. Если строка не найдена, он содержит пустой payload: `get("name")` возвращает `None`, и пример не публикует результат.

```python
class LookupJoin(RowFunction):
    """Looks up each event's name in the reference state and emits the joined row."""

    def on_message(self, message, output, ctx):
        name = ctx.joined_external_state("/reference", message).get("name")
        if name is None:
            return

        builder = ctx.message_builder("enriched")
        builder.set("key", message.payload["key"])
        builder.set("name", name)
        output.add_message(builder.finish())

```

## См. также

- [External State (Python)](https://ytsaurus.tech/docs/ru/flow/python/external-state.md)
- [Пример Static Table Join](https://ytsaurus.tech/docs/ru/flow/python/examples/static_table_join.md)
<!-- endsource: ru/_includes/flow/python/examples/external_state_join.md -->
