Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions logical_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,8 @@ func nativeFromDecimalBytes(fn toNativeFn, precision, scale int) toNativeFn {
}
i := big.NewInt(0)
fromSignedBytes(i, bs)
if i.BitLen() > 64 {
// Avro spec specifies we return underlying type if the logicalType is invalid
return d, b, err
}
r := big.NewRat(i.Int64(), int64(math.Pow10(scale)))
r := new(big.Rat)
r.SetFrac(i, big.NewInt(int64(math.Pow10(scale))))
return r, b, nil
}
}
Expand Down
7 changes: 7 additions & 0 deletions logical_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func TestDecimalBytesLogicalTypeEncode(t *testing.T) {
testBinaryCodecPass(t, schema, big.NewRat(617, 50), []byte("\x04\x04\xd2"))
testBinaryCodecPass(t, schema, big.NewRat(-617, 50), []byte("\x04\xfb\x2e"))
testBinaryCodecPass(t, schema, big.NewRat(0, 1), []byte("\x02\x00"))
schema0scale := `{"type": "bytes", "logicalType": "decimal", "precision": 100, "scale": 0}`
r1, _ := new(big.Rat).SetString("9223372036854775808") // 2^63
testBinaryCodecPass(t, schema0scale, r1, []byte("\x12\x00\x80\x00\x00\x00\x00\x00\x00\x00"))
r2, _ := new(big.Rat).SetString("18446744073709551615") // 2^64 - 1
testBinaryCodecPass(t, schema0scale, r2, []byte("\x12\x00\xff\xff\xff\xff\xff\xff\xff\xff"))
r3, _ := new(big.Rat).SetString("170141183460469231731687303715884105728")
testBinaryCodecPass(t, schema0scale, r3, []byte("\x22\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"))
}

func TestDecimalFixedLogicalTypeEncode(t *testing.T) {
Expand Down