Skip to content

Commit

Permalink
Fix narrowing conversion bug in timeMicrosFromNative
Browse files Browse the repository at this point in the history
Looks like this issue comes from a regression introduced in linkedin#213.

Fixes linkedin#242.
  • Loading branch information
mihaitodor committed Mar 25, 2022
1 parent 91f8062 commit 75c2b7e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 1 addition & 1 deletion logical_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func timeMicrosFromNative(fn fromNativeFn) fromNativeFn {
return fn(b, val)

case time.Duration:
duration := int32(val.Nanoseconds() / int64(time.Microsecond))
duration := val.Nanoseconds() / int64(time.Microsecond)
return fn(b, duration)

default:
Expand Down
2 changes: 0 additions & 2 deletions logical_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ func TestTimeMicrosLogicalTypeEncode(t *testing.T) {
schema := `{"type": "long", "logicalType": "time-micros"}`
testBinaryDecodeFail(t, schema, []byte(""), "short buffer")
testBinaryEncodeFail(t, schema, "test", "cannot transform to binary time-micros, expected time.Duration")
t.Skip("this test is broken")
testBinaryCodecPass(t, schema, 66904022566*time.Microsecond, []byte("\xcc\xf8\xd2\xbc\xf2\x03"))
}

func TestTimeMicrosLogicalTypeUnionEncode(t *testing.T) {
schema := `{"type": ["null", {"type": "long", "logicalType": "time-micros"}]}`
testBinaryEncodeFail(t, schema, Union("string", "test"), "cannot encode binary union: no member schema types support datum: allowed types: [null long.time-micros]")
t.Skip("this test is broken")
testBinaryCodecPass(t, schema, Union("long.time-micros", 66904022566*time.Microsecond), []byte("\x02\xcc\xf8\xd2\xbc\xf2\x03"))
}
func TestDateLogicalTypeEncode(t *testing.T) {
Expand Down

0 comments on commit 75c2b7e

Please sign in to comment.