You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
outputs {"long_time_micros": 20192000000000}, while the following main.go program
// > go version// go version go1.17.8 darwin/amd64package main
import (
"fmt""log""github.com/linkedin/goavro/v2"
)
var (
schemaJSON=`{ "type": "record", "name": "LongList2", "fields": [ { "default": null, "name": "long_time_micros", "type": [ "null", { "type": "long", "logicalType": "time-micros" } ] } ]}`// message = `{"long_time_micros":{"long":20192000000000}}`avroMessage="\x02\x80\x80揪\x97\t"
)
funcmain() {
varcodec*goavro.Codecvarerrerrorifcodec, err=goavro.NewCodecForStandardJSON(schemaJSON); err!=nil {
log.Fatalf("failed to parse response for schema: %v", err)
}
native, _, err:=codec.NativeFromBinary([]byte(avroMessage))
iferr!=nil {
log.Fatalf("failed to call NativeFromBinary: %v", err)
}
jb, err:=codec.TextualFromNative(nil, native)
iferr!=nil {
log.Fatalf("failed to call TextualFromNative: %v", err)
}
fmt.Println(string(jb))
}
outputs {"long_time_micros":{"long.time-micros":1358741504}} with github.com/linkedin/goavro/v2v2.11.0.
It looks like this is caused by a narrowing conversion here where duration should probably be of type int64, in which case the cast to int32 should be removed. I'm not knowledgeable enough to read the Java code in detail to see if this is the type they use, but I believe the implementation starts here and the tests for it are here.
Note that my go code produces the same output as Java if I remove the int32 cast in timeMicrosFromNative for the time.Duration case. The tests in this package aren't checking this particular edge case.
I'm guessing this is a bug, but please let me know what you think.
The text was updated successfully, but these errors were encountered:
When dealing with logical types, we can't serialise the native
struct emitted by goavro directly to JSON, since that will discard
schema information that `codec.TextualFromNative` uses to produce
the expected JSON.
Also, the tip version of goavro is required because the fix for
this regression linkedin/goavro#242 was
merged, but there isn't a tagged release yet.
Fixesredpanda-data#1161.
When dealing with logical types, we can't serialise the native
struct emitted by goavro directly to JSON, since that will discard
schema information that `codec.TextualFromNative` uses to produce
the expected JSON.
Also, the tip version of goavro is required because the fix for
this regression linkedin/goavro#242 was
merged, but there isn't a tagged release yet.
Fixesredpanda-data#1161.
Given the following schema.avsc
and the following JSON message:
The following
Main.java
programoutputs
{"long_time_micros": 20192000000000}
, while the followingmain.go
programoutputs
{"long_time_micros":{"long.time-micros":1358741504}}
withjackfan.us.kg/linkedin/goavro/v2
v2.11.0
.It looks like this is caused by a narrowing conversion here where
duration
should probably be of typeint64
, in which case the cast toint32
should be removed. I'm not knowledgeable enough to read the Java code in detail to see if this is the type they use, but I believe the implementation starts here and the tests for it are here.Note that my go code produces the same output as Java if I remove the
int32
cast intimeMicrosFromNative
for thetime.Duration
case. The tests in this package aren't checking this particular edge case.I'm guessing this is a bug, but please let me know what you think.
The text was updated successfully, but these errors were encountered: