1
0
mirror of synced 2026-01-21 15:06:13 -05:00
Files
airbyte/airbyte-cdk/python/airbyte_cdk/utils/message_utils.py
Artem Inzhyyants f5bea19647 perf(airbyte-cdk): performance enhancement (#42441)
Signed-off-by: Artem Inzhyyants <artem.inzhyyants@gmail.com>
2024-07-29 13:52:57 +02:00

19 lines
989 B
Python

# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from airbyte_cdk.sources.connector_state_manager import HashableStreamDescriptor
from airbyte_protocol.models import AirbyteMessage, Type
def get_stream_descriptor(message: AirbyteMessage) -> HashableStreamDescriptor:
match message.type:
case Type.RECORD:
return HashableStreamDescriptor(name=message.record.stream, namespace=message.record.namespace)
case Type.STATE:
if not message.state.stream or not message.state.stream.stream_descriptor:
raise ValueError("State message was not in per-stream state format, which is required for record counts.")
return HashableStreamDescriptor(
name=message.state.stream.stream_descriptor.name, namespace=message.state.stream.stream_descriptor.namespace
)
case _:
raise NotImplementedError(f"get_stream_descriptor is not implemented for message type '{message.type}'.")