Skip to content

Commit

Permalink
Add Global Parent Cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
tolik0 committed Aug 15, 2024
1 parent 95d3c3f commit 0e17388
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.

from typing import Any, Mapping

from airbyte_cdk.sources.declarative.migrations.state_migration import StateMigration


class IssuesChildStreamsStateMigration(StateMigration):
"""
Migrate threads state
"""

def should_migrate(self, stream_state: Mapping[str, Any]) -> bool:
"""
Check if the stream_state should be migrated
:param stream_state: The stream_state to potentially migrate
:return: true if the state is of the expected format and should be migrated. False otherwise.
"""
return "state" not in stream_state and "updated" in stream_state

def migrate(self, stream_state: Mapping[str, Any]) -> Mapping[str, Any]:
"""
Migrate the stream_state. Assumes should_migrate(stream_state) returned True.
:param stream_state: The stream_state to migrate
:return: The migrated stream_state
"""
migrated_stream_state = {"state": {"updated": stream_state["updated"]}, "parent_state": {"issues": {"states": []}}}
return migrated_stream_state
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.72.1
version: 0.51.42
type: DeclarativeSource

definitions:
Expand Down Expand Up @@ -1071,13 +1071,6 @@ definitions:

# Incremental Streams

semi_incremental_retriever:
$ref: "#/definitions/retriever"
record_selector:
$ref: "#/definitions/selector"
record_filter:
condition: "{{ record['updated'] >= stream_slice['start_time'] }}"

incremental_sync:
type: DatetimeBasedCursor
cursor_field: "updated"
Expand All @@ -1094,7 +1087,10 @@ definitions:

semi_incremental_stream:
$ref: "#/definitions/incremental_stream"
retriever: "#/definitions/semi_incremental_retriever"
incremental_sync:
$ref: "#/definitions/incremental_sync"
global_parent_cursor: true
is_client_side_incremental: true

# https://developer.atlassian.com/cloud/jira/software/rest/api-group-board/#api-rest-agile-1-0-board-boardid-issue-get
board_issues_stream:
Expand Down Expand Up @@ -1251,7 +1247,7 @@ definitions:
name: issue_comments
primary_key: "id"
retriever:
$ref: "#/definitions/semi_incremental_stream/retriever"
$ref: "#/definitions/retriever"
partition_router:
type: SubstreamPartitionRouter
parent_stream_configs:
Expand All @@ -1263,9 +1259,12 @@ definitions:
transformations:
- type: AddFields
fields:
- path: [ "issueId" ]
- path: ["issueId"]
value_type: string
value: "{{ stream_slice.issue_id }}"
state_migrations:
- type: CustomStateMigration
class_name: "source_jira.components.issues_child_streams_state_migration.IssuesChildStreamsStateMigration"
$parameters:
path: "issue/{{ stream_slice.issue_id }}/comment"
extract_field: "comments"
Expand All @@ -1276,7 +1275,7 @@ definitions:
name: issue_worklogs
primary_key: "id"
retriever:
$ref: "#/definitions/semi_incremental_stream/retriever"
$ref: "#/definitions/retriever"
partition_router:
type: SubstreamPartitionRouter
parent_stream_configs:
Expand All @@ -1288,14 +1287,16 @@ definitions:
transformations:
- type: AddFields
fields:
- path: [ "issueId" ]
- path: ["issueId"]
value_type: string
value: "{{ stream_slice.issue_id }}"
state_migrations:
- type: CustomStateMigration
class_name: "source_jira.components.issues_child_streams_state_migration.IssuesChildStreamsStateMigration"
$parameters:
path: "issue/{{ stream_slice.issue_id }}/worklog"
extract_field: "worklogs"


streams:
# Full refresh streams

Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/jira.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ The Jira connector should not run into Jira API limitations under normal usage.

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:-----------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 3.2.0 | 2024-08-16 | [38612](https://github.com/airbytehq/airbyte/pull/38612) | Migrate IssueComments and IssueWorklogs streams to low code |
| 3.1.0 | 2024-08-13 | [39558](https://github.com/airbytehq/airbyte/pull/39558) | Ensure config_error when state has improper format |
| 3.0.14 | 2024-08-12 | [43885](https://github.com/airbytehq/airbyte/pull/43885) | Update dependencies |
| 3.0.13 | 2024-08-10 | [43542](https://github.com/airbytehq/airbyte/pull/43542) | Update dependencies |
Expand Down

0 comments on commit 0e17388

Please sign in to comment.