Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taps): Allow sort checking to be disabled #730

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions singer_sdk/helpers/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ def increment_state(
latest_record: dict,
replication_key: str,
is_sorted: bool,
check_sorted: bool,
) -> None:
"""Update the state using data from the latest record.

Raises InvalidStreamSortException if is_sorted=True and unsorted
Raises InvalidStreamSortException if is_sorted=True, check_sorted=True and unsorted
data is detected in the stream.
"""
progress_dict = stream_or_partition_state
Expand All @@ -217,7 +218,7 @@ def increment_state(
progress_dict = stream_or_partition_state[PROGRESS_MARKERS]
old_rk_value = to_json_compatible(progress_dict.get("replication_key_value"))
new_rk_value = to_json_compatible(latest_record[replication_key])
if old_rk_value is None or new_rk_value >= old_rk_value:
if old_rk_value is None or new_rk_value >= old_rk_value or not check_sorted:
edgarrmondragon marked this conversation as resolved.
Show resolved Hide resolved
progress_dict["replication_key"] = replication_key
progress_dict["replication_key_value"] = new_rk_value
return
Expand Down
16 changes: 13 additions & 3 deletions singer_sdk/streams/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,18 +431,27 @@ def replication_key(self, new_value: str) -> None:

@property
def is_sorted(self) -> bool:
"""Check if stream is sorted.
"""Expect stream to be sorted.

When `True`, incremental streams will attempt to resume if unexpectedly
interrupted.

Returns:
`True` if stream is sorted. Defaults to `False`.
"""
return False

@property
def check_sorted(self) -> bool:
"""Check if stream is sorted.

This setting enables additional checks which may trigger
`InvalidStreamSortException` if records are found which are unsorted.

Returns:
`True` if stream is sorted. Defaults to `False`.
`True` if sorting is checked. Defaults to `True`.
"""
return False
return True

@property
def metadata(self) -> MetadataMapping:
Expand Down Expand Up @@ -676,6 +685,7 @@ def _increment_stream_state(
replication_key=self.replication_key,
latest_record=latest_record,
is_sorted=treat_as_sorted,
check_sorted=self.check_sorted,
)

# Private message authoring methods:
Expand Down