contract self heal logic (#313)

This commit is contained in:
Sam 2023-11-29 10:28:30 +08:00 committed by GitHub
parent 141f08d996
commit 7d99176fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 4 deletions

View File

@ -41,9 +41,7 @@ WITH base AS (
{% if is_incremental() %}
AND TO_TIMESTAMP_NTZ(_inserted_timestamp) >= (
SELECT
MAX(
_inserted_timestamp
)
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
@ -234,6 +232,7 @@ all_transfers AS (
erc1155_value,
_inserted_timestamp,
event_index,
1 AS intra_event_index,
'erc721_Transfer' AS token_transfer_type,
CONCAT(
_log_id,
@ -256,6 +255,7 @@ all_transfers AS (
erc1155_value,
_inserted_timestamp,
event_index,
1 AS intra_event_index,
'erc1155_TransferSingle' AS token_transfer_type,
CONCAT(
_log_id,
@ -280,6 +280,7 @@ all_transfers AS (
erc1155_value,
_inserted_timestamp,
event_index,
intra_event_index,
'erc1155_TransferBatch' AS token_transfer_type,
CONCAT(
_log_id,
@ -301,6 +302,7 @@ transfer_base AS (
block_timestamp,
tx_hash,
event_index,
intra_event_index,
contract_address,
C.token_name AS project_name,
from_address,
@ -328,6 +330,7 @@ fill_transfers AS (
t.block_timestamp,
t.tx_hash,
t.event_index,
t.intra_event_index,
t.contract_address,
C.token_name AS project_name,
t.from_address,
@ -348,6 +351,25 @@ fill_transfers AS (
WHERE
t.project_name IS NULL
AND C.token_name IS NOT NULL
),
blocks_fill AS (
SELECT
*
FROM
{{ this }}
WHERE
block_number IN (
SELECT
block_number
FROM
fill_transfers
)
AND _log_id NOT IN (
SELECT
_log_id
FROM
fill_transfers
)
)
{% endif %},
final_base AS (
@ -356,6 +378,7 @@ final_base AS (
block_timestamp,
tx_hash,
event_index,
intra_event_index,
contract_address,
project_name,
from_address,
@ -370,12 +393,13 @@ final_base AS (
transfer_base
{% if is_incremental() %}
UNION
UNION ALL
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
intra_event_index,
contract_address,
project_name,
from_address,
@ -388,6 +412,25 @@ SELECT
_inserted_timestamp
FROM
fill_transfers
UNION ALL
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
intra_event_index,
contract_address,
project_name,
from_address,
to_address,
tokenId,
erc1155_value,
event_type,
token_transfer_type,
_log_id,
_inserted_timestamp
FROM
blocks_fill
{% endif %}
)
SELECT
@ -395,6 +438,7 @@ SELECT
block_timestamp,
tx_hash,
event_index,
intra_event_index,
contract_address,
project_name,
from_address,

View File

@ -28,6 +28,12 @@ models:
- not_null
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: EVENT_INDEX
tests:
- not_null
- name: INTRA_EVENT_INDEX
tests:
- not_null
- name: CONTRACT_ADDRESS
tests:
- not_null