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

Use generated field name for subchain queries in extract_blocks #14422

Merged
merged 4 commits into from
Nov 2, 2023
Merged
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
21 changes: 11 additions & 10 deletions src/app/extract_blocks/sql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@

module Subchain = struct
let make_sql ~join_condition =
let insert_commas s = Core_kernel.String.concat ~sep:"," s in
let fields = insert_commas Archive_lib.Processor.Block.Fields.names in
let b_fields =
insert_commas
@@ Core_kernel.List.map Archive_lib.Processor.Block.Fields.names
~f:(fun field -> "b." ^ field)
in
Core_kernel.sprintf
{sql| WITH RECURSIVE chain AS (

SELECT id,state_hash,parent_id,parent_hash,creator_id,block_winner_id,snarked_ledger_hash_id,
staking_epoch_data_id,next_epoch_data_id,min_window_density,total_currency,ledger_hash,
height,global_slot_since_hard_fork,global_slot_since_genesis,timestamp,chain_status
SELECT %s
FROM blocks b WHERE b.state_hash = $1

UNION ALL

SELECT b.id,b.state_hash,b.parent_id,b.parent_hash,b.creator_id,b.block_winner_id,b.snarked_ledger_hash_id,
b.staking_epoch_data_id,b.next_epoch_data_id,b.min_window_density,b.total_currency,b.ledger_hash,
b.height,b.global_slot_since_hard_fork,b.global_slot_since_genesis,b.timestamp,b.chain_status
SELECT %s
FROM blocks b

INNER JOIN chain

ON %s
)

SELECT state_hash,parent_id,parent_hash,creator_id,block_winner_id,snarked_ledger_hash_id,
staking_epoch_data_id,next_epoch_data_id,min_window_density,total_currency,ledger_hash,
height,global_slot_since_hard_fork,global_slot_since_genesis,timestamp,chain_status
SELECT %s
FROM chain
|sql}
join_condition
fields b_fields join_condition fields

let query_unparented =
Caqti_request.collect Caqti_type.string Archive_lib.Processor.Block.typ
Expand Down