Skip to main content
Beyond PostgreSQL, Squid SDK supports saving indexed data to various destinations including Google BigQuery and filesystem-based datasets (CSV, Parquet, JSON).

BigQuery

Squids can store their data to BigQuery datasets using the @subsquid/bigquery-store package.

Basic Usage

Define and use the Database object as follows:
src/main.ts

Configuration

  • bq is a BigQuery instance. When created without arguments it’ll look at the GOOGLE_APPLICATION_CREDENTIALS environment variable for a path to a JSON with authentication details.
  • dataset is the path to the target dataset.
The dataset must be created prior to running the processor.
  • tables lists the tables that will be created and populated within the dataset. For every field of the tables object an eponymous field of the ctx.store object will be created; calling insert() or insertMany() on such a field will result in data being queued for writing to the corresponding dataset table. The actual writing will be done at the end of the batch in a single transaction, ensuring dataset integrity.
Tables are made out of statically typed columns. For the list of available types, see the BigQuery store reference.

Deploying to SQD Cloud

We discourage uploading any sensitive data with squid code when deploying to SQD Cloud. To pass your credentials JSON to your squid, create a Cloud secret variable populated with its contents:
Then in src/main.ts write the contents to a file:
src/main.ts
Set the GOOGLE_APPLICATION_CREDENTIALS variable and request the secret in the deployment manifest:
squid.yaml

BigQuery Examples

An end-to-end example geared towards local runs can be found in this repo. Look at this branch for an example of a squid made for deployment to SQD Cloud.

BigQuery Troubleshooting

Transaction is aborted due to concurrent update This means that your project has an open session that is updating some of the tables used by the squid. Most commonly, the session is left by a squid itself after an unclean termination. You have two options:
  1. If you are not sure if your squid is the only app that uses sessions to access your BigQuery project, find the faulty session manually and terminate it. See Get a list of your active sessions and Terminate a session by ID.
  2. DANGEROUS If you are absolutely certain that the squid is the only app that uses sessions to access your BigQuery project, you can terminate all the dangling sessions at once.
    Run the following, replacing region-us with your dataset’s region:
    You can also enable abortAllProjectSessionsOnStartup and supply datasetRegion in your database config to perform this operation at startup:
    This method will cause data loss if, at the moment when the squid starts, some other app happens to be writing data anywhere in the project using the sessions mechanism.
Error 413 (Request Entity Too Large) Squid produced too much data per batch per table and BigQuery refused to handle it. Begin by finding out which table causes the issue (e.g. by counting insert() calls), then enable pagination for that table by passing a page size as the third argument of the Table constructor:

Filesystem Datasets

Make sure you understand and use the chunkSizeMb setting and the setForceFlush() store method. Failure to do so may cause the processor to output an empty dataset.

Overview

Squid SDK provides append-only Store interface implementations for saving data to files. The store is designed primarily for offline analytics and supports:
  • CSV files - Using @subsquid/file-store-csv
  • Parquet files - Using @subsquid/file-store-parquet
  • JSON files - Using @subsquid/file-store-json
Files can be persisted either locally or to S3 storage.

Basic Example

Save decoded transfer records to transfers.csv files:
The resulting ./data folder may look like this:
Each of the folders here contains a little over 10 MBytes of data. status.txt contains the height of the last indexed block and its hash.

Data Partitioning

File-based stores always partition datasets along the “block height” dimension, even when it is not in the schema. A new partition is written when either:
  • The internal buffer (size governed by chunkSizeMb) fills up, or
  • There’s a call to setForceFlush() during batch processing
Same failover guarantees as with the Postgres-based store are provided: the processor will roll back to the last successful state after a restart.

Storage Destinations

  • Local filesystem - Using LocalDest class
  • S3-compatible storage - Using S3Dest class for AWS S3, Google Cloud Storage, or other S3-compatible services
For complete filesystem store documentation, see the file-store reference.