-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AN-5459/point transfers api integration (#378)
* point transfers api integration * upd 2 silver models * gha workflow with auth * upd gha workflow * add gha on push config for testing * add print step * chg echo * upd auth.py * rm run on commit from gha * upd model tags * merge 2 silver into 1, add yml, upd gha * upd auth return vals * add exit 1 on failure * upd return on success True * add gha on-run config for final test * add backup default to env_var(JWT) * add backup default to env_var(JWT) - 2 * rm run on commit from gha and upd sql limit for balance call * add yml for evm address model * add evm address threshold test * upd gha workflow * upd per CRs
- Loading branch information
Showing
17 changed files
with
414 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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
24 changes: 24 additions & 0 deletions
24
models/silver/streamline/external/streamline__evm_addresses.yml
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,24 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: streamline__evm_addresses | ||
description: "Table of unique EVM addresses." | ||
data_tests: | ||
- dbt_utils.recency: | ||
datepart: day | ||
field: modified_timestamp | ||
interval: 1 | ||
|
||
columns: | ||
- name: address | ||
tests: | ||
- not_null | ||
- unique | ||
|
||
- name: modified_timestamp | ||
|
||
- name: inserted_timestamp | ||
|
||
- name: evm_addresses_id | ||
|
||
- name: _invocation_id |
9 changes: 9 additions & 0 deletions
9
models/silver/streamline/external/transfers/bronze_api__FR_points_transfers.sql
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,9 @@ | ||
{{ config ( | ||
materialized = 'view', | ||
tags = ['streamline_non_core'] | ||
) }} | ||
|
||
{{ streamline_external_table_FR_query_v2( | ||
model = "points_transfers", | ||
partition_function = "CAST(SPLIT_PART(SPLIT_PART(file_name, '/', 3), '_', 1) AS INTEGER )" | ||
) }} |
9 changes: 9 additions & 0 deletions
9
models/silver/streamline/external/transfers/bronze_api__points_transfers.sql
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,9 @@ | ||
{{ config ( | ||
materialized = 'view', | ||
tags = ['streamline_non_core'] | ||
) }} | ||
|
||
{{ streamline_external_table_query_v2( | ||
model = "points_transfers", | ||
partition_function = "CAST(SPLIT_PART(SPLIT_PART(file_name, '/', 3), '_', 1) AS INTEGER )" | ||
) }} |
102 changes: 102 additions & 0 deletions
102
models/silver/streamline/external/transfers/silver_api__points_transfers.sql
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,102 @@ | ||
-- depends_on: {{ ref('bronze_api__points_transfers') }} | ||
-- depends_on: {{ ref('bronze_api__FR_points_transfers') }} | ||
{{ config( | ||
materialized = 'incremental', | ||
unique_key = "batch_id", | ||
incremental_strategy = 'merge', | ||
merge_exclude_columns = ["inserted_timestamp", "_inserted_timestamp"], | ||
cluster_by = ['modified_timestamp :: DATE', 'from_address'], | ||
post_hook = [ "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION on equality(from_address, to_address)" ], | ||
tags = ['streamline_non_core'] | ||
) }} | ||
|
||
WITH points_transfers_raw AS ( | ||
|
||
SELECT | ||
partition_key, | ||
TO_TIMESTAMP(partition_key) :: DATE AS request_date, | ||
DATA, | ||
_inserted_timestamp | ||
FROM | ||
|
||
{% if is_incremental() %} | ||
{{ ref('bronze_api__points_transfers') }} | ||
WHERE | ||
_inserted_timestamp >= ( | ||
SELECT | ||
MAX(_inserted_timestamp) | ||
FROM | ||
{{ this }} | ||
) | ||
{% else %} | ||
{{ ref('bronze_api__FR_points_transfers') }} | ||
{% endif %} | ||
), | ||
flatten_protocols AS ( | ||
SELECT | ||
partition_key, | ||
request_date, | ||
_inserted_timestamp, | ||
A.value :address :: STRING AS address, | ||
A.value :transfers :: ARRAY AS transfers | ||
FROM | ||
points_transfers_raw, | ||
LATERAL FLATTEN(DATA) A | ||
), | ||
flatten_batches AS ( | ||
SELECT | ||
partition_key, | ||
request_date, | ||
_inserted_timestamp, | ||
address AS from_address, | ||
A.index AS batch_index, | ||
A.value :batchId :: STRING AS batch_id, | ||
A.value :status :: STRING AS batch_status, | ||
A.value :transfers :: ARRAY AS batch_transfers | ||
FROM | ||
flatten_protocols, | ||
LATERAL FLATTEN( | ||
transfers | ||
) A | ||
), | ||
flatten_transfers AS ( | ||
SELECT | ||
partition_key, | ||
request_date, | ||
from_address, | ||
batch_index, | ||
batch_id, | ||
_inserted_timestamp, | ||
A.index AS transfer_index, | ||
A.value :boxes :: NUMBER AS boxes, | ||
A.value :keys :: NUMBER AS keys, | ||
A.value :points :: NUMBER AS points, | ||
A.value :toAddressId :: STRING AS to_address | ||
FROM | ||
flatten_batches, | ||
LATERAL FLATTEN(batch_transfers) A | ||
) | ||
SELECT | ||
request_date, | ||
batch_id, | ||
batch_index, | ||
transfer_index, | ||
from_address, | ||
to_address, | ||
boxes, | ||
keys, | ||
points, | ||
partition_key, | ||
{{ dbt_utils.generate_surrogate_key( | ||
['batch_id', 'transfer_index'] | ||
) }} AS points_transfers_id, | ||
SYSDATE() AS inserted_timestamp, | ||
SYSDATE() AS modified_timestamp, | ||
'{{ invocation_id }}' AS _invocation_id, | ||
_inserted_timestamp | ||
FROM | ||
flatten_transfers | ||
|
||
qualify(ROW_NUMBER() over (PARTITION BY batch_id | ||
ORDER BY | ||
_inserted_timestamp ASC)) = 1 |
57 changes: 57 additions & 0 deletions
57
models/silver/streamline/external/transfers/silver_api__points_transfers.yml
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,57 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: silver_api__points_transfers | ||
description: "Response from the Reward Points API Transfers Endpoint. Logs each response and dedplicates by batch_id. Original _inserted_timestamp preserved as request timestamp." | ||
tests: | ||
- dbt_utils.recency: | ||
datepart: day | ||
field: request_date | ||
interval: 1 | ||
|
||
columns: | ||
- name: partition_key | ||
|
||
- name: request_date | ||
|
||
- name: from_address | ||
tests: | ||
- not_null | ||
|
||
- name: batch_id | ||
tests: | ||
- not_null | ||
|
||
- name: batch_index | ||
tests: | ||
- not_null | ||
|
||
- name: transfer_index | ||
tests: | ||
- not_null | ||
|
||
- name: boxes | ||
tests: | ||
- not_null | ||
|
||
- name: keys | ||
tests: | ||
- not_null | ||
|
||
- name: points | ||
|
||
- name: to_address | ||
tests: | ||
- not_null | ||
|
||
- name: points_transfers_id | ||
tests: | ||
- not_null | ||
- unique | ||
|
||
- name: inserted_timestamp | ||
|
||
- name: modified_timestamp | ||
|
||
- name: _invocation_id | ||
- name: _inserted_timestamp |
32 changes: 32 additions & 0 deletions
32
models/silver/streamline/external/transfers/streamline__points_transfers_realtime.sql
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,32 @@ | ||
{{ config ( | ||
materialized = "view", | ||
post_hook = fsc_utils.if_data_call_function_v2( | ||
func = '{{this.schema}}.udf_bulk_rest_api_v2', | ||
target = "{{this.schema}}.{{this.identifier}}", | ||
params = { | ||
"external_table": "points_transfers", | ||
"sql_limit": "1", | ||
"producer_batch_size": "1", | ||
"worker_batch_size": "1", | ||
"sql_source": "{{this.identifier}}" | ||
} | ||
) | ||
) }} | ||
|
||
|
||
SELECT | ||
DATE_PART('EPOCH', SYSDATE()) :: INTEGER AS partition_key, | ||
{{ target.database }}.live.udf_api( | ||
'GET', | ||
'{Service}/points/dapp/transfer/all', | ||
{ | ||
'Authorization': 'Bearer ' || '{{ env_var("JWT", "") }}', | ||
'Accept': 'application/json', | ||
'Connection': 'keep-alive', | ||
'Content-Type': 'application/json', | ||
'User-Agent': 'Flipside/0.1' | ||
}, | ||
{}, | ||
'Vault/prod/flow/points-api/prod' | ||
) AS request | ||
|
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
Oops, something went wrong.