Skip to content

Commit

Permalink
Fix removed enum fields throwing an error on deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
actgardner committed Apr 16, 2022
1 parent 22e6fef commit 97bdf7e
Show file tree
Hide file tree
Showing 14 changed files with 654 additions and 5 deletions.
6 changes: 3 additions & 3 deletions v10/compiler/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ func (p *irMethod) compileRecord(writer, reader *schema.RecordDefinition) error
func (p *irMethod) compileEnum(writer, reader *schema.EnumDefinition) error {
log("compileEnum()\n writer:\n %v\n---\nreader: %v\n---\n", writer, reader)
p.addLiteral(vm.Read, vm.Long)
errId := p.addError("Unexpected value for enum")
switchId := p.addSwitchStart(len(writer.Symbols()), errId)
if reader != nil {
errId := p.addError("Unexpected value for enum")
switchId := p.addSwitchStart(len(writer.Symbols()), errId)
for i, wSymbol := range writer.Symbols() {
p.addSwitchCase(switchId, i, -1)
rIdx := reader.SymbolIndex(wSymbol)
Expand All @@ -313,8 +313,8 @@ func (p *irMethod) compileEnum(writer, reader *schema.EnumDefinition) error {
p.addLiteral(vm.Halt, typedErrId)
}
}
p.addSwitchEnd(switchId)
}
p.addSwitchEnd(switchId)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions v10/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.17

require (
github.com/golang/snappy v0.0.4
github.com/linkedin/goavro/v2 v2.11.0
github.com/stretchr/testify v1.7.0
github.com/linkedin/goavro/v2 v2.11.1
github.com/stretchr/testify v1.7.1
)

require (
Expand Down
4 changes: 4 additions & 0 deletions v10/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/linkedin/goavro/v2 v2.11.0 h1:AlU/NR32ESbC/dlzbhTjyqybwESupUCc3SrrHg2qdTg=
github.com/linkedin/goavro/v2 v2.11.0/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA=
github.com/linkedin/goavro/v2 v2.11.1 h1:4cuAtbDfqkKnBXp9E+tRkIJGa6W6iAjwonwt8O1f4U0=
github.com/linkedin/goavro/v2 v2.11.1/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
181 changes: 181 additions & 0 deletions v10/test/enum-removed/enum_test_record.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions v10/test/enum-removed/enum_test_record_container.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions v10/test/enum-removed/evolution.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "record",
"name": "EnumTestRecord",
"fields": [
{
"name": "stringField",
"type": "string"
}
]
}
11 changes: 11 additions & 0 deletions v10/test/enum-removed/evolution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"data": {
"stringField": "testString",
"EnumField": "testSymbol2"
},
"expected": {
"stringField": "testString"
}
}
]
Loading

0 comments on commit 97bdf7e

Please sign in to comment.