diff --git a/go/arrow/array/bufferbuilder_numeric_test.go b/go/arrow/array/bufferbuilder_numeric_test.go index a2205ea4815..7834679ff75 100644 --- a/go/arrow/array/bufferbuilder_numeric_test.go +++ b/go/arrow/array/bufferbuilder_numeric_test.go @@ -21,6 +21,7 @@ import ( "unsafe" "github.com/apache/arrow/go/arrow/memory" + "github.com/apache/arrow/go/arrow/endian" "github.com/stretchr/testify/assert" ) @@ -33,13 +34,25 @@ func TestInt32BufferBuilder(t *testing.T) { bb.AppendValues(exp[:3]) bb.AppendValues(exp[3:]) - expBuf := []byte{ - 0x04, 0x03, 0x02, 0x01, - 0x08, 0x07, 0x06, 0x05, - 0x0c, 0x0b, 0x0a, 0x09, - 0x01, 0x0f, 0x0e, 0x0d, - 0x05, 0x04, 0x03, 0x02, - 0x09, 0x08, 0x07, 0x06, + var expBuf []byte + if endian.IsBigEndian { + expBuf = []byte{ + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x01, + 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, + } + } else { + expBuf = []byte{ + 0x04, 0x03, 0x02, 0x01, + 0x08, 0x07, 0x06, 0x05, + 0x0c, 0x0b, 0x0a, 0x09, + 0x01, 0x0f, 0x0e, 0x0d, + 0x05, 0x04, 0x03, 0x02, + 0x09, 0x08, 0x07, 0x06, + } } assert.Equal(t, expBuf, bb.Bytes(), "unexpected byte values") assert.Equal(t, exp, bb.Values(), "unexpected int32 values") @@ -66,13 +79,25 @@ func TestInt32BufferBuilder_AppendValue(t *testing.T) { bb.AppendValue(v) } - expBuf := []byte{ - 0x04, 0x03, 0x02, 0x01, - 0x08, 0x07, 0x06, 0x05, - 0x0c, 0x0b, 0x0a, 0x09, - 0x01, 0x0f, 0x0e, 0x0d, - 0x05, 0x04, 0x03, 0x02, - 0x09, 0x08, 0x07, 0x06, + var expBuf []byte + if endian.IsBigEndian { + expBuf = []byte{ + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x01, + 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, + } + } else { + expBuf = []byte{ + 0x04, 0x03, 0x02, 0x01, + 0x08, 0x07, 0x06, 0x05, + 0x0c, 0x0b, 0x0a, 0x09, + 0x01, 0x0f, 0x0e, 0x0d, + 0x05, 0x04, 0x03, 0x02, + 0x09, 0x08, 0x07, 0x06, + } } assert.Equal(t, expBuf, bb.Bytes(), "unexpected byte values") assert.Equal(t, exp, bb.Values(), "unexpected int32 values") diff --git a/go/arrow/endian/big.go b/go/arrow/endian/big.go new file mode 100644 index 00000000000..ebd36539db0 --- /dev/null +++ b/go/arrow/endian/big.go @@ -0,0 +1,25 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build s390x + +package endian + +import "encoding/binary" + +var Native = binary.BigEndian + +const IsBigEndian = true diff --git a/go/arrow/endian/little.go b/go/arrow/endian/little.go new file mode 100644 index 00000000000..d98b5c97a9d --- /dev/null +++ b/go/arrow/endian/little.go @@ -0,0 +1,25 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !s390x + +package endian + +import "encoding/binary" + +var Native = binary.LittleEndian + +var IsBigEndian = false diff --git a/go/arrow/math/float64_s390x.go b/go/arrow/math/float64_s390x.go new file mode 100644 index 00000000000..4808228096e --- /dev/null +++ b/go/arrow/math/float64_s390x.go @@ -0,0 +1,23 @@ +// Code generated by type_s390x.go.tmpl. DO NOT EDIT. + +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package math + +func initFloat64Go() { + Float64.sum = sum_float64_go +} diff --git a/go/arrow/math/int64_s390x.go b/go/arrow/math/int64_s390x.go new file mode 100644 index 00000000000..ccf491604ef --- /dev/null +++ b/go/arrow/math/int64_s390x.go @@ -0,0 +1,23 @@ +// Code generated by type_s390x.go.tmpl. DO NOT EDIT. + +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package math + +func initInt64Go() { + Int64.sum = sum_int64_go +} diff --git a/go/arrow/math/math_s390x.go b/go/arrow/math/math_s390x.go new file mode 100644 index 00000000000..4a70753cec8 --- /dev/null +++ b/go/arrow/math/math_s390x.go @@ -0,0 +1,28 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +package math + +func init() { + initGo() +} + +func initGo() { + initFloat64Go() + initInt64Go() + initUint64Go() +} diff --git a/go/arrow/math/type_s390x.go.tmpl b/go/arrow/math/type_s390x.go.tmpl new file mode 100644 index 00000000000..e78c4b2566c --- /dev/null +++ b/go/arrow/math/type_s390x.go.tmpl @@ -0,0 +1,24 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +package math + +{{with .In}} +func init{{.Name}}Go() { + {{.Name}}.sum = sum_{{.Type}}_go +} +{{end}} diff --git a/go/arrow/math/uint64_s390x.go b/go/arrow/math/uint64_s390x.go new file mode 100644 index 00000000000..6cfffe804de --- /dev/null +++ b/go/arrow/math/uint64_s390x.go @@ -0,0 +1,23 @@ +// Code generated by type_s390x.go.tmpl. DO NOT EDIT. + +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package math + +func initUint64Go() { + Uint64.sum = sum_uint64_go +} diff --git a/go/arrow/type_traits_decimal128.go b/go/arrow/type_traits_decimal128.go index debe6c7a47d..7d1177ebe48 100644 --- a/go/arrow/type_traits_decimal128.go +++ b/go/arrow/type_traits_decimal128.go @@ -17,11 +17,11 @@ package arrow import ( - "encoding/binary" "reflect" "unsafe" "github.com/apache/arrow/go/arrow/decimal128" + "github.com/apache/arrow/go/arrow/endian" ) // Decimal128 traits @@ -39,8 +39,8 @@ func (decimal128Traits) BytesRequired(n int) int { return Decimal128SizeBytes * // PutValue func (decimal128Traits) PutValue(b []byte, v decimal128.Num) { - binary.LittleEndian.PutUint64(b[:8], uint64(v.LowBits())) - binary.LittleEndian.PutUint64(b[8:], uint64(v.HighBits())) + endian.Native.PutUint64(b[:8], uint64(v.LowBits())) + endian.Native.PutUint64(b[8:], uint64(v.HighBits())) } // CastFromBytes reinterprets the slice b to a slice of type uint16. diff --git a/go/arrow/type_traits_float16.go b/go/arrow/type_traits_float16.go index f21ea4d3236..1e8239de8eb 100644 --- a/go/arrow/type_traits_float16.go +++ b/go/arrow/type_traits_float16.go @@ -17,11 +17,11 @@ package arrow import ( - "encoding/binary" "reflect" "unsafe" "github.com/apache/arrow/go/arrow/float16" + "github.com/apache/arrow/go/arrow/endian" ) // Float16 traits @@ -39,7 +39,7 @@ func (float16Traits) BytesRequired(n int) int { return Float16SizeBytes * n } // PutValue func (float16Traits) PutValue(b []byte, v float16.Num) { - binary.LittleEndian.PutUint16(b, uint16(v.Uint16())) + endian.Native.PutUint16(b, uint16(v.Uint16())) } // CastFromBytes reinterprets the slice b to a slice of type uint16. diff --git a/go/arrow/type_traits_interval.go b/go/arrow/type_traits_interval.go index fcff1e6fd67..f4f4dfe4f9b 100644 --- a/go/arrow/type_traits_interval.go +++ b/go/arrow/type_traits_interval.go @@ -17,9 +17,10 @@ package arrow import ( - "encoding/binary" "reflect" "unsafe" + + "github.com/apache/arrow/go/arrow/endian" ) var ( @@ -41,7 +42,7 @@ func (monthTraits) BytesRequired(n int) int { return MonthIntervalSizeBytes * n // PutValue func (monthTraits) PutValue(b []byte, v MonthInterval) { - binary.LittleEndian.PutUint32(b, uint32(v)) + endian.Native.PutUint32(b, uint32(v)) } // CastFromBytes reinterprets the slice b to a slice of type MonthInterval. @@ -89,8 +90,8 @@ func (daytimeTraits) BytesRequired(n int) int { return DayTimeIntervalSizeBytes // PutValue func (daytimeTraits) PutValue(b []byte, v DayTimeInterval) { - binary.LittleEndian.PutUint32(b[0:4], uint32(v.Days)) - binary.LittleEndian.PutUint32(b[4:8], uint32(v.Milliseconds)) + endian.Native.PutUint32(b[0:4], uint32(v.Days)) + endian.Native.PutUint32(b[4:8], uint32(v.Milliseconds)) } // CastFromBytes reinterprets the slice b to a slice of type DayTimeInterval. diff --git a/go/arrow/type_traits_numeric.gen.go b/go/arrow/type_traits_numeric.gen.go index f98f4947e25..c4c14d4904a 100644 --- a/go/arrow/type_traits_numeric.gen.go +++ b/go/arrow/type_traits_numeric.gen.go @@ -19,10 +19,11 @@ package arrow // import "github.com/apache/arrow/go/arrow" import ( - "encoding/binary" "math" "reflect" "unsafe" + + "github.com/apache/arrow/go/arrow/endian" ) var ( @@ -58,7 +59,7 @@ func (int64Traits) BytesRequired(n int) int { return Int64SizeBytes * n } // PutValue func (int64Traits) PutValue(b []byte, v int64) { - binary.LittleEndian.PutUint64(b, uint64(v)) + endian.Native.PutUint64(b, uint64(v)) } // CastFromBytes reinterprets the slice b to a slice of type int64. @@ -106,7 +107,7 @@ func (uint64Traits) BytesRequired(n int) int { return Uint64SizeBytes * n } // PutValue func (uint64Traits) PutValue(b []byte, v uint64) { - binary.LittleEndian.PutUint64(b, uint64(v)) + endian.Native.PutUint64(b, uint64(v)) } // CastFromBytes reinterprets the slice b to a slice of type uint64. @@ -154,7 +155,7 @@ func (float64Traits) BytesRequired(n int) int { return Float64SizeBytes * n } // PutValue func (float64Traits) PutValue(b []byte, v float64) { - binary.LittleEndian.PutUint64(b, math.Float64bits(v)) + endian.Native.PutUint64(b, math.Float64bits(v)) } // CastFromBytes reinterprets the slice b to a slice of type float64. @@ -202,7 +203,7 @@ func (int32Traits) BytesRequired(n int) int { return Int32SizeBytes * n } // PutValue func (int32Traits) PutValue(b []byte, v int32) { - binary.LittleEndian.PutUint32(b, uint32(v)) + endian.Native.PutUint32(b, uint32(v)) } // CastFromBytes reinterprets the slice b to a slice of type int32. @@ -250,7 +251,7 @@ func (uint32Traits) BytesRequired(n int) int { return Uint32SizeBytes * n } // PutValue func (uint32Traits) PutValue(b []byte, v uint32) { - binary.LittleEndian.PutUint32(b, uint32(v)) + endian.Native.PutUint32(b, uint32(v)) } // CastFromBytes reinterprets the slice b to a slice of type uint32. @@ -298,7 +299,7 @@ func (float32Traits) BytesRequired(n int) int { return Float32SizeBytes * n } // PutValue func (float32Traits) PutValue(b []byte, v float32) { - binary.LittleEndian.PutUint32(b, math.Float32bits(v)) + endian.Native.PutUint32(b, math.Float32bits(v)) } // CastFromBytes reinterprets the slice b to a slice of type float32. @@ -346,7 +347,7 @@ func (int16Traits) BytesRequired(n int) int { return Int16SizeBytes * n } // PutValue func (int16Traits) PutValue(b []byte, v int16) { - binary.LittleEndian.PutUint16(b, uint16(v)) + endian.Native.PutUint16(b, uint16(v)) } // CastFromBytes reinterprets the slice b to a slice of type int16. @@ -394,7 +395,7 @@ func (uint16Traits) BytesRequired(n int) int { return Uint16SizeBytes * n } // PutValue func (uint16Traits) PutValue(b []byte, v uint16) { - binary.LittleEndian.PutUint16(b, uint16(v)) + endian.Native.PutUint16(b, uint16(v)) } // CastFromBytes reinterprets the slice b to a slice of type uint16. @@ -538,7 +539,7 @@ func (timestampTraits) BytesRequired(n int) int { return TimestampSizeBytes * n // PutValue func (timestampTraits) PutValue(b []byte, v Timestamp) { - binary.LittleEndian.PutUint64(b, uint64(v)) + endian.Native.PutUint64(b, uint64(v)) } // CastFromBytes reinterprets the slice b to a slice of type Timestamp. @@ -586,7 +587,7 @@ func (time32Traits) BytesRequired(n int) int { return Time32SizeBytes * n } // PutValue func (time32Traits) PutValue(b []byte, v Time32) { - binary.LittleEndian.PutUint32(b, uint32(v)) + endian.Native.PutUint32(b, uint32(v)) } // CastFromBytes reinterprets the slice b to a slice of type Time32. @@ -634,7 +635,7 @@ func (time64Traits) BytesRequired(n int) int { return Time64SizeBytes * n } // PutValue func (time64Traits) PutValue(b []byte, v Time64) { - binary.LittleEndian.PutUint64(b, uint64(v)) + endian.Native.PutUint64(b, uint64(v)) } // CastFromBytes reinterprets the slice b to a slice of type Time64. @@ -682,7 +683,7 @@ func (date32Traits) BytesRequired(n int) int { return Date32SizeBytes * n } // PutValue func (date32Traits) PutValue(b []byte, v Date32) { - binary.LittleEndian.PutUint32(b, uint32(v)) + endian.Native.PutUint32(b, uint32(v)) } // CastFromBytes reinterprets the slice b to a slice of type Date32. @@ -730,7 +731,7 @@ func (date64Traits) BytesRequired(n int) int { return Date64SizeBytes * n } // PutValue func (date64Traits) PutValue(b []byte, v Date64) { - binary.LittleEndian.PutUint64(b, uint64(v)) + endian.Native.PutUint64(b, uint64(v)) } // CastFromBytes reinterprets the slice b to a slice of type Date64. @@ -778,7 +779,7 @@ func (durationTraits) BytesRequired(n int) int { return DurationSizeBytes * n } // PutValue func (durationTraits) PutValue(b []byte, v Duration) { - binary.LittleEndian.PutUint64(b, uint64(v)) + endian.Native.PutUint64(b, uint64(v)) } // CastFromBytes reinterprets the slice b to a slice of type Duration. diff --git a/go/arrow/type_traits_numeric.gen.go.tmpl b/go/arrow/type_traits_numeric.gen.go.tmpl index c4a25ee3256..a4c49ea9625 100644 --- a/go/arrow/type_traits_numeric.gen.go.tmpl +++ b/go/arrow/type_traits_numeric.gen.go.tmpl @@ -17,10 +17,11 @@ package arrow // import "github.com/apache/arrow/go/arrow" import ( - "encoding/binary" "math" "reflect" "unsafe" + + "github.com/apache/arrow/go/arrow/endian" ) var ( @@ -45,17 +46,17 @@ func ({{.name}}Traits) BytesRequired(n int) int { return {{.Name}}SizeBytes * n // PutValue func ({{.name}}Traits) PutValue(b []byte, v {{.Type}}) { {{- if eq .Type "float32" -}} - binary.LittleEndian.PutUint32(b, math.Float32bits(v)) + endian.Native.PutUint32(b, math.Float32bits(v)) {{- else if eq .Type "float64" -}} - binary.LittleEndian.PutUint64(b, math.Float64bits(v)) + endian.Native.PutUint64(b, math.Float64bits(v)) {{- else if eq .Size "1" -}} b[0] = byte(v) {{- else if eq .Size "2" -}} - binary.LittleEndian.PutUint16(b, uint16(v)) + endian.Native.PutUint16(b, uint16(v)) {{- else if eq .Size "4" -}} - binary.LittleEndian.PutUint32(b, uint32(v)) + endian.Native.PutUint32(b, uint32(v)) {{- else if eq .Size "8" -}} - binary.LittleEndian.PutUint64(b, uint64(v)) + endian.Native.PutUint64(b, uint64(v)) {{- else -}} panic("invalid type {{.Type}}") {{end}}