Files
greptimedb/tests-integration
Ning Sun f796889bbd feat(postgres): jsonl COPY FROM STDIN via the arrow-json engine (#10109)
* feat(postgres): Prometheus Remote Write protobuf ingest via COPY FROM STDIN

COPY FROM STDIN WITH (FORMAT promwrite [, version 2] [, <options>])
ingests one Prometheus Remote Write request body over the postgres wire
protocol — a GreptimeDB-specific, binary COPY format (wire format code
1). The payload is byte-for-byte the body a remote-write client POSTs
to /v1/prometheus/write, compression included: buffered until CopyDone
and completed through the exact ingestion core that endpoint runs.

To share that core, the HTTP handlers' ingestion bodies are extracted
into axum-free functions (ingest_remote_write_v1/v2 plus the context
extension stamping), and the HTTP routes become thin wrappers — their
behavior is unchanged, and the copy layer runs the identical decode,
validation, conversion, batched/prepared write paths, per-batch
write-progress accounting and context extensions, under the
connection's regular postgres context.

The WITH options carry what the HTTP endpoint takes as its
content-type/-encoding and query parameters; session-provided values
(database, user) are not repeated:
- version 1|2 (default 1), matching the content-type's proto
- zstd, matching Content-Encoding: zstd (snappy by default)
- physical_table, matching the ?physical_table= parameter
- pipeline_name/pipeline_version, matching the pipeline headers
  (v1 only; for v2 they are accepted and ignored, exactly like the
  HTTP route ignores them)

Table-less like the other ingestion formats; one COPY statement is one
bounded request (shared 64 MiB limit); the row count reports written
rows (v1) or written samples plus histograms (v2). The flush enforces
the frontend's shared request-memory quota (max_in_flight_write_bytes)
— the same limiter the HTTP ingestion protocols use, so COPY cannot
bypass the aggregate budget. Wiring: PostgresServer::with_prom_remote_write
carries the handler, metric-engine flag, validation mode and shared
memory limiter.

e2e: v1 body chunked across CopyData boundaries; v2 samples with
readback; physical_table option routing; garbage-body decode failure
with connection reuse; a tiny-quota regression where a compressed body
whose decompressed size exceeds the budget fails like the HTTP route.

Signed-off-by: Ning Sun <sunning@greptime.com>

* feat(postgres): jsonl COPY FROM STDIN via the arrow-json engine

COPY tbl [(cols)] FROM STDIN WITH (FORMAT jsonl) ingests
newline-delimited JSON objects through arrow-json's incremental
Decoder — the same engine behind file-based COPY ... FROM 'file.json' —
so both COPY routes accept identical data. One JSON object per record;
keys address the targeted columns by name, absent keys become NULL,
and offset-free timestamp strings parse in the session timezone (the
same schema substitution the csv codec makes), like SQL INSERT.

The streaming contract mirrors arrow-csv's exactly (decode returns
consumed bytes; a short read means a full batch), so the parser is a
twin of the csv one: objects may span CopyData chunk boundaries,
records surface in COPY_IN_FLUSH_ROWS batches, and a trailing object
without its newline is accepted. Table-bound like csv (a named table
is required; the column list fixes the target order); no options (the
file format's layout options are writer-side; the reader parses
date-times natively).

The two table-bound codecs share the table path through a small
TableBoundCodec trait (check_column_type + create_parser); csv's
behavior is unchanged.

e2e: chunked object-boundary ingest with absent-key NULLs;
session-timezone parity against SQL INSERT; malformed JSON failure
with table-left-clean and connection recovery.

Signed-off-by: Ning Sun <sunning@greptime.com>

* feat(postgres): address jsonl COPY review — codec names, nullable-aware errors, docs and tests

- `TableBoundCodec::name()` drives the codec name `CopyInState` logs
  instead of the hardcoded "csv"; `table_bound_state` reuses the query
  context `begin_copy_in` created; the csv/jsonl trait impls hold their
  bodies and share one supported-type check.
- jsonl: the decode schema marks every field nullable, so a NULL in a
  non-nullable column is reported by column name instead of arrow-json's
  "unmasked nulls in non-nullable StructArray child" error; errors map
  to 22P02/22P04 by semantics (field value vs. syntax), never XX000; the
  no-op `decode(&[])` EOF signal is gone; a top-level JSON array under
  `FORMAT json` fails with a specific hint instead of `expected { got [`.
- Module docs describe what arrow-json really accepts: numeric strings
  for numeric columns, numeric timestamps taken in the column's unit,
  unknown keys ignored (strict mode stays off so column subsets work).
- Tests: multi-batch sweep through the mid-stream flush path, trailing
  and truncated records, column subset/reorder with extra keys, missing
  and null ts, the `json` alias, error classes.

Signed-off-by: Ning Sun <sunning@greptime.com>

---------

Signed-off-by: Ning Sun <sunning@greptime.com>
2026-11-24 03:53:00 +00:00
..

Setup tests for multiple storage backend

To run the integration test, please copy .env.example to .env in the project root folder and change the values on need.

Take s3 for example. You need to set your S3 bucket, access key id and secret key:

# Settings for s3 test
GT_S3_BUCKET=S3 bucket
GT_S3_REGION=S3 region
GT_S3_ACCESS_KEY_ID=S3 access key id
GT_S3_ACCESS_KEY=S3 secret access key

Run

Execute the following command in the project root folder:

cargo test integration

Test s3 storage:

cargo test s3

Test oss storage:

cargo test oss

Test azblob storage:

cargo test azblob

Setup tests with Kafka wal

To run the integration test, please copy .env.example to .env in the project root folder and change the values on need.

GT_KAFKA_ENDPOINTS = localhost:9092

Setup kafka standalone

cd tests-integration/fixtures

docker compose -f docker-compose.yml up kafka

Setup tests with etcd TLS

This guide explains how to set up and test TLS-enabled etcd connections in GreptimeDB integration tests.

Quick Start

TLS certificates are already at tests-integration/fixtures/etcd-tls-certs/.

  1. Start TLS-enabled etcd:

    cd tests-integration/fixtures
    docker compose up etcd-tls -d
    
  2. Start all services (including etcd-tls):

    cd tests-integration/fixtures
    docker compose up -d --wait
    

Certificate Details

The checked-in certificates include:

  • ca.crt - Certificate Authority certificate
  • server.crt / server-key.pem - Server certificate for etcd-tls service
  • client.crt / client-key.pem - Client certificate for connecting to etcd-tls

The server certificate includes SANs for localhost, etcd-tls, 127.0.0.1, and ::1.

Regenerating Certificates (Optional)

If you need to regenerate the etcd certificates:

# Regenerate certificates (overwrites existing ones)
./scripts/generate-etcd-tls-certs.sh

# Or generate in custom location
./scripts/generate-etcd-tls-certs.sh /path/to/cert/directory

If you need to regenerate the mysql and postgres certificates:

# Regenerate certificates (overwrites existing ones)
./scripts/generate_certs.sh

# Or generate in custom location
./scripts/generate_certs.sh /path/to/cert/directory

Note: The checked-in certificates are for testing purposes only and should never be used in production.