Skip to main content
Write pipe output to Google BigQuery with fork-aware reorg handling. The target uses the BigQuery Storage Write API with committed streams: one long-lived stream per table, opened lazily on first write and reused for every batch.
@google-cloud/bigquery and @google-cloud/bigquery-storage are optional peer dependencies. Install them alongside the SDK:

bigqueryTarget

TrackedTable: settings:

Fork handling

On a reorg, the target opens an IN_FLIGHT_ROLLBACK row in the sync table, runs DELETE FROM <table> WHERE <blockNumberColumn> BETWEEN safe+1 AND upper on every tracked table in parallel, then marks the rollback complete. If the process dies between the two markers, the next startup re-runs the bounded DELETEs idempotently. See Fork handling for how the finalization watermark is resolved and enforced across targets.

Example

Full runnable example: 16.bigquery.example.ts.

Notes

  • store.insert(table, rows) is synchronous and buffers rows per table; the commit runs once onData returns. It throws immediately if the table is not declared in tables.
  • The default BIGNUMERIC precision holds up to 38 integer digits. uint256 values (e.g. the 2^256-1 “infinite approval” sentinel) overflow it; store the exact decimal as a STRING column, or clamp before insertion.
  • TIMESTAMP columns take INT64 microseconds since epoch on the write path; the Storage Write API JSONWriter does not parse Date objects or ISO strings.
  • The target closes its write streams and any WriterClient it constructed, but leaves client.bigquery and any client.writer you passed in open. Close them yourself if your code continues after pipeTo (see Resource ownership).
  • Driving the target directly without pipeTo requires either settings.state.id or an id passed to write (E0001).