fix: fix Avro Object Container File (OCF) encoding header using defau…#590
fix: fix Avro Object Container File (OCF) encoding header using defau…#590TuSKan wants to merge 2 commits intohamba:mainfrom
Conversation
| } | ||
|
|
||
| writer := avro.NewWriter(w, 512, avro.WithWriterConfig(cfg.EncodingConfig)) | ||
| writer := avro.NewWriter(w, 512, avro.WithWriterConfig(avro.DefaultConfig)) |
There was a problem hiding this comment.
This does not fix anything. It is simple enough for the DefaultConfig to be overridden to change the tag.
There was a problem hiding this comment.
This is clearly a bug, easily verified with the provided code above., it's using override config
ocf.NewEncoder(schemaStr, &buf, ocf.WithEncodingConfig(config))
There was a problem hiding this comment.
I am not arguing that it is not a bug. I am saying that you are making an assumption that DefaultConfig is immutable, and that is not true.
There was a problem hiding this comment.
Maybe it's should be immutable
Seems not right:
avro. DefaultConfig = cfg. EncodingCoonfig
There was a problem hiding this comment.
a) It is a var
b) There is not reason the user should not be allowed to decide what they want the DefaultConfig to be.
OCF Encoder fails when using custom
TagKeyconfigurationDescription
When attempting to use
ocf.NewEncoderwith a customEncodingConfigthat specifies aTagKey(e.g., using "json" tags instead of "avro"), the encoder fails during initialization.This occurs because the
ocfpackage mistakenly applies the user's custom configuration (which looks for the custom tag key) to the internal serialization of the OCF Header. TheHeaderstruct definition relies on standardavrotags, so when the encoder looks for the custom tag (e.g.,json:"magic"), it fails to find it and reports a missing field error.Reproduction Steps
Here is a minimal reproduction case demonstrating the issue:
Error Output
Running the code above results in the following error:
Root Cause
The issue stems from mixing the configuration for the Container (framing/header) and the Payload (user data).
Headerstruct in Go usesavrotags. This must always be encoded using the standard Avro configuration (DefaultConfig).TestObject) may use custom tags (e.g.,json) as configured by the user.Currently,
ocf.NewEncoderappliescfg.EncodingConfigto both.Proposed Fix
The internal
avro.Writerused for the OCF framing should always useavro.DefaultConfigto ensure the Header is written correctly, while the payloadencodershould continue to use the user-provided config.Diff of proposed changes in
ocf/ocf.go: