Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't specify default values for LogicalType: "decimal" fields #202

Open
shawn-higgins1 opened this issue Feb 20, 2020 · 0 comments · May be fixed by #291
Open

Can't specify default values for LogicalType: "decimal" fields #202

shawn-higgins1 opened this issue Feb 20, 2020 · 0 comments · May be fixed by #291

Comments

@shawn-higgins1
Copy link

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.

rockwotj added a commit to rockwotj/goavro that referenced this issue Dec 17, 2024
@rockwotj rockwotj linked a pull request Dec 17, 2024 that will close this issue
rockwotj added a commit to rockwotj/goavro that referenced this issue Dec 18, 2024
rockwotj added a commit to rockwotj/goavro that referenced this issue Dec 18, 2024
Unlike timestamp types which accepts native values, decimal types must
be big.Rat, which means defaults need to be converted.

This fixes: linkedin#202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant