Skip to content

Commit

Permalink
Canonicalise schema to avoid issue with reading Avro JSON
Browse files Browse the repository at this point in the history
See linkedin/goavro#198 for details
  • Loading branch information
sixstone-qq committed Nov 18, 2021
1 parent 4e31e25 commit 2acaf9a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sync"

"github.com/Shopify/sarama"
"github.com/heetch/avro"
"github.com/heetch/avro/avroregistry"
goavro "github.com/linkedin/goavro/v2"
"golang.org/x/crypto/ssh/terminal"
Expand Down Expand Up @@ -318,7 +319,15 @@ func (c *coder) makeAvroDecoder(keyOrValue string) func(m json.RawMessage) ([]by
return nil, err
}

inCodec, err := goavro.NewCodec(sch.Schema)
// TODO: Cache schema
t, err := avro.ParseType(sch.Schema)
if err != nil {
return nil, err
}

// Canonicalize the schema to remove default values and logical types
// to work around https://github.com/linkedin/goavro/issues/198
inCodec, err := goavro.NewCodec(t.CanonicalString(0))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2acaf9a

Please sign in to comment.