#9350·greptimedb

Support JSON2 in bulk inserts by expanding JSON on the frontend

Author: v0y4g3rCreated Sep 24, 2026Updated Sep 24, 2026
LabelsC-enhancement

What type of enhancement is this?

Performance, API improvement, Refactor

What does the enhancement do?

Support JSON2 columns in the Arrow Flight bulk-insert path without requiring SDKs to know or construct the JSON2 physical layout. An SDK sends each JSON2 value as one opaque JSON field in its RecordBatch. The frontend looks up the target table metadata, parses/validates the JSON and materializes JSON2 columns into the physical Arrow layout before partitioning and dispatching the batch. The region worker and BulkMemtable then consume a prepared RecordBatch rather than doing JSON2 expansion under region-worker contention.

Today the bulk-insert path forwards client Arrow IPC to datanodes without such a JSON2 conversion. BulkMemtable has JSON2 storage/merge support, but that is not end-to-end Flight bulk-insert support; its bulk conversion path also expects a compatible Arrow schema.

Proposed implementation

  1. Define the SDK → frontend representation for an unexpanded JSON2 column (including null handling), independent of the table-specific JSON2 layout. Keep the initial SDK implementation simple: one field per JSON2 column.
  2. On the frontend, resolve the table metadata and JSON2 settings/type hints, validate and expand those fields into physical Arrow arrays and fields, and build the prepared RecordBatch before partition routing. Preserve all non-JSON2 columns.
  3. Forward the prepared IPC batch to datanodes. Keep worker-side work limited to existing write/WAL/memtable operations; BulkMemtable should handle the JSON2 columns as ordinary, already-materialized Arrow columns. Handle stale frontend metadata versus the region schema explicitly (e.g. retry/reject rather than silently misinterpreting an incompatible layout).
  4. Add end-to-end Flight bulk-insert coverage: JSON2 with different object shapes across batches, nulls, type hints and mismatches, partitioned routing, WAL replay, flush/compaction and readback. Verify that JSON2 parsing/expansion no longer runs on region workers.

Follow-ups (not required for the initial JSON2 bulk-insert support)

  • The row-insert path currently does conversion work inside BulkMemtable; evaluate moving that work earlier (ideally to the frontend) to further reduce region-worker contention, while preserving the datanode-side insert API contract.
  • Once the frontend-based path is working, allow SDKs to perform some JSON2 expansion when beneficial, without making complete knowledge of table-specific layout a prerequisite.

Implementation challenges

  • JSON2 physical schemas may differ across batches as paths appear or types change; preserve the existing alignment and compaction semantics.
  • Define versioning/validation for table metadata changes between frontend preparation and datanode write.
  • Avoid breaking existing bulk inserts, row inserts, and older SDKs.

Relevant code: src/servers/src/grpc/flight.rs, src/frontend/src/instance/grpc.rs, src/operator/src/bulk_insert.rs, src/mito2/src/memtable/time_partition.rs, src/mito2/src/memtable/bulk/part.rs.