Skip to content

feat: support auto-create table metadata for bulk writer - #118

Open
v0y4g3r wants to merge 2 commits into
mainfrom
feat/bulk-writer-auto-create
Open

feat: support auto-create table metadata for bulk writer#118
v0y4g3r wants to merge 2 commits into
mainfrom
feat/bulk-writer-auto-create

Conversation

@v0y4g3r

@v0y4g3r v0y4g3r commented Aug 4, 2026

Copy link
Copy Markdown

What's this PR for?

GreptimeDB Enterprise added auto-create table support for Flight bulk inserts (GreptimeTeam/greptimedb-enterprise#845): when the target table does not exist, the server builds a CreateTableExpr from the Arrow schema's field metadata. This PR adds the client-side support for specifying that metadata when creating a bulk writer.

Changes

  • bulk: new WithAutoCreateSchema writer option (NewBulkWriter(ctx, opts...)). Each AutoCreateColumn is matched to a written column by name (exact match first, then sanitized name, so both sanitized and unsanitized tables work) and attached to the Arrow schema as field metadata:
    • greptime:semantic_type = tag / field / timestamp (overridable via TagColumn/FieldColumn/TimestampColumn; defaults to the written table's own schema)
    • greptime:comment (optional)
    • greptime:type (optional; JSON columns are flagged Json automatically)
    • the timestamp column is written non-nullable, as required by the server
    • unmatched or ambiguous spec columns fail fast
  • client.go: new Client.BulkWriteWithOptions (same endpoint selection/health reporting as BulkWrite)
  • table/types: JSON column support in the bulk Arrow converter (mapped to Arrow Binary with UTF-8 bytes, mirroring the Java SDK and the server contract)
  • unit tests for metadata attachment, fallback, and invalid schemas; examples/bulkwrite and README updated

Usage

resp, err := client.BulkWriteWithOptions(ctx, tbl,
    bulk.WithAutoCreateSchema(&bulk.AutoCreateSchema{
        Columns: []bulk.AutoCreateColumn{
            bulk.TagColumn("id"),
            {Name: "host", Comment: "source host"},
            bulk.FieldColumn("temperature"),
            bulk.TimestampColumn("ts"),
        },
    }),
)

Verification

  • go build ./..., go vet ./...
  • go test ./... (89 passed)
  • golangci-lint run ./... (0 issues)

Add a WithAutoCreateSchema writer option so GreptimeDB Enterprise can
auto-create a missing table from the Arrow schema metadata attached to
bulk (Flight) writes. Each column is described by name with its semantic
type (tag/field/timestamp, overridable via TagColumn/FieldColumn/
TimestampColumn), an optional comment, and an optional type override;
unlisted columns fall back to the written table's own schema, the
timestamp column is written non-nullable, and JSON columns are flagged
greptime:type=Json. Unmatched or ambiguous spec columns fail fast, with
exact-name-first then sanitized-name matching for both sanitized and
unsanitized tables.

Expose the option through NewBulkWriter, BulkClient.BulkWriteWithOptions,
and Client.BulkWriteWithOptions, and add JSON column support to the bulk
Arrow converter to match the server contract and the Java SDK.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
Copilot AI lite review requested due to automatic review settings August 4, 2026 08:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds client-side support for GreptimeDB Enterprise’s Flight bulk auto-create-table feature by allowing callers to attach per-column metadata to the Arrow schema produced during bulk writes, plus adds JSON column support in the Arrow converter used by bulk.

Changes:

  • Add bulk writer options (notably bulk.WithAutoCreateSchema) to enrich Arrow field metadata for server-side auto-create during Flight bulk inserts.
  • Add Client.BulkWriteWithOptions / BulkClient.BulkWriteWithOptions to pass writer options through the existing endpoint-selection + health-reporting path.
  • Add JSON column support in the Arrow converter (map JSON to Arrow Binary and encode JSON values as UTF-8 bytes), with new unit tests and documentation/examples.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
table/types/arrow.go Map JSON to Arrow Binary and encode JSON values into binary arrays.
table/types/arrow_test.go Add a unit test validating JSON→Arrow Binary encoding.
bulk/bulk.go Introduce WriterOption, plumb options through writer creation and single-shot bulk writes, and apply auto-create schema enrichment.
bulk/autocreate.go Implement auto-create schema metadata attachment to Arrow field metadata (semantic type, comment, Json type flag, timestamp non-nullable).
bulk/autocreate_test.go Add unit tests for metadata attachment, fallback behavior, and invalid schema handling.
client.go Add Client.BulkWriteWithOptions and route BulkWrite through it.
README.md Document auto-create support and how to enable it.
examples/bulkwrite/README.md Add an auto-create usage section and explain semantic types + JSON handling.
examples/bulkwrite/main.go Update example to demonstrate BulkWriteWithOptions + WithAutoCreateSchema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread table/types/arrow.go
Comment on lines 264 to 273
case *array.BinaryBuilder:
if value == nil {
b.AppendNull()
} else if s, ok := value.ValueData.(*gpbv1.Value_StringValue); ok {
// JSON values are transported as strings (see BuildJSON); store
// their UTF-8 bytes in the binary column.
b.Append([]byte(s.StringValue))
} else {
b.Append(value.GetBinaryValue())
}
Comment thread bulk/autocreate.go
Comment on lines +214 to +220

if len(exactByName) > 0 {
return nil, fmt.Errorf(
"auto-create schema columns %v not found in the written table",
slices.Sorted(maps.Keys(exactByName)),
)
}
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants