Skip to content

Commit 4d50127

Browse files
committed
format and lint
1 parent 5c0c12b commit 4d50127

File tree

3 files changed

+83
-43
lines changed

3 files changed

+83
-43
lines changed

airbyte_cdk/sources/declarative/concurrent_declarative_source.py

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,28 +190,48 @@ def _group_streams(
190190
# these legacy Python streams the way we do low-code streams to determine if they are concurrent compatible,
191191
# so we need to treat them as synchronous
192192
if isinstance(declarative_stream, DeclarativeStream):
193-
datetime_based_cursor_component_definition = name_to_stream_mapping[declarative_stream.name].get("incremental_sync")
194-
195-
is_without_partition_router_nor_cursor = not bool(datetime_based_cursor_component_definition) and not(name_to_stream_mapping[declarative_stream.name].get("retriever", {}).get("partition_router"))
196-
is_datetime_incremental_with_partition_routing = self._is_datetime_incremental_with_partition_routing(datetime_based_cursor_component_definition,
197-
declarative_stream)
198-
if is_without_partition_router_nor_cursor or is_datetime_incremental_with_partition_routing:
193+
datetime_based_cursor_component_definition = name_to_stream_mapping[
194+
declarative_stream.name
195+
].get("incremental_sync")
196+
197+
is_without_partition_router_nor_cursor = not bool(
198+
datetime_based_cursor_component_definition
199+
) and not (
200+
name_to_stream_mapping[declarative_stream.name]
201+
.get("retriever", {})
202+
.get("partition_router")
203+
)
204+
is_datetime_incremental_with_partition_routing = (
205+
self._is_datetime_incremental_with_partition_routing(
206+
datetime_based_cursor_component_definition, declarative_stream
207+
)
208+
)
209+
if (
210+
is_without_partition_router_nor_cursor
211+
or is_datetime_incremental_with_partition_routing
212+
):
199213
stream_state = state_manager.get_stream_state(
200214
stream_name=declarative_stream.name, namespace=declarative_stream.namespace
201215
)
202216

203217
if is_datetime_incremental_with_partition_routing:
204-
cursor: Cursor = self._constructor.create_concurrent_cursor_from_datetime_based_cursor(
205-
state_manager=state_manager,
206-
model_type=DatetimeBasedCursorModel,
207-
component_definition=datetime_based_cursor_component_definition,
208-
stream_name=declarative_stream.name,
209-
stream_namespace=declarative_stream.namespace,
210-
config=config or {},
211-
stream_state=stream_state,
218+
cursor: Cursor = (
219+
self._constructor.create_concurrent_cursor_from_datetime_based_cursor(
220+
state_manager=state_manager,
221+
model_type=DatetimeBasedCursorModel,
222+
component_definition=datetime_based_cursor_component_definition,
223+
stream_name=declarative_stream.name,
224+
stream_namespace=declarative_stream.namespace,
225+
config=config or {},
226+
stream_state=stream_state,
227+
)
212228
)
213229
else:
214-
cursor = FinalStateCursor(declarative_stream.name, declarative_stream.namespace, self.message_repository)
230+
cursor = FinalStateCursor(
231+
declarative_stream.name,
232+
declarative_stream.namespace,
233+
self.message_repository,
234+
)
215235

216236
partition_generator = StreamSlicerPartitionGenerator(
217237
DeclarativePartitionFactory(
@@ -234,7 +254,9 @@ def _group_streams(
234254
json_schema=declarative_stream.get_json_schema(),
235255
availability_strategy=AlwaysAvailableAvailabilityStrategy(),
236256
primary_key=get_primary_key_from_stream(declarative_stream.primary_key),
237-
cursor_field=cursor.cursor_field.cursor_field_key if hasattr(cursor, "cursor_field") else None,
257+
cursor_field=cursor.cursor_field.cursor_field_key
258+
if hasattr(cursor, "cursor_field")
259+
else None,
238260
logger=self.logger,
239261
cursor=cursor,
240262
)
@@ -246,8 +268,21 @@ def _group_streams(
246268

247269
return concurrent_streams, synchronous_streams
248270

249-
def _is_datetime_incremental_with_partition_routing(self, datetime_based_cursor_component_definition: Mapping[str, Any], declarative_stream: DeclarativeStream) -> bool:
250-
return bool(datetime_based_cursor_component_definition) and datetime_based_cursor_component_definition.get("type", "") == DatetimeBasedCursorModel.__name__ and self._stream_supports_concurrent_partition_processing(declarative_stream=declarative_stream) and hasattr(declarative_stream.retriever, "stream_slicer") and isinstance(declarative_stream.retriever.stream_slicer, DatetimeBasedCursor)
271+
def _is_datetime_incremental_with_partition_routing(
272+
self,
273+
datetime_based_cursor_component_definition: Mapping[str, Any],
274+
declarative_stream: DeclarativeStream,
275+
) -> bool:
276+
return (
277+
bool(datetime_based_cursor_component_definition)
278+
and datetime_based_cursor_component_definition.get("type", "")
279+
== DatetimeBasedCursorModel.__name__
280+
and self._stream_supports_concurrent_partition_processing(
281+
declarative_stream=declarative_stream
282+
)
283+
and hasattr(declarative_stream.retriever, "stream_slicer")
284+
and isinstance(declarative_stream.retriever.stream_slicer, DatetimeBasedCursor)
285+
)
251286

252287
def _stream_supports_concurrent_partition_processing(
253288
self, declarative_stream: DeclarativeStream

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
Mapping,
1818
MutableMapping,
1919
Optional,
20-
Tuple,
2120
Type,
2221
Union,
2322
get_args,

unit_tests/sources/declarative/parsers/test_model_to_component_factory.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,14 +3055,16 @@ def test_create_concurrent_cursor_from_datetime_based_cursor_all_fields(
30553055
"lookback_window": "P3D",
30563056
}
30573057

3058-
concurrent_cursor = connector_builder_factory.create_concurrent_cursor_from_datetime_based_cursor(
3059-
state_manager=connector_state_manager,
3060-
model_type=DatetimeBasedCursorModel,
3061-
component_definition=cursor_component_definition,
3062-
stream_name=stream_name,
3063-
stream_namespace=None,
3064-
config=config,
3065-
stream_state=stream_state,
3058+
concurrent_cursor = (
3059+
connector_builder_factory.create_concurrent_cursor_from_datetime_based_cursor(
3060+
state_manager=connector_state_manager,
3061+
model_type=DatetimeBasedCursorModel,
3062+
component_definition=cursor_component_definition,
3063+
stream_name=stream_name,
3064+
stream_namespace=None,
3065+
config=config,
3066+
stream_state=stream_state,
3067+
)
30663068
)
30673069

30683070
assert concurrent_cursor._stream_name == stream_name
@@ -3186,14 +3188,16 @@ def test_create_concurrent_cursor_from_datetime_based_cursor(
31863188
stream_state={},
31873189
)
31883190
else:
3189-
concurrent_cursor = connector_builder_factory.create_concurrent_cursor_from_datetime_based_cursor(
3190-
state_manager=connector_state_manager,
3191-
model_type=DatetimeBasedCursorModel,
3192-
component_definition=cursor_component_definition,
3193-
stream_name=stream_name,
3194-
stream_namespace=None,
3195-
config=config,
3196-
stream_state={},
3191+
concurrent_cursor = (
3192+
connector_builder_factory.create_concurrent_cursor_from_datetime_based_cursor(
3193+
state_manager=connector_state_manager,
3194+
model_type=DatetimeBasedCursorModel,
3195+
component_definition=cursor_component_definition,
3196+
stream_name=stream_name,
3197+
stream_namespace=None,
3198+
config=config,
3199+
stream_state={},
3200+
)
31973201
)
31983202

31993203
assert getattr(concurrent_cursor, assertion_field) == expected_value
@@ -3241,14 +3245,16 @@ def test_create_concurrent_cursor_uses_min_max_datetime_format_if_defined():
32413245
"lookback_window": "P3D",
32423246
}
32433247

3244-
concurrent_cursor = connector_builder_factory.create_concurrent_cursor_from_datetime_based_cursor(
3245-
state_manager=connector_state_manager,
3246-
model_type=DatetimeBasedCursorModel,
3247-
component_definition=cursor_component_definition,
3248-
stream_name=stream_name,
3249-
stream_namespace=None,
3250-
config=config,
3251-
stream_state={},
3248+
concurrent_cursor = (
3249+
connector_builder_factory.create_concurrent_cursor_from_datetime_based_cursor(
3250+
state_manager=connector_state_manager,
3251+
model_type=DatetimeBasedCursorModel,
3252+
component_definition=cursor_component_definition,
3253+
stream_name=stream_name,
3254+
stream_namespace=None,
3255+
config=config,
3256+
stream_state={},
3257+
)
32523258
)
32533259

32543260
assert concurrent_cursor.start == expected_start

0 commit comments

Comments
 (0)