Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ocf/ocf.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func newEncoder(schema avro.Schema, w io.Writer, cfg encoderConfig) (*Encoder, e
return nil, err
}

writer := avro.NewWriter(w, 512, avro.WithWriterConfig(cfg.EncodingConfig))
writer := avro.NewWriter(w, 512, avro.WithWriterConfig(avro.DefaultConfig))
Copy link
Member

Choose a reason for hiding this comment

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

This does not fix anything. It is simple enough for the DefaultConfig to be overridden to change the tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is clearly a bug, easily verified with the provided code above., it's using override config
ocf.NewEncoder(schemaStr, &buf, ocf.WithEncodingConfig(config))

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it's should be immutable
Seems not right:
avro. DefaultConfig = cfg. EncodingCoonfig

Copy link
Member

Choose a reason for hiding this comment

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

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.

buf := &bytes.Buffer{}
e := &Encoder{
writer: writer,
Expand Down Expand Up @@ -438,7 +438,7 @@ func newEncoder(schema avro.Schema, w io.Writer, cfg encoderConfig) (*Encoder, e
return nil, err
}

writer := avro.NewWriter(w, 512, avro.WithWriterConfig(cfg.EncodingConfig))
writer := avro.NewWriter(w, 512, avro.WithWriterConfig(avro.DefaultConfig))
writer.WriteVal(HeaderSchema, header)
if err = writer.Flush(); err != nil {
return nil, err
Expand Down
55 changes: 55 additions & 0 deletions ocf/ocf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1649,3 +1649,58 @@ func TestEncoder_ResetPreservesCodec(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []byte("deflate"), dec2.Metadata()["avro.codec"])
}

type CustomTagTestObject struct {
StringField string `json:"string_field"`
IntField int `json:"int_field"`
}

func TestCustomTagKey(t *testing.T) {
// Define schema matching the json tags
schemaStr := `{
"type": "record",
"name": "CustomTagTestObject",
"fields": [
{"name": "string_field", "type": "string"},
{"name": "int_field", "type": "int"}
]
}`

// Create a Config with TagKey set to "json"
config := avro.Config{
TagKey: "json",
}.Freeze()

// Create a buffer to write the OCF file to
var buf bytes.Buffer

// Create OCF encoder with custom encoding config
enc, err := ocf.NewEncoder(schemaStr, &buf, ocf.WithEncodingConfig(config))
require.NoError(t, err)

// Data to encode
data := CustomTagTestObject{
StringField: "hello",
IntField: 42,
}

// Encode using the OCF encoder
err = enc.Encode(data)
require.NoError(t, err)

// Close the encoder to flush data
err = enc.Close()
require.NoError(t, err)

// Verify the output by decoding
dec, err := ocf.NewDecoder(&buf, ocf.WithDecoderConfig(config))
require.NoError(t, err)

var result CustomTagTestObject
require.True(t, dec.HasNext())
err = dec.Decode(&result)
require.NoError(t, err)

assert.Equal(t, data.StringField, result.StringField)
assert.Equal(t, data.IntField, result.IntField)
}