airbyte_cdk.sources.streams.concurrent.partitions.partition

 1#
 2# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
 3#
 4
 5from abc import ABC, abstractmethod
 6from typing import Any, Iterable, Mapping, Optional
 7
 8from airbyte_cdk.sources.types import Record
 9
10
11class Partition(ABC):
12    """
13    A partition is responsible for reading a specific set of data from a source.
14    """
15
16    @abstractmethod
17    def read(self) -> Iterable[Record]:
18        """
19        Reads the data from the partition.
20        :return: An iterable of records.
21        """
22        pass
23
24    @abstractmethod
25    def to_slice(self) -> Optional[Mapping[str, Any]]:
26        """
27        Converts the partition to a slice that can be serialized and deserialized.
28
29        Note: it would have been interesting to have a type of `Mapping[str, Comparable]` to simplify typing but some slices can have nested
30         values ([example](https://github.com/airbytehq/airbyte/blob/1ce84d6396e446e1ac2377362446e3fb94509461/airbyte-integrations/connectors/source-stripe/source_stripe/streams.py#L584-L596))
31        :return: A mapping representing a slice
32        """
33        pass
34
35    @abstractmethod
36    def stream_name(self) -> str:
37        """
38        Returns the name of the stream that this partition is reading from.
39        :return: The name of the stream.
40        """
41        pass
42
43    @abstractmethod
44    def __hash__(self) -> int:
45        """
46        Returns a hash of the partition.
47        Partitions must be hashable so that they can be used as keys in a dictionary.
48        """
class Partition(abc.ABC):
12class Partition(ABC):
13    """
14    A partition is responsible for reading a specific set of data from a source.
15    """
16
17    @abstractmethod
18    def read(self) -> Iterable[Record]:
19        """
20        Reads the data from the partition.
21        :return: An iterable of records.
22        """
23        pass
24
25    @abstractmethod
26    def to_slice(self) -> Optional[Mapping[str, Any]]:
27        """
28        Converts the partition to a slice that can be serialized and deserialized.
29
30        Note: it would have been interesting to have a type of `Mapping[str, Comparable]` to simplify typing but some slices can have nested
31         values ([example](https://github.com/airbytehq/airbyte/blob/1ce84d6396e446e1ac2377362446e3fb94509461/airbyte-integrations/connectors/source-stripe/source_stripe/streams.py#L584-L596))
32        :return: A mapping representing a slice
33        """
34        pass
35
36    @abstractmethod
37    def stream_name(self) -> str:
38        """
39        Returns the name of the stream that this partition is reading from.
40        :return: The name of the stream.
41        """
42        pass
43
44    @abstractmethod
45    def __hash__(self) -> int:
46        """
47        Returns a hash of the partition.
48        Partitions must be hashable so that they can be used as keys in a dictionary.
49        """

A partition is responsible for reading a specific set of data from a source.

@abstractmethod
def read(self) -> Iterable[airbyte_cdk.Record]:
17    @abstractmethod
18    def read(self) -> Iterable[Record]:
19        """
20        Reads the data from the partition.
21        :return: An iterable of records.
22        """
23        pass

Reads the data from the partition.

Returns

An iterable of records.

@abstractmethod
def to_slice(self) -> Optional[Mapping[str, Any]]:
25    @abstractmethod
26    def to_slice(self) -> Optional[Mapping[str, Any]]:
27        """
28        Converts the partition to a slice that can be serialized and deserialized.
29
30        Note: it would have been interesting to have a type of `Mapping[str, Comparable]` to simplify typing but some slices can have nested
31         values ([example](https://github.com/airbytehq/airbyte/blob/1ce84d6396e446e1ac2377362446e3fb94509461/airbyte-integrations/connectors/source-stripe/source_stripe/streams.py#L584-L596))
32        :return: A mapping representing a slice
33        """
34        pass

Converts the partition to a slice that can be serialized and deserialized.

Note: it would have been interesting to have a type of Mapping[str, Comparable] to simplify typing but some slices can have nested values (example)

Returns

A mapping representing a slice

@abstractmethod
def stream_name(self) -> str:
36    @abstractmethod
37    def stream_name(self) -> str:
38        """
39        Returns the name of the stream that this partition is reading from.
40        :return: The name of the stream.
41        """
42        pass

Returns the name of the stream that this partition is reading from.

Returns

The name of the stream.