From e2af5b3c7011870543cbfdd5597a1044bc7c297a Mon Sep 17 00:00:00 2001 From: Eevui Date: Thu, 27 Oct 2022 23:58:01 +0800 Subject: [PATCH 1/5] governance_votes: track silver sql --- models/silver/silver__governance_votes.sql | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 models/silver/silver__governance_votes.sql diff --git a/models/silver/silver__governance_votes.sql b/models/silver/silver__governance_votes.sql new file mode 100644 index 0000000..1a542ab --- /dev/null +++ b/models/silver/silver__governance_votes.sql @@ -0,0 +1,61 @@ +{{ config( + materialized = 'incremental', + unique_key = 'tx_id', + incremental_strategy = 'delete+insert' +) }} + +with base_votes as ( + select + tx_id, + block_id, + block_timestamp, + tx_succeeded, + chain_id, + attributes, + _inserted_timestamp + from {{ ref('silver__messages') }} + where message_type = '/cosmos.gov.v1beta1.MsgVote' + and {{ incremental_load_filter('_inserted_timestamp') }} +), + +parsed_votes as ( + select + tx_id, + block_id, + block_timestamp, + tx_succeeded, + chain_id, + attributes:message:sender::text as voter, + attributes:proposal_vote:proposal_id::number as proposal_id, + parse_json(attributes:proposal_vote:option) as parsed_vote_option, + parsed_vote_option:option::number as vote_option, + case vote_option + when 1 then 'Yes' + when 2 then 'Abstain' + when 3 then 'No' + when 4 then 'NoWithVeto' + end as vote_option_text, + parsed_vote_option:weight::number as vote_weight, + 'terra' as blockchain, + _inserted_timestamp + from base_votes +), + +final as ( + select + tx_id, + block_id, + block_timestamp, + blockchain, + chain_id, + voter, + proposal_id, + vote_option, + vote_option_text, + vote_weight, + tx_succeeded, + _inserted_timestamp + from parsed_votes +) + +select * from final From 1f13e859882b8996fbf09458f069cfbaf41dea95 Mon Sep 17 00:00:00 2001 From: Eevui Date: Thu, 27 Oct 2022 23:58:24 +0800 Subject: [PATCH 2/5] governance_votes: track silver docs --- models/descriptions/proposal_id.md | 5 + models/descriptions/vote_option.md | 5 + models/descriptions/vote_option_text.md | 5 + models/descriptions/vote_weight.md | 5 + models/descriptions/voter.md | 5 + models/silver/silver__governance_votes.yml | 133 +++++++++++++++++++++ 6 files changed, 158 insertions(+) create mode 100644 models/descriptions/proposal_id.md create mode 100644 models/descriptions/vote_option.md create mode 100644 models/descriptions/vote_option_text.md create mode 100644 models/descriptions/vote_weight.md create mode 100644 models/descriptions/voter.md create mode 100644 models/silver/silver__governance_votes.yml diff --git a/models/descriptions/proposal_id.md b/models/descriptions/proposal_id.md new file mode 100644 index 0000000..dee6022 --- /dev/null +++ b/models/descriptions/proposal_id.md @@ -0,0 +1,5 @@ +{% docs proposal_id %} + +The ID of the governance proposal that this vote is for. + +{% enddocs %} diff --git a/models/descriptions/vote_option.md b/models/descriptions/vote_option.md new file mode 100644 index 0000000..36af7b9 --- /dev/null +++ b/models/descriptions/vote_option.md @@ -0,0 +1,5 @@ +{% docs vote_option %} + +The numerical vote option cast by the voter. + +{% enddocs %} diff --git a/models/descriptions/vote_option_text.md b/models/descriptions/vote_option_text.md new file mode 100644 index 0000000..b32a4b3 --- /dev/null +++ b/models/descriptions/vote_option_text.md @@ -0,0 +1,5 @@ +{% docs vote_option_text %} + +The human-readable vote option cast by the voter. + +{% enddocs %} diff --git a/models/descriptions/vote_weight.md b/models/descriptions/vote_weight.md new file mode 100644 index 0000000..d8b45e0 --- /dev/null +++ b/models/descriptions/vote_weight.md @@ -0,0 +1,5 @@ +{% docs vote_weight %} + +The weight of the vote cast by the voter. For now, it's always a full vote: `1`. + +{% enddocs %} diff --git a/models/descriptions/voter.md b/models/descriptions/voter.md new file mode 100644 index 0000000..1c53a08 --- /dev/null +++ b/models/descriptions/voter.md @@ -0,0 +1,5 @@ +{% docs voter %} + +The address of the validator or delegator who casted this vote. + +{% enddocs %} diff --git a/models/silver/silver__governance_votes.yml b/models/silver/silver__governance_votes.yml new file mode 100644 index 0000000..5fdfbc9 --- /dev/null +++ b/models/silver/silver__governance_votes.yml @@ -0,0 +1,133 @@ +version: 2 + +models: + - name: silver__governance_votes + description: |- + This table contains votes cast on governance proposals. + + columns: + - name: tx_id + description: "{{ doc('tx_id') }}" + tests: + - unique + - not_null + - relationships: + to: ref('silver__transactions') + field: tx_id + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: block_id + description: "{{ doc('block_id') }}" + tests: + - not_null + - relationships: + to: ref('silver__blocks') + field: block_id + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: block_timestamp + description: "{{ doc('block_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - timestamp_ntz + + - name: blockchain + description: "{{ doc('blockchain') }}" + tests: + - not_null + - accepted_values: + values: + - 'terra' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: chain_id + description: "{{ doc('chain_id') }}" + tests: + - not_null + - accepted_values: + values: + - 'phoenix-1' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: voter + description: "{{ doc('voter') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: proposal_id + description: "{{ doc('proposal_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: vote_option + description: "{{ doc('vote_option') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 1 + max_value: 4 + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: vote_option_text + description: "{{ doc('vote_option_text') }}" + tests: + - not_null + - accepted_values: + values: + - 'Yes' + - 'Abstain' + - 'No' + - 'NoWithVeto' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: vote_weight + description: "{{ doc('vote_weight') }}" + tests: + - not_null + - accepted_values: + values: + - 1 + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: tx_succeeded + description: "{{ doc('tx_succeeded') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - boolean + + - name: _inserted_timestamp + description: "{{ doc('_inserted_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - timestamp_ntz From 453e056a55abf8db52c82820cbe2b8d2ca61eb87 Mon Sep 17 00:00:00 2001 From: Eevui Date: Fri, 28 Oct 2022 00:31:23 +0800 Subject: [PATCH 3/5] governance_votes: add core view --- models/core/core__fact_governance_votes.sql | 11 ++ models/core/core__fact_governance_votes.yml | 133 ++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 models/core/core__fact_governance_votes.sql create mode 100644 models/core/core__fact_governance_votes.yml diff --git a/models/core/core__fact_governance_votes.sql b/models/core/core__fact_governance_votes.sql new file mode 100644 index 0000000..25bc087 --- /dev/null +++ b/models/core/core__fact_governance_votes.sql @@ -0,0 +1,11 @@ +{{ config( + materialized = 'view' +) }} + +with governance_votes as ( + select + * + from {{ ref('silver__governance_votes') }} +) + +select * from governance_votes diff --git a/models/core/core__fact_governance_votes.yml b/models/core/core__fact_governance_votes.yml new file mode 100644 index 0000000..0892bdb --- /dev/null +++ b/models/core/core__fact_governance_votes.yml @@ -0,0 +1,133 @@ +version: 2 + +models: + - name: core__fact_governance_votes + description: |- + This table contains votes cast on governance proposals. + + columns: + - name: tx_id + description: "{{ doc('tx_id') }}" + tests: + - unique + - not_null + - relationships: + to: ref('silver__transactions') + field: tx_id + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: block_id + description: "{{ doc('block_id') }}" + tests: + - not_null + - relationships: + to: ref('silver__blocks') + field: block_id + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: block_timestamp + description: "{{ doc('block_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - timestamp_ntz + + - name: blockchain + description: "{{ doc('blockchain') }}" + tests: + - not_null + - accepted_values: + values: + - 'terra' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: chain_id + description: "{{ doc('chain_id') }}" + tests: + - not_null + - accepted_values: + values: + - 'phoenix-1' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: voter + description: "{{ doc('voter') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: proposal_id + description: "{{ doc('proposal_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: vote_option + description: "{{ doc('vote_option') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 1 + max_value: 4 + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: vote_option_text + description: "{{ doc('vote_option_text') }}" + tests: + - not_null + - accepted_values: + values: + - 'Yes' + - 'Abstain' + - 'No' + - 'NoWithVeto' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - string + - varchar + + - name: vote_weight + description: "{{ doc('vote_weight') }}" + tests: + - not_null + - accepted_values: + values: + - 1 + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + + - name: tx_succeeded + description: "{{ doc('tx_succeeded') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - boolean + + - name: _inserted_timestamp + description: "{{ doc('_inserted_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - timestamp_ntz From 482df321435adcb9e433542c9979ada44256556c Mon Sep 17 00:00:00 2001 From: Eevui Date: Fri, 28 Oct 2022 11:09:33 +0800 Subject: [PATCH 4/5] governance_votes: enumerate core view columns --- models/core/core__fact_governance_votes.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/models/core/core__fact_governance_votes.sql b/models/core/core__fact_governance_votes.sql index 25bc087..f77e043 100644 --- a/models/core/core__fact_governance_votes.sql +++ b/models/core/core__fact_governance_votes.sql @@ -4,7 +4,18 @@ with governance_votes as ( select - * + tx_id, + block_id, + block_timestamp, + blockchain, + chain_id, + voter, + proposal_id, + vote_option, + vote_option_text, + vote_weight, + tx_succeeded, + _inserted_timestamp from {{ ref('silver__governance_votes') }} ) From b3d196d0372fe69f6a44f6b3d27e4312e0664eb5 Mon Sep 17 00:00:00 2001 From: Eevui Date: Fri, 28 Oct 2022 14:29:10 +0800 Subject: [PATCH 5/5] governance_votes: remove _inserted_timestamp from core view --- models/core/core__fact_governance_votes.sql | 3 +-- models/core/core__fact_governance_votes.yml | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/models/core/core__fact_governance_votes.sql b/models/core/core__fact_governance_votes.sql index f77e043..c873021 100644 --- a/models/core/core__fact_governance_votes.sql +++ b/models/core/core__fact_governance_votes.sql @@ -14,8 +14,7 @@ with governance_votes as ( vote_option, vote_option_text, vote_weight, - tx_succeeded, - _inserted_timestamp + tx_succeeded from {{ ref('silver__governance_votes') }} ) diff --git a/models/core/core__fact_governance_votes.yml b/models/core/core__fact_governance_votes.yml index 0892bdb..4e63bd6 100644 --- a/models/core/core__fact_governance_votes.yml +++ b/models/core/core__fact_governance_votes.yml @@ -124,10 +124,3 @@ models: column_type_list: - boolean - - name: _inserted_timestamp - description: "{{ doc('_inserted_timestamp') }}" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - timestamp_ntz