-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathabstract_stream.py
More file actions
89 lines (73 loc) · 3.58 KB
/
abstract_stream.py
File metadata and controls
89 lines (73 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from abc import ABC, abstractmethod
from typing import Any, Iterable, Mapping, Optional
from typing_extensions import deprecated
from airbyte_cdk.models import AirbyteStream
from airbyte_cdk.sources.source import ExperimentalClassWarning
from airbyte_cdk.sources.streams.concurrent.cursor import Cursor
from airbyte_cdk.sources.streams.concurrent.partitions.partition import Partition
@deprecated(
"This class is experimental. Use at your own risk.",
category=ExperimentalClassWarning,
)
class AbstractStream(ABC):
"""
AbstractStream is an experimental interface for streams developed as part of the Concurrent CDK.
This interface is not yet stable and may change in the future. Use at your own risk.
Why create a new interface instead of adding concurrency capabilities the existing Stream?
We learnt a lot since the initial design of the Stream interface, and we wanted to take the opportunity to improve.
High level, the changes we are targeting are:
- Removing superfluous or leaky parameters from the methods' interfaces
- Using composition instead of inheritance to add new capabilities
To allow us to iterate fast while ensuring backwards compatibility, we are creating a new interface with a facade object that will bridge the old and the new interfaces.
Source connectors that wish to leverage concurrency need to implement this new interface. An example will be available shortly
Current restrictions on sources that implement this interface. Not all of these restrictions will be lifted in the future, but most will as we iterate on the design.
- Only full refresh is supported. This will be addressed in the future.
- The read method does not accept a cursor_field. Streams must be internally aware of the cursor field to use. User-defined cursor fields can be implemented by modifying the connector's main method to instantiate the streams with the configured cursor field.
- Streams cannot return user-friendly messages by overriding Stream.get_error_display_message. This will be addressed in the future.
- The Stream's behavior cannot depend on a namespace
- TypeTransformer is not supported. This will be addressed in the future.
- Nested cursor and primary keys are not supported
"""
@abstractmethod
def generate_partitions(self) -> Iterable[Partition]:
"""
Generates the partitions that will be read by this stream.
:return: An iterable of partitions.
"""
@property
@abstractmethod
def name(self) -> str:
"""
:return: The stream name
"""
@property
@abstractmethod
def cursor_field(self) -> Optional[str]:
"""
Override to return the default cursor field used by this stream e.g: an API entity might always use created_at as the cursor field.
:return: The name of the field used as a cursor. Nested cursor fields are not supported.
"""
@abstractmethod
def get_json_schema(self) -> Mapping[str, Any]:
"""
:return: A dict of the JSON schema representing this stream.
"""
@abstractmethod
def as_airbyte_stream(self) -> AirbyteStream:
"""
:return: A dict of the JSON schema representing this stream.
"""
@abstractmethod
def log_stream_sync_configuration(self) -> None:
"""
Logs the stream's configuration for debugging purposes.
"""
@property
@abstractmethod
def cursor(self) -> Cursor:
"""
:return: The cursor associated with this stream.
"""