Skip to content

Commit b5f04c6

Browse files
authored
add/near-encoded-table (#229)
* address encoding for near * removed job * incremental * qualify
1 parent 4e8dad7 commit b5f04c6

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

.github/workflows/dbt_run_hourly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
called_workflow_template:
2525
uses: FlipsideCrypto/analytics-workflow-templates/.github/workflows/dbt_run_template.yml@main
2626
with:
27-
dbt_command: dbt run -s models/silver/hourly_prices+
27+
dbt_command: dbt run -s models/silver/hourly_prices+ models/silver/near
2828
environment: workflow_prod
2929
warehouse: ${{ vars.WAREHOUSE }}
3030
secrets: inherit
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{{ config(
2+
materialized = 'incremental',
3+
unique_key = "near_address"
4+
) }}
5+
6+
WITH log_address AS (
7+
8+
SELECT
9+
DISTINCT receiver_id AS near_address,
10+
CONCAT('0x', SHA2(near_address, 256)) AS addr_encoded,
11+
_inserted_timestamp
12+
FROM
13+
{{ source(
14+
'near_silver',
15+
'logs_s3'
16+
) }}
17+
18+
{% if is_incremental() %}
19+
WHERE
20+
near_address NOT IN (
21+
SELECT
22+
DISTINCT near_address
23+
FROM
24+
{{ this }}
25+
)
26+
AND _inserted_timestamp >= (
27+
SELECT
28+
MAX(_inserted_timestamp) - INTERVAL '24 hours'
29+
FROM
30+
{{ this }}
31+
)
32+
{% endif %}
33+
UNION
34+
SELECT
35+
DISTINCT signer_id AS near_address,
36+
CONCAT('0x', SHA2(near_address, 256)) AS addr_encoded,
37+
_inserted_timestamp
38+
FROM
39+
{{ source(
40+
'near_silver',
41+
'logs_s3'
42+
) }}
43+
44+
{% if is_incremental() %}
45+
WHERE
46+
near_address NOT IN (
47+
SELECT
48+
DISTINCT near_address
49+
FROM
50+
{{ this }}
51+
)
52+
AND _inserted_timestamp >= (
53+
SELECT
54+
MAX(_inserted_timestamp) - INTERVAL '24 hours'
55+
FROM
56+
{{ this }}
57+
)
58+
{% endif %}
59+
)
60+
SELECT
61+
near_address,
62+
addr_encoded,
63+
_inserted_timestamp
64+
FROM
65+
log_address qualify(ROW_NUMBER() over (PARTITION BY near_address
66+
ORDER BY
67+
_inserted_timestamp DESC)) = 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
models:
3+
- name: silver__near_address_encoded
4+
tests:
5+
- dbt_utils.unique_combination_of_columns:
6+
combination_of_columns:
7+
- NEAR_ADDRESS
8+
columns:
9+
- name: ADDR_ENCODED
10+
tests:
11+
- not_null

models/sources.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ sources:
247247
schema: silver
248248
tables:
249249
- name: dex_swaps_s3
250+
- name: logs_s3
250251
- name: osmosis_silver
251252
database: osmosis
252253
schema: silver

0 commit comments

Comments
 (0)