You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ze...@apache.org on 2023/06/06 14:45:13 UTC
[arrow] branch main updated: GH-35911: [Go] Fix method CastToBytes of decimal256Traits (#35912)
This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 4ec231b234 GH-35911: [Go] Fix method CastToBytes of decimal256Traits (#35912)
4ec231b234 is described below
commit 4ec231b23432e9af340ed1a10d914f9bee84aca7
Author: Igor Izvekov <iz...@gmail.com>
AuthorDate: Tue Jun 6 17:45:06 2023 +0300
GH-35911: [Go] Fix method CastToBytes of decimal256Traits (#35912)
### Rationale for this change
### What changes are included in this PR?
### Are these changes tested?
Yes
### Are there any user-facing changes?
Yes
* Closes: #35911
Authored-by: izveigor <iz...@gmail.com>
Signed-off-by: Matt Topol <zo...@gmail.com>
---
go/arrow/type_traits_decimal256.go | 2 +-
go/arrow/type_traits_test.go | 45 ++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/go/arrow/type_traits_decimal256.go b/go/arrow/type_traits_decimal256.go
index b213df32fb..38d26ce100 100644
--- a/go/arrow/type_traits_decimal256.go
+++ b/go/arrow/type_traits_decimal256.go
@@ -59,7 +59,7 @@ func (decimal256Traits) CastToBytes(b []decimal256.Num) []byte {
h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
var res []byte
- s := (*reflect.SliceHeader)(unsafe.Pointer(&b))
+ s := (*reflect.SliceHeader)(unsafe.Pointer(&res))
s.Data = h.Data
s.Len = h.Len * Decimal256SizeBytes
s.Cap = h.Cap * Decimal256SizeBytes
diff --git a/go/arrow/type_traits_test.go b/go/arrow/type_traits_test.go
index 3b9571d3d3..a54d2d7c69 100644
--- a/go/arrow/type_traits_test.go
+++ b/go/arrow/type_traits_test.go
@@ -24,6 +24,7 @@ import (
"github.com/apache/arrow/go/v13/arrow"
"github.com/apache/arrow/go/v13/arrow/decimal128"
+ "github.com/apache/arrow/go/v13/arrow/decimal256"
"github.com/apache/arrow/go/v13/arrow/float16"
)
@@ -133,6 +134,50 @@ func TestDecimal128Traits(t *testing.T) {
}
}
+func TestDecimal256Traits(t *testing.T) {
+ const N = 10
+ nbytes := arrow.Decimal256Traits.BytesRequired(N)
+ b1 := arrow.Decimal256Traits.CastToBytes([]decimal256.Num{
+ decimal256.New(0, 0, 0, 10),
+ decimal256.New(1, 1, 1, 10),
+ decimal256.New(2, 2, 2, 10),
+ decimal256.New(3, 3, 3, 10),
+ decimal256.New(4, 4, 4, 10),
+ decimal256.New(5, 5, 5, 10),
+ decimal256.New(6, 6, 6, 10),
+ decimal256.New(7, 7, 7, 10),
+ decimal256.New(8, 8, 8, 10),
+ decimal256.New(9, 9, 9, 10),
+ })
+
+ b2 := make([]byte, nbytes)
+ for i := 0; i < N; i++ {
+ beg := i * arrow.Decimal256SizeBytes
+ end := (i + 1) * arrow.Decimal256SizeBytes
+ arrow.Decimal256Traits.PutValue(b2[beg:end], decimal256.New(uint64(i), uint64(i), uint64(i), 10))
+ }
+
+ if !reflect.DeepEqual(b1, b2) {
+ v1 := arrow.Decimal256Traits.CastFromBytes(b1)
+ v2 := arrow.Decimal256Traits.CastFromBytes(b2)
+ t.Fatalf("invalid values:\nb1=%v\nb2=%v\nv1=%v\nv2=%v\n", b1, b2, v1, v2)
+ }
+
+ v1 := arrow.Decimal256Traits.CastFromBytes(b1)
+ for i, v := range v1 {
+ if got, want := v, decimal256.New(uint64(i), uint64(i), uint64(i), 10); got != want {
+ t.Fatalf("invalid value[%d]. got=%v, want=%v", i, got, want)
+ }
+ }
+
+ v2 := make([]decimal256.Num, N)
+ arrow.Decimal256Traits.Copy(v2, v1)
+
+ if !reflect.DeepEqual(v1, v2) {
+ t.Fatalf("invalid values:\nv1=%v\nv2=%v\n", v1, v2)
+ }
+}
+
func TestMonthIntervalTraits(t *testing.T) {
const N = 10
b1 := arrow.MonthIntervalTraits.CastToBytes([]arrow.MonthInterval{