linkedin / linkedin/goavro

Cannot set default value for timestamp logical types

Open
#198 2 comments 2 reactions 1 assignee View on GitHub

@karrick is already working on this.

Since Jan 17, 2020.

Dominant language
Go
Stars
1.1k
Forks
232
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.