-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source Facebook marketing: Fix duplicating records during insights lo…
…okback period (#13047) Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
- Loading branch information
Showing
8 changed files
with
166 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
airbyte-integrations/connectors/source-facebook-marketing/unit_tests/helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# | ||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
|
||
from typing import Any, MutableMapping | ||
|
||
from airbyte_cdk.models import SyncMode | ||
from airbyte_cdk.sources.streams import Stream | ||
|
||
|
||
def read_full_refresh(stream_instance: Stream): | ||
records = [] | ||
slices = stream_instance.stream_slices(sync_mode=SyncMode.full_refresh) | ||
for slice in slices: | ||
records.extend(list(stream_instance.read_records(stream_slice=slice, sync_mode=SyncMode.full_refresh))) | ||
return records | ||
|
||
|
||
def read_incremental(stream_instance: Stream, stream_state: MutableMapping[str, Any]): | ||
records = [] | ||
stream_instance.state = stream_state | ||
slices = stream_instance.stream_slices(sync_mode=SyncMode.incremental, stream_state=stream_state) | ||
for slice in slices: | ||
records.extend(list(stream_instance.read_records(sync_mode=SyncMode.incremental, stream_slice=slice, stream_state=stream_state))) | ||
stream_state.clear() | ||
stream_state.update(stream_instance.state) | ||
return records | ||
|
||
|
||
class FakeInsightAsyncJobManager: | ||
def __init__(self, jobs, **kwargs): | ||
self.jobs = jobs | ||
|
||
def completed_jobs(self): | ||
yield from self.jobs | ||
|
||
|
||
class FakeInsightAsyncJob: | ||
updated_insights = {} | ||
|
||
@classmethod | ||
def update_insight(cls, date_start, updated_time): | ||
cls.updated_insights[date_start] = updated_time | ||
|
||
def __init__(self, interval, **kwargs): | ||
self.interval = interval | ||
|
||
def get_result(self): | ||
return [self] | ||
|
||
def export_all_data(self): | ||
date_start = str(self.interval.start) | ||
return {"date_start": date_start, "updated_time": self.updated_insights.get(date_start, date_start)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters