Skip to content

Commit

Permalink
feat(parquet-exporter): export blocks, txs and data items to parquet
Browse files Browse the repository at this point in the history
* Add schema for blocks and transactions tables
* Update schema for tags table
* Refactor ParquetExporter to import blocks, transactions and tags from sqlite to duckdb
* Refactor ParquetExporter to export blocks, transactions and tags to parquet
  • Loading branch information
karlprieb committed Sep 26, 2024
1 parent 6242301 commit 874c953
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 95 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion src/database/duckdb/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,46 @@ CREATE TABLE IF NOT EXISTS tags (
height UBIGINT NOT NULL,
id BLOB NOT NULL,
tag_index USMALLINT NOT NULL,
created_at UBIGINT NOT NULL,
created_at UBIGINT,
tag_name BLOB NOT NULL,
tag_value BLOB NOT NULL,
is_data_item BOOLEAN NOT NULL
);

CREATE TABLE IF NOT EXISTS transactions (
id BLOB NOT NULL,
block_transaction_index USMALLINT,
is_data_item BOOLEAN,
target BLOB,
quantity DECIMAL(20,0),
reward DECIMAL(20,0),
signature BLOB,
last_tx BLOB NOT NULL,
data_size UBIGINT,
content_type TEXT,
format UTINYINT,
height UBIGINT NOT NULL,
owner_address BLOB,
data_root BLOB,
parent BLOB,
"offset" UBIGINT,
size UINTEGER,
data_offset UINTEGER,
owner_offset UINTEGER,
owner_size UINTEGER,
owner BLOB,
signature_offset UINTEGER,
signature_size UINTEGER,
signature_type UINTEGER
);

CREATE TABLE IF NOT EXISTS blocks (
indep_hash BLOB,
height UBIGINT NOT NULL,
previous_block BLOB,
nonce BLOB NOT NULL,
hash BLOB NOT NULL,
block_timestamp INTEGER NOT NULL,
tx_count INTEGER NOT NULL,
block_size UINTEGER
);
20 changes: 15 additions & 5 deletions src/routes/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,28 @@ arIoRouter.post(
try {
const { outputDir, startHeight, endHeight, maxFileRows } = req.body;

if (!outputDir || !startHeight || !endHeight || !maxFileRows) {
res.status(400).send('Missing required parameters');
if (
typeof outputDir !== 'string' ||
outputDir.trim() === '' ||
!Number.isInteger(startHeight) ||
startHeight < 0 ||
!Number.isInteger(endHeight) ||
endHeight < 0 ||
!Number.isInteger(maxFileRows) ||
maxFileRows < 0
) {
res.status(400).send('Invalid or missing required parameters');
return;
}

const parquetExporter = await ParquetExporter.create({
log,
duckDbPath: 'data/duckdb/tags.duckdb',
sqliteDbPath: 'data/sqlite/bundles.db',
duckDbPath: 'data/duckdb/db.duckdb',
sqliteBundlesDbPath: 'data/sqlite/bundles.db',
sqliteCoreDbPath: 'data/sqlite/core.db',
});

await parquetExporter.exportDataItemTagsParquet({
await parquetExporter.export({
outputDir,
startHeight,
endHeight,
Expand Down
Loading

0 comments on commit 874c953

Please sign in to comment.