chore: add schema handling in the kafka serializer#66
Merged
Yash Shrivastava (alephys26) merged 4 commits intoMay 25, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the Kafka task’s Avro serialization path by introducing schema parsing/caching and pre-processing JSON payloads to better match hamba/avro’s expectations (notably union tagging and numeric/logical type coercion).
Changes:
- Added Schema Registry schema fetch + parse caching for Avro serialization.
- Added a schema-guided walk to tag nullable unions into Avro’s JSON tagged-union form and coerce JSON numbers into Avro-compatible Go types.
- Minor formatting/whitespace adjustments in the Kafka task struct and producer flush block.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
internal/pkg/pipeline/task/kafka/serializer.go |
Adds schema loading/caching and JSON rewriting (union tagging + number/logical-type coercion) before Avro serialization. |
internal/pkg/pipeline/task/kafka/kafka.go |
Formatting/whitespace-only adjustments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
prasadlohakpure
previously approved these changes
May 25, 2026
Divyanshu Tiwari (divyanshu-tiwari)
previously approved these changes
May 25, 2026
2287aa3
Divyanshu Tiwari (divyanshu-tiwari)
approved these changes
May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces significant improvements to Avro serialization in the Kafka pipeline, specifically addressing the handling of Avro unions and type coercion when serializing JSON data. The main changes include adding schema caching, automatic tagging for Avro unions, and correct type coercion for numbers and logical types. These changes ensure that JSON data is properly transformed to match Avro expectations, improving compatibility and reliability.
Changes
Avro Serialization Improvements:
avroCodecby introducing aloadSchemamethod, which fetches and parses the latest schema for each topic only once, improving performance and consistency. [1] [2]tagUnionsfunction to automatically rewrite untagged unions in JSON to the Avro JSON-tagged form required by thehamba/avrolibrary, ensuring correct serialization of union types.coerceNumberto convertfloat64values (from JSON) into the appropriate Go types for Avro primitive and logical types (e.g.,int32,int64,time.Time,time.Duration), preventing type errors during serialization.pickNonNullBranchandbranchTagNameto support correct tagging and disambiguation of nullable unions.Dependency Updates:
sync,time, andgithub.com/hamba/avro/v2to support schema caching, logical type coercion, and Avro schema parsing.Types of changes
Tests
Tested locally with test pipelines. All suceeded.
Checklist