Skip to content

Commit 3e1ffb0

Browse files
authored
Fix: Syncs shows "0 records" synced when using incremental sync (#282)
1 parent aea02e1 commit 3e1ffb0

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

airbyte/sources/base.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import warnings
66
from pathlib import Path
7-
from typing import TYPE_CHECKING, Any, cast
7+
from typing import TYPE_CHECKING, Any, Optional, cast
88

99
import jsonschema
1010
import pendulum
@@ -222,6 +222,14 @@ def get_available_streams(self) -> list[str]:
222222
"""Get the available streams from the spec."""
223223
return [s.name for s in self.discovered_catalog.streams]
224224

225+
def _get_incremental_stream_names(self) -> list[str]:
226+
"""Get the name of streams that support incremental sync."""
227+
return [
228+
stream.name
229+
for stream in self.discovered_catalog.streams
230+
if SyncMode.incremental in stream.supported_sync_modes
231+
]
232+
225233
def _get_spec(self, *, force_refresh: bool = False) -> ConnectorSpecification:
226234
"""Call spec on the connector.
227235
@@ -624,6 +632,19 @@ def _log_sync_start(
624632
event_type=EventType.SYNC,
625633
)
626634

635+
def _log_incremental_streams(
636+
self,
637+
*,
638+
incremental_streams: Optional[set[str]] = None,
639+
) -> None:
640+
"""Log the streams which are using incremental sync mode."""
641+
log_message = (
642+
"The following streams are currently using incremental sync:\n"
643+
f"{incremental_streams}\n"
644+
"To perform a full refresh, set 'force_full_refresh=True' in 'airbyte.read()' method."
645+
)
646+
print(log_message)
647+
627648
def _log_stream_read_start(self, stream: str) -> None:
628649
print(f"Read started on stream: {stream} at {pendulum.now().format('HH:mm:ss')}...")
629650

@@ -737,6 +758,17 @@ def read(
737758

738759
self._log_sync_start(cache=cache)
739760

761+
# Log incremental stream if incremental streams are known
762+
if state_provider and state_provider.known_stream_names:
763+
# Retrieve set of the known streams support which support incremental sync
764+
incremental_streams = (
765+
set(self._get_incremental_stream_names())
766+
& state_provider.known_stream_names
767+
& set(self.get_selected_streams())
768+
)
769+
if incremental_streams:
770+
self._log_incremental_streams(incremental_streams=incremental_streams)
771+
740772
cache_processor = cache.get_record_processor(
741773
source_name=self.name,
742774
catalog_provider=CatalogProvider(self.configured_catalog),

0 commit comments

Comments
 (0)