Skip to content
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

AN-5554/ez actions #385

Merged
merged 17 commits into from
Dec 16, 2024
Prev Previous commit
Next Next commit
actions model v1
  • Loading branch information
gregoriustanleyy committed Dec 5, 2024
commit 79b3ba424dae427bfbc13aaac7f9d13343210152
87 changes: 77 additions & 10 deletions models/silver/actions/silver__actions.sql
Original file line number Diff line number Diff line change
@@ -2,22 +2,38 @@
materialized = 'incremental',
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
unique_key = 'actions_id'
cluster_by = ['block_timestamp::DATE', '_modified_timestamp::DATE'],
unique_key = 'actions_id',
tags = ['actions', 'curated', 'scheduled_core', 'grail']
) }}
-- TODO: add back cluster, SO, incremental predicates, tags
-- TODO: add back SO, incremental predicates
WITH transactions AS (

SELECT
tx_hash,
tx_signer,
tx_receiver,
gas_used AS tx_gas_used,
tx_succeeded
tx_succeeded,
_modified_timestamp
FROM
{{ ref('silver__streamline_transactions_final') }}
WHERE
block_timestamp > CURRENT_DATE - 30
-- TODO add incremental filter
block_timestamp > CURRENT_DATE - 3

{% if var("MANUAL_FIX") %}
WHERE
{{ partition_load_manual('no_buffer') }}
{% else %}
{% if is_incremental() %}
WHERE modified_timestamp >= (
SELECT
MAX(modified_timestamp)
FROM
{{ this }}
)
{% endif %}
{% endif %}
),
receipts AS (
SELECT
@@ -30,15 +46,30 @@ receipts AS (
receipt_actions :predecessor_id :: STRING AS receipt_predecessor_id,
receipt_succeeded,
gas_burnt AS receipt_gas_burnt,
status_value,
receipt_actions,
logs AS receipt_logs,
_partition_by_block_number,
_inserted_timestamp
_inserted_timestamp,
modified_timestamp AS _modified_timestamp
FROM
{{ ref('silver__streamline_receipts_final') }}
WHERE
block_timestamp > CURRENT_DATE - 30
-- TODO add incremental filter

{% if var("MANUAL_FIX") %}
WHERE
{{ partition_load_manual('no_buffer') }}
{% else %}
{% if is_incremental() %}
WHERE _modified_timestamp >= (
SELECT
MAX(_modified_timestamp)
FROM
{{ this }}
)
{% endif %}
{% endif %}
),
join_data AS (
SELECT
@@ -55,6 +86,7 @@ join_data AS (
r.receipt_predecessor_id,
r.receipt_succeeded,
r.receipt_gas_burnt,
r.status_value,
r.receipt_actions,
r.receipt_logs,
r._partition_by_block_number,
@@ -79,7 +111,24 @@ flatten_actions AS (
receipt_predecessor_id,
receipt_succeeded,
receipt_gas_burnt,
IFF(
object_keys(status_value)[0] :: STRING = 'SuccessValue',
OBJECT_INSERT(
status_value,
'SuccessValue',
COALESCE(
TRY_PARSE_JSON(
TRY_BASE64_DECODE_STRING(
GET(status_value, 'SuccessValue')
)
),
GET(status_value, 'SuccessValue')
),
TRUE
),
status_value) as receipt_status_value,
receipt_logs, -- TODO review logs, clean logs?
False AS is_delegated,
INDEX AS action_index,
receipt_actions :receipt :Action :gas_price :: NUMBER AS action_gas_price,
IFF(VALUE = 'CreateAccount', VALUE, object_keys(VALUE) [0] :: STRING) AS action_name,
@@ -112,21 +161,35 @@ flatten_actions AS (
LATERAL FLATTEN(
receipt_actions :receipt :Action :actions :: ARRAY
)
),
flatten_delegated_actions AS (
SELECT
tx_hash,
True AS is_delegated,
object_keys(VALUE)[0] ::STRING AS delegated_action_name,
IFF(
VALUE = 'CreateAccount',
{},
GET(VALUE, object_keys(VALUE) [0] :: STRING)
) AS delegated_action_data
FROM flatten_actions, LATERAL FLATTEN(action_data :delegate_action :actions :: ARRAY)
WHERE action_name = 'Delegate'
)
SELECT
block_id,
block_timestamp,
tx_hash,
fa.tx_hash,
tx_signer,
tx_receiver,
tx_gas_used,
tx_succeeded,
receipt_id,
fa.receipt_id,
receipt_receiver_id,
receipt_signer_id,
receipt_predecessor_id,
receipt_succeeded,
receipt_gas_burnt,
receipt_status_value,
receipt_logs,
action_index,
action_gas_price,
@@ -141,4 +204,8 @@ SELECT
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
flatten_actions
flatten_actions fa
LEFT JOIN flatten_delegated_actions da
ON fa.tx_hash = da.tx_hash
AND fa.action_name = da.delegated_action_name
AND fa.action_data :: STRING = da.delegated_action_data :: STRING