Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

fix clickhouse (22.2.x) syntax errors #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dao/clickhouse/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (cl Clickhouse) CreateAccountBalances(balances []dmodels.AccountBalance) (e
return err
}
stmt, err := tx.Prepare(
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_time, acb_account, acb_nonce, acb_general_balance, acb_escrow_balance_active, acb_escrow_balance_share, acb_escrow_debonding_active, acb_escrow_debonding_share, acb_delegations_balance, acb_debonding_delegations_balance, acb_self_delegation_balance , acb_commission_schedule)"+
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_time, acb_account, acb_nonce, acb_general_balance, acb_escrow_balance_active, acb_escrow_balance_share, acb_escrow_debonding_active, acb_escrow_debonding_share, acb_delegations_balance, acb_debonding_delegations_balance, acb_self_delegation_balance , acb_commission_schedule) "+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", dmodels.AccountBalanceTable))
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions dao/clickhouse/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (cl Clickhouse) CreateBlocks(blocks []dmodels.Block) (err error) {
return err
}
stmt, err := tx.Prepare(
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_created_at, blk_hash, blk_proposer_address, blk_validator_hash, blk_epoch)"+
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_created_at, blk_hash, blk_proposer_address, blk_validator_hash, blk_epoch) "+
"VALUES (?, ?, ?, ?, ?, ?)", dmodels.BlocksTable))
if err != nil {
return err
Expand Down Expand Up @@ -64,7 +64,7 @@ func (cl Clickhouse) CreateBlockSignatures(blocks []dmodels.BlockSignature) erro
return err
}
stmt, err := tx.Prepare(
fmt.Sprintf("INSERT INTO %s (blk_lvl, sig_timestamp, sig_block_id_flag, sig_validator_address, sig_blk_signature)"+
fmt.Sprintf("INSERT INTO %s (blk_lvl, sig_timestamp, sig_block_id_flag, sig_validator_address, sig_blk_signature) "+
"VALUES (?, ?, ?, ?, ?)", dmodels.BlockSignaturesTable))
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions dao/clickhouse/migrations/004_block_view.up.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--CREATE VIEW IF NOT EXISTS block_row_view AS
--select * from blocks ANY LEFT JOIN
-- (select blk_lvl, sum(tx_gas_price), sum(tx_fee), count()
--from transactions group by blk_lvl) as s USING blk_lvl ORDER BY blk_lvl DESC;
--from transactions group by blk_lvl) as s USING blk_lvl ORDER BY blk_lvl DESC
-- HERE IS FULL SCAN OF txs table, cause it ordered by hash, not block height
-- SO we have create Materialized view to store ordered data

Expand Down Expand Up @@ -37,6 +37,6 @@ ANY LEFT JOIN
GROUP BY blk_lvl
) AS s USING (blk_lvl)
ORDER BY blk_lvl DESC
)
);

CREATE VIEW IF NOT EXISTS blocks_sig_count AS select blk_lvl, count() sig_count from block_signatures group by blk_lvl;
CREATE VIEW IF NOT EXISTS blocks_sig_count AS select blk_lvl, count() sig_count FROM block_signatures GROUP BY blk_lvl;
8 changes: 4 additions & 4 deletions dao/clickhouse/migrations/008_entity_nodes_view.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-- select tx_receiver, tx_sender, sum(tx_escrow_reclaim_amount) output
-- from transactions
-- where tx_type = 'reclaimescrow' and tx_status = 1
-- group by tx_receiver, tx_sender) remove USING tx_receiver, tx_sender;
-- group by tx_receiver, tx_sender) remove USING tx_receiver, tx_sender
-- ┌─tx_receiver────────────────────────────────────┬─tx_sender──────────────────────────────────────┬────────escrow_since─┬────────input─┬─output─┬──────balance─┐
-- │ oasis1qq0xmq7r0z9sdv02t5j9zs7en3n6574gtg8v9fyt │ oasis1qr07pxep97z79d5qnsvcue85pr924rt34gdguytc │ 2022-02-09 18:26:36 │ 100000000000 │ 0 │ 100000000000 │
-- │ oasis1qp60saapdcrhe5zp3c3zk52r4dcfkr2uyuc5qjxp │ oasis1qqjhx3qsfyevtyxpl58dxnmqrzkl9mceys5kjkux │ 2022-02-12 16:46:46 │ 110900000000 │ 0 │ 110900000000 │
Expand Down Expand Up @@ -40,8 +40,7 @@ AS
from transactions
where tx_type = 'reclaimescrow' and tx_status = 1
group by tx_receiver, tx_sender) remove USING tx_receiver, tx_sender
)

);

CREATE VIEW IF NOT EXISTS entity_active_depositors_counter_view AS
SELECT tx_receiver reg_entity_address, count() depositors_num from entity_depositors_view
Expand Down Expand Up @@ -118,6 +117,7 @@ ANY LEFT JOIN
GROUP BY sig_validator_address
) AS blk USING (reg_consensus_address)
)

-- Memory troubles: try to fix with MVIEW. ALSO: this DDL was changed!
-- CREATE VIEW IF NOT EXISTS entity_nodes_view AS
-- select *
Expand All @@ -141,5 +141,5 @@ ANY LEFT JOIN
-- --Blocks signatures count
-- select sig_validator_address reg_consensus_address, max(sig_timestamp) last_signature_time, count() c_block_signatures
-- from block_signatures
-- group by sig_validator_address) blk USING reg_consensus_address;
-- group by sig_validator_address) blk USING reg_consensus_address

5 changes: 3 additions & 2 deletions dao/clickhouse/migrations/010_validators.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ from (
group by reg_entity_address ) val_lvl USING reg_entity_address) validator
ANY
LEFT JOIN (SELECT acb_account reg_entity_address, acb_escrow_balance_active,
acb_general_balance, acb_escrow_balance_share, acb_escrow_debonding_active,\
acb_general_balance, acb_escrow_balance_share, acb_escrow_debonding_active,
acb_delegations_balance , acb_debonding_delegations_balance ,
acb_self_delegation_balance, acb_commission_schedule ,
depositors_num
Expand All @@ -152,4 +152,5 @@ from (
OR signatures > 0
OR reg_expiration >= (select max(blk_epoch) from blocks)) prep
ANY
LEFT JOIN public_validators USING reg_entity_address; --public validators 134 rows
LEFT JOIN public_validators USING reg_entity_address --public validators 134 rows
;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need the semicolon on the next line here, or else --public validators 134 rows get interpreted as an empty statement.

2 changes: 1 addition & 1 deletion dao/clickhouse/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (cl Clickhouse) CreateRewards(rewards []dmodels.Reward) error {
return err
}
stmt, err := tx.Prepare(
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_epoch, reg_entity_address, acb_account, rwd_amount, rwd_type, created_at)"+
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_epoch, reg_entity_address, acb_account, rwd_amount, rwd_type, created_at) "+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)", dmodels.RewardsTable))
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions dao/clickhouse/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (cl Clickhouse) CreateTransfers(transfers []dmodels.Transaction) error {
}

stmt, err := tx.Prepare(
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_hash, tx_time, tx_hash, tx_amount, tx_escrow_amount, tx_escrow_reclaim_amount, tx_type, tx_status, tx_error, tx_sender, tx_receiver, tx_nonce, tx_fee, tx_gas_limit, tx_gas_price)"+
fmt.Sprintf("INSERT INTO %s (blk_lvl, blk_hash, tx_time, tx_hash, tx_amount, tx_escrow_amount, tx_escrow_reclaim_amount, tx_type, tx_status, tx_error, tx_sender, tx_receiver, tx_nonce, tx_fee, tx_gas_limit, tx_gas_price) "+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", dmodels.TransactionsTable))
if err != nil {
return err
Expand Down Expand Up @@ -77,7 +77,7 @@ func (cl Clickhouse) CreateRegisterNodeTransactions(txs []dmodels.NodeRegistryTr
}

stmt, err := tx.Prepare(
fmt.Sprintf("INSERT INTO %s (blk_lvl, tx_time, tx_hash, reg_id, reg_address, reg_entity_id, reg_entity_address, reg_expiration, reg_p2p_id, reg_consensus_id, reg_consensus_address, reg_physical_address, reg_roles)"+
fmt.Sprintf("INSERT INTO %s (blk_lvl, tx_time, tx_hash, reg_id, reg_address, reg_entity_id, reg_entity_address, reg_expiration, reg_p2p_id, reg_consensus_id, reg_consensus_address, reg_physical_address, reg_roles) "+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", dmodels.RegisterNodeTable))
if err != nil {
return err
Expand Down Expand Up @@ -129,7 +129,7 @@ func (cl Clickhouse) CreateRegisterEntityTransactions(txs []dmodels.EntityRegist
}

stmt, err := tx.Prepare(
fmt.Sprintf("INSERT INTO %s (blk_lvl, tx_time, tx_hash, reg_entity_id, reg_entity_address, reg_nodes)"+
fmt.Sprintf("INSERT INTO %s (blk_lvl, tx_time, tx_hash, reg_entity_id, reg_entity_address, reg_nodes) "+
"VALUES (?, ?, ?, ?, ?, ?)", dmodels.RegisterEntityTable))
if err != nil {
return err
Expand Down