Skip to content

Commit

Permalink
_sdc_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianswms committed Dec 18, 2024
1 parent 9e63da4 commit ce00aa3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion meltano.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins:
- name: secret_key
sensitive: true
- name: start_date
kind: integer
kind: date_iso8601
loaders:
- name: target-jsonl
variant: andyh1203
Expand Down
7 changes: 7 additions & 0 deletions tap_calltrackingmetrics/schemas/call.json
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,13 @@
}
}
}
},
"_sdc_timestamp": {
"type": [
"string",
"null"
],
"format": "date-time"
}
}
}
20 changes: 11 additions & 9 deletions tap_calltrackingmetrics/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CallStream(PaginatedCallTrackingMetricsStream):
path = "/api/v1/accounts/{_sdc_account_id}/calls"
records_jsonpath = "$.calls[*]"
primary_keys: t.ClassVar[list[str]] = ["id"]
replication_key = "unix_time"
replication_key = "_sdc_timestamp"
schema_filepath = SCHEMAS_DIR / "call.json"
parent_stream_type = AccountStream

Expand All @@ -64,16 +64,18 @@ def get_url_params(
next_page_token: t.Any | None,
) -> dict[str, t.Any]:
params = super().get_url_params(context, next_page_token)
starting_replication_key_value = self.get_starting_replication_key_value(
context
) or self.config.get("start_date")
if "start_date" not in params and starting_replication_key_value is not None:
start_date = datetime.datetime.fromtimestamp(
starting_replication_key_value, tz=datetime.timezone.utc
).strftime("%Y-%m-%d")
params["start_date"] = start_date
starting_timestamp = self.get_starting_timestamp(context)
if starting_timestamp is not None:
params["start_date"] = starting_timestamp.strftime("%Y-%m-%d")
return params

def post_process(self, row: types.Record, context: types.Context | None) -> types.Record:
row = super().post_process(row, context)
row["_sdc_timestamp"] = datetime.datetime.fromtimestamp(
row["unix_time"], tz=datetime.timezone.utc
).isoformat()
return row

def get_child_context(
self,
record: types.Record,
Expand Down
4 changes: 2 additions & 2 deletions tap_calltrackingmetrics/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class TapCallTrackingMetrics(Tap):
),
th.Property(
"start_date",
th.IntegerType,
th.DateTimeType,
required=False,
title="Start Date",
description="Formatted as a Unix timestamp.",
description="The earliest record to sync.",
),
).to_dict()

Expand Down

0 comments on commit ce00aa3

Please sign in to comment.