converted ripple to metrics cte

This commit is contained in:
San Yong 2025-03-13 22:00:04 +08:00
parent 6092285563
commit 44334efaae

View File

@ -8,7 +8,7 @@ WITH metrics AS (
SELECT
'hedera' AS blockchain,
'tx_count' AS metric,
'query ($network: HederaNetwork!, $dateFormat: String!, $from: ISO8601DateTime, $till: ISO8601DateTime) { hedera(network: $network) { transactions(options: {asc: "date.date"}, date: {since: $from, till: $till}) { date {date(format: $dateFormat) } countBigInt}} }' AS query_text,
'query ($network: HederaNetwork!, $dateFormat: String!, $from: ISO8601DateTime, $till: ISO8601DateTime) { hedera(network: $network) { transactions(options: {asc: "date.date"}, date: {since: $from, till: $till}) { date {date(format: $dateFormat) } countBigInt}} }' AS query_text,
'Count of tx hashes by day' AS description
UNION ALL
SELECT
@ -50,13 +50,13 @@ WITH metrics AS (
SELECT
'hedera' AS blockchain,
'active_users' AS metric,
'query ($network: HederaNetwork!, $from: ISO8601DateTime, $till: ISO8601DateTime) {hedera(network: $network) {transactions(date: {since: $from, till: $till}) { countBigInt(uniq: payer_account)}}}' AS query_text,
'query ($network: HederaNetwork!, $from: ISO8601DateTime, $till: ISO8601DateTime) {hedera(network: $network) {transactions(date: {since: $from, till: $till}) { date: date { date(format: $dateFormat) } countBigInt(uniq: payer_account) } } }' AS query_text,
'distinct counts of payer accounts over the last 30 days' AS description
UNION ALL
SELECT
'ripple' AS blockchain,
'active_users' AS metric,
'' AS query_text,
'query ($network: RippleNetwork!, $from: ISO8601DateTime, $till: ISO8601DateTime) { ripple(network: $network) { transactions( date: {since: $from, till: $till}) { countBigInt(uniq: senders) } } } ' AS query_text,
'distinct counts of senders over the last 30 days' AS description
UNION ALL
SELECT
@ -98,32 +98,24 @@ SELECT
) AS date_day_minus_30,
blockchain,
metric,
CASE
WHEN blockchain = 'ripple'
AND metric = 'tx_count' THEN '{ripple(network: ripple) {transactions(date: {after: "' || date_day || '"}) {countBigInt date {date}}}}'
WHEN blockchain = 'ripple'
AND metric = 'active_users' THEN '{ripple(network: ripple) {transactions(date: {after: "' || date_day_minus_30 || '"}) {countBigInt( uniq: senders) }}}'
ELSE query_text
END AS query_text,
CASE
WHEN blockchain = 'hedera' THEN OBJECT_CONSTRUCT(
'limit',
'1',
'offset',
'0',
'network',
blockchain,
'from',
CASE
WHEN metric = 'active_users' THEN date_day_minus_30
ELSE date_day
END,
'till',
date_day,
'dateFormat',
'%Y-%m-%d'
)
END AS variables,
query_text,
OBJECT_CONSTRUCT(
'limit',
'1',
'offset',
'0',
'network',
blockchain,
'from',
CASE
WHEN metric = 'active_users' THEN date_day_minus_30
ELSE date_day
END,
'till',
date_day,
'dateFormat',
'%Y-%m-%d'
) AS variables,
description
FROM
{{ source(