Skip to content

[avro] Support record unions as JSON (#800) - #814

Open
29shivam wants to merge 1 commit into
ClickHouse:mainfrom
29shivam:fix/800-avro-record-union-json
Open

[avro] Support record unions as JSON (#800)#814
29shivam wants to merge 1 commit into
ClickHouse:mainfrom
29shivam:fix/800-avro-record-union-json

Conversation

@29shivam

@29shivam 29shivam commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #800 (part of #726). Implements the direction from your comment @chernser.

Confluent's Avro converter turns a union of two records ([TypeA, TypeB]) into a Connect union struct (io.confluent.connect.avro.Union) keyed by branch record name. Per your Item 1, the value is kept in this tagged form (which branch it was is preserved) — no serialization change, a ClickHouse JSON column stores it as-is.

Per your Item 2, writing to a JSON column in RowBinary needs input_format_binary_read_json_as_string=1, so the Avro integration harness now routes JSON-target fixtures through a dedicated connector config.

Changes:

  • clickhouse_sink_avro_json.json + SinkConfigs.AVRO_JSON + setupAvroConnectorWithJson — Avro converter with the JSON-as-string setting. avroSchemaTest routes to it when a fixture's target table has a JSON column.
  • AvroRecordUnionJsonTest — asserts the tagged-by-branch JSON serialization of a record union (parses the output; no live ClickHouse needed).
  • Retarget union_two_records from Variant(Tuple, Tuple)JSON and promote it from incompatible/compatible/.
  • CHANGELOG under 1.5.0.

On the two branches you mentioned: this covers the input_format_binary_read_json_as_string=1 (happy) path end to end. For the =0 + JSON-present branch — today the connector throws Writing JSON in binary is not supported yet… I'd like your call on whether that should stay a task failure or route to DLQ before I add that coverage (happy to do it in this PR or a follow-up).

Verification: feature test passes locally the end-to-end Avro→JSON path runs via the integration test in CI.

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

Confluent's Avro converter turns a union of two records (e.g. [TypeA, TypeB])
into a Connect union struct (io.confluent.connect.avro.Union) keyed by branch
record name. Per the maintainer, the value is kept in this tagged form (which
branch it was is preserved); a ClickHouse JSON column stores it as-is.

Writing to a JSON column in RowBinary requires input_format_binary_read_json_as_string=1,
so the Avro integration harness now routes fixtures whose target table has a JSON
column through a new setupAvroConnectorWithJson connector config.

- Add clickhouse_sink_avro_json.json (Avro converter + JSON-as-string setting) and
  SinkConfigs.AVRO_JSON / setupAvroConnectorWithJson; avroSchemaTest routes to it when
  a fixture targets a JSON column.
- Add AvroRecordUnionJsonTest: asserts the tagged-by-branch JSON serialization of a
  record union (no live ClickHouse needed).
- Retarget union_two_records from Variant(Tuple, Tuple) to JSON and promote it from the
  incompatible to the compatible Avro fixtures.
- CHANGELOG entry under 1.5.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Avro] Record Union

1 participant