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

Cannot set default value for timestamp logical types #198

Open
kdarkhan opened this issue Jan 17, 2020 · 2 comments
Open

Cannot set default value for timestamp logical types #198

kdarkhan opened this issue Jan 17, 2020 · 2 comments
Assignees

Comments

@kdarkhan
Copy link

kdarkhan commented Jan 17, 2020

The same issue as In #122
Creating a new one since got no response there. For any timestamp type with logicalType timestamp-millis, setting default value 0 (not a string), throws an error.

default value ought to encode using field schema...

In the linked ticket it seems people talk about strings being used as default for long timestamp.
Our use case is more valid where default 0 long does not work as expected.
Here is a small test to reproduce the issue.

package main_test

import (
	"testing"

	"github.com/linkedin/goavro/v2"
)

func TestNewCodec(t *testing.T) {
	schema := `{
    "type" : "record",
    "name" : "schema",
    "fields" : [{
        "name" : "timestamp",
        "type" : {
            "type" : "long",
            "logicalType" : "timestamp-millis"
        },
        "default" : 0
    }]
}`
	_, err := goavro.NewCodec(schema)
	if err != nil {
		t.Error(err)
	}
}

The test fails with Record "schema" field "timestamp": default value ought to encode using field schema: cannot transform binary timestamp-millis, expected time.Time, received float64.
The same test does not fail when import path is changed to github.com/linkedin/goavro.

@karrick karrick self-assigned this Jan 17, 2020
@kdarkhan
Copy link
Author

I just updated the issue description with a small proof of concept.

@karrick
Copy link
Contributor

karrick commented Jan 18, 2020

Thanks. That should help.

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

No branches or pull requests

2 participants