-
Notifications
You must be signed in to change notification settings - Fork 225
Closed
Description
Similar issue to #198
For any field with logicalType decimals, setting a default value, throws an error.
default value ought to encode using field schema...
package main_test
import (
"testing"
"github.com/linkedin/goavro/v2"
)
func TestNewCodec(t *testing.T) {
schema := `{
"type" : "record",
"name" : "schema",
"fields" : [{
"name" : "price",
“type”: [{
“type”: “bytes”,
“scale”: 2,
“precision”: 20,
“connect.version”: 1,
“connect.parameters”: {
“scale”: “2”,
“connect.decimal.precision”: “20”
},
“connect.default”: “AA==“,
“connect.name”: “org.apache.kafka.connect.data.Decimal”,
“logicalType”: “decimal”
}, “null”],
“default”: “\u0000”
}]
}`
_, err := goavro.NewCodec(schema)
if err != nil {
t.Error(err)
}
}
The test fails with Record "schema" field 1 ought to be valid Avro named type: Union item 2 ought to be valid Avro type: Record "*" field "price": default value ought to encode using field schema: cannot transform to bytes, expected *big.Rat, received string
Even if you try to change the schema to have a default type of *big.Rat there is no way to achieve this as the value will never get interpreted as a *big.Int. However, the Avro schema shouldn't have to work with a specific GO type it should be able to handle a default value specified in the same way as a normal avro decimal field.
Metadata
Metadata
Assignees
Labels
No labels