You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Support wrapped primitive types in Avro union fields (#379)
* Fix: Support wrapped primitive types in Avro union fields
Fixes#376
The convertUnionField function was unable to handle wrapped primitive
types in union fields (e.g., {"int": 20474} or {"int.date": 20474}).
This caused serialization errors when users attempted to send data
in this format for union types containing primitives with logical types.
Changes:
- Add getPrimitiveTypeName helper to map Avro schema types to primitive names
- Update convertUnionField to recognize and unwrap wrapped primitive types
- Handle logical type suffixes (e.g., "int.date" -> "int") by stripping suffix
- Return unwrapped primitive values directly (hamba/avro expects unwrapped primitives)
The fix ensures that both wrapped formats work:
- {"int": 20474} -> unwraps to int32(20474)
- {"int.date": 20474} -> strips suffix and unwraps to int32(20474)
Added comprehensive tests to verify the fix works for various primitive types
and union combinations.
* Add test script
* Fix linter issues
* Fix Avro logical union date handling for issue #376
Normalize logical primitive union values to the discriminator format expected by hamba/avro, preventing float64/unknown union errors in nested schemas. Document supported input shapes for logical union fields and add regression coverage for serialize and conversion paths.
* Refine logical union roundtrip regression test
Replace the skipped logical union test with a focused roundtrip assertion that validates deserialize output type/value for date unions, avoiding overlap with serialize-path coverage.
* Address golangci-lint findings in Avro conversion paths
Fix unsafe byte narrowing in bytes conversion with explicit range checks and reduce duplicated logical date schema literals in tests by reusing a shared constant.
* Update CI Go patch version for xk6 build compatibility
Pin GitHub Actions setup-go to 1.25.8 and enable check-latest so go install xk6@latest meets the minimum Go patch requirement during CI builds.
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -636,7 +636,7 @@ The example scripts are available as `test_<format/feature>.js` with more code a
636
636
637
637
## Avro Union Types
638
638
639
-
xk6-kafka uses `hamba/avro` for Avro serialization/deserialization. When working with Avro union types, you can provide union values directly without wrapping them in type-specific objects. For nullable fields, you can use `null` directly. See the [Schema Registry documentation](./docs/schema-registry.md#complex-schemas--manage-union-types) for detailed examples and best practices.
639
+
xk6-kafka uses `hamba/avro` for Avro serialization/deserialization. When working with Avro union types, you can usually provide union values directly without wrapping them in type-specific objects. For nullable fields, you can use `null` directly. For logical primitive unions (for example `int` with `logicalType: "date"`), direct values and wrapped values like `{ "int": 20474 }` or `{ "int.date": 20474 }` are supported and normalized before encoding. See the [Schema Registry documentation](./docs/schema-registry.md#complex-schemas--manage-union-types) for detailed examples and best practices.
0 commit comments