airbyte-cdk 0.36.0__py3-none-any.whl → 0.36.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airbyte_cdk/sources/declarative/declarative_stream.py +18 -8
- airbyte_cdk/sources/streams/core.py +3 -5
- {airbyte_cdk-0.36.0.dist-info → airbyte_cdk-0.36.1.dist-info}/METADATA +1 -1
- {airbyte_cdk-0.36.0.dist-info → airbyte_cdk-0.36.1.dist-info}/RECORD +8 -8
- unit_tests/sources/declarative/test_declarative_stream.py +18 -7
- {airbyte_cdk-0.36.0.dist-info → airbyte_cdk-0.36.1.dist-info}/LICENSE.txt +0 -0
- {airbyte_cdk-0.36.0.dist-info → airbyte_cdk-0.36.1.dist-info}/WHEEL +0 -0
- {airbyte_cdk-0.36.0.dist-info → airbyte_cdk-0.36.1.dist-info}/top_level.txt +0 -0
@@ -5,14 +5,14 @@
|
|
5
5
|
from dataclasses import InitVar, dataclass, field
|
6
6
|
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Union
|
7
7
|
|
8
|
-
from airbyte_cdk.models import
|
8
|
+
from airbyte_cdk.models import AirbyteMessage, SyncMode
|
9
9
|
from airbyte_cdk.sources.declarative.interpolation import InterpolatedString
|
10
10
|
from airbyte_cdk.sources.declarative.retrievers.retriever import Retriever
|
11
11
|
from airbyte_cdk.sources.declarative.schema import DefaultSchemaLoader
|
12
12
|
from airbyte_cdk.sources.declarative.schema.schema_loader import SchemaLoader
|
13
13
|
from airbyte_cdk.sources.declarative.transformations import RecordTransformation
|
14
14
|
from airbyte_cdk.sources.declarative.types import Config, StreamSlice
|
15
|
-
from airbyte_cdk.sources.streams.core import Stream
|
15
|
+
from airbyte_cdk.sources.streams.core import Stream, StreamData
|
16
16
|
|
17
17
|
|
18
18
|
@dataclass
|
@@ -102,17 +102,27 @@ class DeclarativeStream(Stream):
|
|
102
102
|
|
103
103
|
def _apply_transformations(
|
104
104
|
self,
|
105
|
-
message_or_record_data:
|
105
|
+
message_or_record_data: StreamData,
|
106
106
|
config: Config,
|
107
107
|
stream_slice: StreamSlice,
|
108
108
|
):
|
109
|
-
# If the input is an
|
110
|
-
# If the input is another type of
|
109
|
+
# If the input is an AirbyteMessage with a record, transform the record's data
|
110
|
+
# If the input is another type of AirbyteMessage, return it as is
|
111
111
|
# If the input is a dict, transform it
|
112
|
-
if isinstance(message_or_record_data,
|
113
|
-
|
112
|
+
if isinstance(message_or_record_data, AirbyteMessage):
|
113
|
+
if message_or_record_data.record:
|
114
|
+
record = message_or_record_data.record.data
|
115
|
+
else:
|
116
|
+
return message_or_record_data
|
117
|
+
elif isinstance(message_or_record_data, dict):
|
118
|
+
record = message_or_record_data
|
119
|
+
else:
|
120
|
+
# Raise an error because this is unexpected and indicative of a typing problem in the CDK
|
121
|
+
raise ValueError(
|
122
|
+
f"Unexpected record type. Expected {StreamData}. Got {type(message_or_record_data)}. This is probably due to a bug in the CDK."
|
123
|
+
)
|
114
124
|
for transformation in self.transformations:
|
115
|
-
transformation.transform(
|
125
|
+
transformation.transform(record, config=config, stream_state=self.state, stream_slice=stream_slice)
|
116
126
|
|
117
127
|
return message_or_record_data
|
118
128
|
|
@@ -11,7 +11,7 @@ from functools import lru_cache
|
|
11
11
|
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple, Union
|
12
12
|
|
13
13
|
import airbyte_cdk.sources.utils.casing as casing
|
14
|
-
from airbyte_cdk.models import
|
14
|
+
from airbyte_cdk.models import AirbyteMessage, AirbyteStream, SyncMode
|
15
15
|
|
16
16
|
# list of all possible HTTP methods which can be used for sending of request bodies
|
17
17
|
from airbyte_cdk.sources.utils.schema_helpers import ResourceSchemaLoader
|
@@ -24,10 +24,8 @@ if typing.TYPE_CHECKING:
|
|
24
24
|
|
25
25
|
# A stream's read method can return one of the following types:
|
26
26
|
# Mapping[str, Any]: The content of an AirbyteRecordMessage
|
27
|
-
#
|
28
|
-
|
29
|
-
# AirbyteTraceMessage: A trace message
|
30
|
-
StreamData = Union[Mapping[str, Any], AirbyteLogMessage, AirbyteTraceMessage]
|
27
|
+
# AirbyteMessage: An AirbyteMessage. Could be of any type
|
28
|
+
StreamData = Union[Mapping[str, Any], AirbyteMessage]
|
31
29
|
|
32
30
|
|
33
31
|
def package_name_from_class(cls: object) -> str:
|
@@ -24,7 +24,7 @@ airbyte_cdk/sources/declarative/__init__.py,sha256=ZnqYNxHsKCgO38IwB34RQyRMXTs4G
|
|
24
24
|
airbyte_cdk/sources/declarative/create_partial.py,sha256=sUJOwD8hBzW4pxw2XhYlSTMgl-WMc5WpP5Oq_jo3fHw,3371
|
25
25
|
airbyte_cdk/sources/declarative/declarative_component_schema.yaml,sha256=DJIV9HgHfBgv4w8zg6DhLIqXjZe235UVTe79IT7O51Q,74761
|
26
26
|
airbyte_cdk/sources/declarative/declarative_source.py,sha256=U2As9PDKmcWDgbsWUo-RetJ9fxQOBlwntWZ0NOgs5Ac,1453
|
27
|
-
airbyte_cdk/sources/declarative/declarative_stream.py,sha256=
|
27
|
+
airbyte_cdk/sources/declarative/declarative_stream.py,sha256=0iZSpypxt8bhO3Lmf3BpGRTO7Fp0Q2GI8m8xyJJUjeM,6580
|
28
28
|
airbyte_cdk/sources/declarative/exceptions.py,sha256=kTPUA4I2NV4J6HDz-mKPGMrfuc592akJnOyYx38l_QM,176
|
29
29
|
airbyte_cdk/sources/declarative/manifest_declarative_source.py,sha256=vTbRNM8D9P_ChOu1GNvtNRt-PM2L9N5Y0pNRyfVFuZg,9759
|
30
30
|
airbyte_cdk/sources/declarative/types.py,sha256=b_RJpL9TyAgxJIRYZx5BxpC39p-WccHKxbAqxWrn9oE,482
|
@@ -128,7 +128,7 @@ airbyte_cdk/sources/singer/singer_helpers.py,sha256=q1LmgjFxSnN-dobMy7nikUwcK-9F
|
|
128
128
|
airbyte_cdk/sources/singer/source.py,sha256=3YY8UTOXmctvMVUnYmIegmL3_IxF55iGP_bc_s2MZdY,8530
|
129
129
|
airbyte_cdk/sources/streams/__init__.py,sha256=XGrzYjIkqItvnMshsOUzYhi4lC4M9kFHhxG0oCAoAyE,176
|
130
130
|
airbyte_cdk/sources/streams/availability_strategy.py,sha256=7BM0qLvXS0QrlKvnVkBEw4Cw8i7PCENCBLcIAcuD3nY,1007
|
131
|
-
airbyte_cdk/sources/streams/core.py,sha256=
|
131
|
+
airbyte_cdk/sources/streams/core.py,sha256=G0MxhVkrF1DAPoPgmRBd_wnhrI7S6ZAdtOG0h9N_zHU,11021
|
132
132
|
airbyte_cdk/sources/streams/http/__init__.py,sha256=6hRmA0P_RhB7X54xQbtj2RTz1RGlP52AG9V4pPWLaEQ,261
|
133
133
|
airbyte_cdk/sources/streams/http/availability_strategy.py,sha256=uYYjanBG0f-CIrUYn1SnMyJqHoQQHnTggeJiB0m4i-Y,6344
|
134
134
|
airbyte_cdk/sources/streams/http/exceptions.py,sha256=OokLDI7W8hZvq9e15sL3em2AdwmzmcAl72Ms-i5l0Nw,1334
|
@@ -177,7 +177,7 @@ unit_tests/sources/test_source.py,sha256=eVtU9Zuc9gBsg11Pb5xjDtyU0gVrbYqbZ4RmzPv
|
|
177
177
|
unit_tests/sources/declarative/__init__.py,sha256=ZnqYNxHsKCgO38IwB34RQyRMXTs4GTvlRi3ImKnIioo,61
|
178
178
|
unit_tests/sources/declarative/external_component.py,sha256=lU2gL736bLEWtmrGm1B2k83RXt_3XkROimLIahZd5dg,293
|
179
179
|
unit_tests/sources/declarative/test_create_partial.py,sha256=s_KIywQqt8RlauOCWNJVk3HC3KBTAtSwFTN6JVQgu80,2636
|
180
|
-
unit_tests/sources/declarative/test_declarative_stream.py,sha256=
|
180
|
+
unit_tests/sources/declarative/test_declarative_stream.py,sha256=3leJnZIYHiFq8XI4jb3TjPXTubGJmvNGzABt4c01EkQ,5436
|
181
181
|
unit_tests/sources/declarative/test_manifest_declarative_source.py,sha256=GckUc3nepzZkD1UM24woHlYCVZb5DP4IAQC3IeMyZF0,58924
|
182
182
|
unit_tests/sources/declarative/test_yaml_declarative_source.py,sha256=6HhsUFgB7ueN0yOUHWb4gpPYLng5jasxN_plvz3x37g,5097
|
183
183
|
unit_tests/sources/declarative/auth/__init__.py,sha256=4Hw-PX1-VgESLF16cDdvuYCzGJtHntThLF4qIiULWeo,61
|
@@ -259,8 +259,8 @@ unit_tests/utils/test_schema_inferrer.py,sha256=ckl17GlNOZInqgxni7Z2A0bg_p6JDy0G
|
|
259
259
|
unit_tests/utils/test_secret_utils.py,sha256=XKe0f1RHYii8iwE6ATmBr5JGDI1pzzrnZUGdUSMJQP4,4886
|
260
260
|
unit_tests/utils/test_stream_status_utils.py,sha256=NpV155JMXA6CG-2Zvofa14lItobyh3Onttc59X4m5DI,3382
|
261
261
|
unit_tests/utils/test_traced_exception.py,sha256=bDFP5zMBizFenz6V2WvEZTRCKGB5ijh3DBezjbfoYIs,4198
|
262
|
-
airbyte_cdk-0.36.
|
263
|
-
airbyte_cdk-0.36.
|
264
|
-
airbyte_cdk-0.36.
|
265
|
-
airbyte_cdk-0.36.
|
266
|
-
airbyte_cdk-0.36.
|
262
|
+
airbyte_cdk-0.36.1.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
|
263
|
+
airbyte_cdk-0.36.1.dist-info/METADATA,sha256=julG0JMgo00RRk6h3nZf_h-2-wVJffJ3e_fEEsV3dhQ,8902
|
264
|
+
airbyte_cdk-0.36.1.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
265
|
+
airbyte_cdk-0.36.1.dist-info/top_level.txt,sha256=edvsDKTnE6sD2wfCUaeTfKf5gQIL6CPVMwVL2sWZzqo,51
|
266
|
+
airbyte_cdk-0.36.1.dist-info/RECORD,,
|
@@ -5,7 +5,16 @@
|
|
5
5
|
from unittest import mock
|
6
6
|
from unittest.mock import MagicMock, call
|
7
7
|
|
8
|
-
from airbyte_cdk.models import
|
8
|
+
from airbyte_cdk.models import (
|
9
|
+
AirbyteLogMessage,
|
10
|
+
AirbyteMessage,
|
11
|
+
AirbyteRecordMessage,
|
12
|
+
AirbyteTraceMessage,
|
13
|
+
Level,
|
14
|
+
SyncMode,
|
15
|
+
TraceType,
|
16
|
+
Type,
|
17
|
+
)
|
9
18
|
from airbyte_cdk.sources.declarative.declarative_stream import DeclarativeStream
|
10
19
|
from airbyte_cdk.sources.declarative.transformations import AddFields, RecordTransformation
|
11
20
|
from airbyte_cdk.sources.declarative.transformations.add_fields import AddedFieldDefinition
|
@@ -24,8 +33,8 @@ def test_declarative_stream():
|
|
24
33
|
records = [
|
25
34
|
{"pk": 1234, "field": "value"},
|
26
35
|
{"pk": 4567, "field": "different_value"},
|
27
|
-
AirbyteLogMessage(level=Level.INFO, message="This is a log message"),
|
28
|
-
AirbyteTraceMessage(type=TraceType.ERROR, emitted_at=12345),
|
36
|
+
AirbyteMessage(type=Type.LOG, log=AirbyteLogMessage(level=Level.INFO, message="This is a log message")),
|
37
|
+
AirbyteMessage(type=Type.TRACE, trace=AirbyteTraceMessage(type=TraceType.ERROR, emitted_at=12345)),
|
29
38
|
]
|
30
39
|
stream_slices = [
|
31
40
|
{"date": "2021-01-01"},
|
@@ -84,15 +93,17 @@ def test_declarative_stream_with_add_fields_transform():
|
|
84
93
|
retriever_records = [
|
85
94
|
{"pk": 1234, "field": "value"},
|
86
95
|
{"pk": 4567, "field": "different_value"},
|
87
|
-
|
88
|
-
|
96
|
+
AirbyteMessage(type=Type.RECORD, record=AirbyteRecordMessage(data={"pk": 1357, "field": "a_value"}, emitted_at=12344, stream="stream")),
|
97
|
+
AirbyteMessage(type=Type.LOG, log=AirbyteLogMessage(level=Level.INFO, message="This is a log message")),
|
98
|
+
AirbyteMessage(type=Type.TRACE, trace=AirbyteTraceMessage(type=TraceType.ERROR, emitted_at=12345)),
|
89
99
|
]
|
90
100
|
|
91
101
|
expected_records = [
|
92
102
|
{"pk": 1234, "field": "value", "added_key": "added_value"},
|
93
103
|
{"pk": 4567, "field": "different_value", "added_key": "added_value"},
|
94
|
-
|
95
|
-
|
104
|
+
AirbyteMessage(type=Type.RECORD, record=AirbyteRecordMessage(data={"pk": 1357, "field": "a_value", "added_key": "added_value"}, emitted_at=12344, stream="stream")),
|
105
|
+
AirbyteMessage(type=Type.LOG, log=AirbyteLogMessage(level=Level.INFO, message="This is a log message")),
|
106
|
+
AirbyteMessage(type=Type.TRACE, trace=AirbyteTraceMessage(type=TraceType.ERROR, emitted_at=12345)),
|
96
107
|
]
|
97
108
|
stream_slices = [
|
98
109
|
{"date": "2021-01-01"},
|
File without changes
|
File without changes
|
File without changes
|