|
4 | 4 |
|
5 | 5 | import copy |
6 | 6 | import json |
| 7 | +import math |
7 | 8 | from datetime import datetime, timedelta, timezone |
8 | 9 | from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union |
9 | 10 | from unittest.mock import patch |
|
43 | 44 | from airbyte_cdk.sources.streams.checkpoint import Cursor |
44 | 45 | from airbyte_cdk.sources.streams.concurrent.cursor import ConcurrentCursor |
45 | 46 | from airbyte_cdk.sources.streams.concurrent.default_stream import DefaultStream |
| 47 | +from airbyte_cdk.sources.streams.concurrent.state_converters.incrementing_count_stream_state_converter import ( |
| 48 | + IncrementingCountStreamStateConverter, |
| 49 | +) |
46 | 50 | from airbyte_cdk.sources.streams.core import StreamData |
47 | 51 | from airbyte_cdk.sources.types import Record, StreamSlice |
48 | 52 | from airbyte_cdk.test.mock_http import HttpMocker, HttpRequest, HttpResponse |
|
230 | 234 | "inject_into": "request_parameter", |
231 | 235 | }, |
232 | 236 | }, |
| 237 | + "incremental_counting_cursor": { |
| 238 | + "type": "IncrementingCountCursor", |
| 239 | + "cursor_field": "id", |
| 240 | + "start_value": 0, |
| 241 | + "start_time_option": { |
| 242 | + "type": "RequestOption", |
| 243 | + "field_name": "since_id", |
| 244 | + "inject_into": "request_parameter", |
| 245 | + }, |
| 246 | + }, |
233 | 247 | "base_stream": {"retriever": {"$ref": "#/definitions/retriever"}}, |
234 | 248 | "base_incremental_stream": { |
235 | 249 | "retriever": { |
|
238 | 252 | }, |
239 | 253 | "incremental_sync": {"$ref": "#/definitions/incremental_cursor"}, |
240 | 254 | }, |
| 255 | + "base_incremental_counting_stream": { |
| 256 | + "retriever": { |
| 257 | + "$ref": "#/definitions/retriever", |
| 258 | + "requester": {"$ref": "#/definitions/requester"}, |
| 259 | + }, |
| 260 | + "incremental_sync": {"$ref": "#/definitions/incremental_counting_cursor"}, |
| 261 | + }, |
241 | 262 | "party_members_stream": { |
242 | 263 | "$ref": "#/definitions/base_incremental_stream", |
243 | 264 | "retriever": { |
|
527 | 548 | }, |
528 | 549 | }, |
529 | 550 | }, |
| 551 | + "incremental_counting_stream": { |
| 552 | + "$ref": "#/definitions/base_incremental_counting_stream", |
| 553 | + "retriever": { |
| 554 | + "$ref": "#/definitions/base_incremental_counting_stream/retriever", |
| 555 | + "record_selector": {"$ref": "#/definitions/selector"}, |
| 556 | + }, |
| 557 | + "$parameters": { |
| 558 | + "name": "incremental_counting_stream", |
| 559 | + "primary_key": "id", |
| 560 | + "path": "/party_members", |
| 561 | + }, |
| 562 | + "schema_loader": { |
| 563 | + "type": "InlineSchemaLoader", |
| 564 | + "schema": { |
| 565 | + "$schema": "https://json-schema.org/draft-07/schema#", |
| 566 | + "type": "object", |
| 567 | + "properties": { |
| 568 | + "id": { |
| 569 | + "description": "The identifier", |
| 570 | + "type": ["null", "string"], |
| 571 | + }, |
| 572 | + "name": { |
| 573 | + "description": "The name of the party member", |
| 574 | + "type": ["null", "string"], |
| 575 | + }, |
| 576 | + }, |
| 577 | + }, |
| 578 | + }, |
| 579 | + }, |
530 | 580 | }, |
531 | 581 | "streams": [ |
532 | 582 | "#/definitions/party_members_stream", |
|
536 | 586 | "#/definitions/arcana_personas_stream", |
537 | 587 | "#/definitions/palace_enemies_stream", |
538 | 588 | "#/definitions/async_job_stream", |
| 589 | + "#/definitions/incremental_counting_stream", |
539 | 590 | ], |
540 | 591 | "check": {"stream_names": ["party_members", "locations"]}, |
541 | 592 | "concurrency_level": { |
@@ -756,6 +807,20 @@ def test_create_concurrent_cursor(): |
756 | 807 | "state_type": "date-range", |
757 | 808 | } |
758 | 809 |
|
| 810 | + incremental_counting_stream = concurrent_streams[7] |
| 811 | + assert isinstance(incremental_counting_stream, DefaultStream) |
| 812 | + incremental_counting_cursor = incremental_counting_stream.cursor |
| 813 | + |
| 814 | + assert isinstance(incremental_counting_cursor, ConcurrentCursor) |
| 815 | + assert isinstance( |
| 816 | + incremental_counting_cursor._connector_state_converter, |
| 817 | + IncrementingCountStreamStateConverter, |
| 818 | + ) |
| 819 | + assert incremental_counting_cursor._stream_name == "incremental_counting_stream" |
| 820 | + assert incremental_counting_cursor._cursor_field.cursor_field_key == "id" |
| 821 | + assert incremental_counting_cursor._start == 0 |
| 822 | + assert incremental_counting_cursor._end_provider() == math.inf |
| 823 | + |
759 | 824 |
|
760 | 825 | def test_check(): |
761 | 826 | """ |
|
0 commit comments