forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 8
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 : Mgramseva expense stream incremental #115
Closed
avirajsingh7
wants to merge
1
commit into
upgrade-cdk/mgramseva
from
feat/mgram/expense-stream-incremental
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
airbyte-integrations/connectors/source-mgramseva/integration_tests/sample_state.json
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"todo-stream-name": { | ||
"todo-field-name": "value" | ||
"mgramseva_tenant_expenses": { | ||
"toDate": "2024-08-09" | ||
} | ||
} |
90 changes: 45 additions & 45 deletions
90
airbyte-integrations/connectors/source-mgramseva/poetry.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
}, | ||
"data": { | ||
"type": "object" | ||
}, | ||
"toDate":{ | ||
"type": "string" | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
import pytz | ||
from airbyte_cdk.models import SyncMode | ||
from airbyte_cdk.sources import AbstractSource | ||
from airbyte_cdk.sources.streams import Stream | ||
from airbyte_cdk.sources.streams import Stream, CheckpointMixin | ||
from airbyte_cdk.sources.streams.http import HttpStream | ||
from airbyte_cdk.sources.streams.core import StreamData | ||
|
||
|
@@ -216,12 +216,15 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp | |
expenses["toDate"] = self.month_end.strftime("%Y-%m-%d") | ||
combined_string = f"{self.tenantid}{expenses['fromDate']}{expenses['toDate']}" | ||
id_hash = hashlib.sha256(combined_string.encode()) | ||
return [{"data": expenses, "id": id_hash.hexdigest()}] | ||
return [{"data": expenses, "id": id_hash.hexdigest(),"toDate":expenses["toDate"]}] | ||
|
||
|
||
class MgramsevaTenantExpenses(MgramsevaStream): | ||
class MgramsevaTenantExpenses(MgramsevaStream, CheckpointMixin): | ||
"""object for tenant payments""" | ||
|
||
cursor_field = "toDate" | ||
_cursor_value = None | ||
|
||
def __init__( | ||
self, headers: dict, request_info: dict, user_request: dict, tenantid_list: list, fromdate: datetime, todate: datetime, **kwargs | ||
): # pylint: disable=super-init-not-called | ||
|
@@ -234,8 +237,20 @@ def __init__( | |
self.request_info = request_info | ||
self.user_request = user_request | ||
self.tenantid_list = tenantid_list | ||
self.fromdate = fromdate | ||
self.todate = todate | ||
self.fromdate = fromdate.replace(hour=0, minute=0, second=0, microsecond=0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to fetch record on month basis |
||
self.todate = todate.replace(hour=0, minute=0, second=0, microsecond=0) | ||
|
||
@property | ||
def state(self) -> Mapping[str, Any]: | ||
if self._cursor_value: | ||
return {self.cursor_field: str(self._cursor_value)} | ||
else: | ||
return {self.cursor_field: str(self.fromdate)} | ||
|
||
@state.setter | ||
def state(self, value: Mapping[str, Any]): | ||
if self.cursor_field in value: | ||
self._cursor_value = value[self.cursor_field] | ||
|
||
def read_records( | ||
self, | ||
|
@@ -248,25 +263,30 @@ def read_records( | |
|
||
for tenantid in self.tenantid_list: | ||
|
||
month_start = self.fromdate.replace(day=1) | ||
state_value = self.state[self.cursor_field] | ||
|
||
while month_start < self.todate: | ||
month_start = datetime.fromisoformat(state_value).replace(day=1) | ||
|
||
next_month_start = month_start + relativedelta(months=1) - timedelta(milliseconds=1) | ||
to_date = self.todate.replace(day=1) | ||
|
||
while month_start < to_date: | ||
|
||
next_month_start = month_start + relativedelta(months=1) | ||
stream = MgramsevaTenantExpense( | ||
"echallan-services/eChallan/v1/_expenseDashboard", | ||
self.headers, | ||
self.request_info, | ||
self.user_request, | ||
tenantid, | ||
month_start, | ||
next_month_start, | ||
next_month_start - timedelta(milliseconds=1), | ||
"ExpenseDashboard", | ||
) | ||
yield from stream.read_records(sync_mode, cursor_field, stream_slice, stream_state) | ||
|
||
for record in stream.read_records(sync_mode, cursor_field, stream_slice, stream_state): | ||
yield record | ||
month_start = next_month_start | ||
|
||
self._cursor_value = str(self.todate.replace(day=1)) | ||
|
||
|
||
class MgramsevaPayments(MgramsevaStream): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we must have cursor field in schema