Skip to content

Commit ddfa815

Browse files
zeroshadekou
authored andcommitted
GH-40733: [Go] Require Go 1.21 or later (#40848)
### Rationale for this change Bumping to require Go 1.21 or later as 1.20 is EOL * GitHub Issue: #40733 Authored-by: Matt Topol <zotthewizard@gmail.com> Signed-off-by: Matt Topol <zotthewizard@gmail.com>
1 parent 6b473cb commit ddfa815

16 files changed

Lines changed: 193 additions & 188 deletions

File tree

arrow/bitutil/bitutil.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package bitutil
1919
import (
2020
"math"
2121
"math/bits"
22-
"reflect"
2322
"unsafe"
2423

2524
"github.com/apache/arrow/go/v16/arrow/memory"
@@ -99,8 +98,6 @@ func countSetBitsWithOffset(buf []byte, offset, n int) int {
9998
count := 0
10099

101100
beg := offset
102-
end := offset + n
103-
104101
begU8 := roundUp(beg, uint64SizeBits)
105102

106103
init := min(n, begU8-beg)
@@ -110,27 +107,8 @@ func countSetBitsWithOffset(buf []byte, offset, n int) int {
110107
}
111108
}
112109

113-
nU64 := (n - init) / uint64SizeBits
114-
begU64 := begU8 / uint64SizeBits
115-
endU64 := begU64 + nU64
116-
bufU64 := bytesToUint64(buf)
117-
if begU64 < len(bufU64) {
118-
for _, v := range bufU64[begU64:endU64] {
119-
count += bits.OnesCount64(v)
120-
}
121-
}
122-
123-
// FIXME: use a fallback to bits.OnesCount8
124-
// before counting the tail bits.
125-
126-
tail := beg + init + nU64*uint64SizeBits
127-
for i := tail; i < end; i++ {
128-
if BitIsSet(buf, i) {
129-
count++
130-
}
131-
}
132-
133-
return count
110+
begU64 := BytesForBits(int64(beg + init))
111+
return count + CountSetBits(buf[begU64:], 0, n-init)
134112
}
135113

136114
func roundUp(v, f int) int {
@@ -149,15 +127,6 @@ const (
149127
uint64SizeBits = uint64SizeBytes * 8
150128
)
151129

152-
func bytesToUint64(b []byte) []uint64 {
153-
if cap(b) < uint64SizeBytes {
154-
return nil
155-
}
156-
157-
h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
158-
return unsafe.Slice((*uint64)(unsafe.Pointer(h.Data)), cap(b)/uint64SizeBytes)[:len(b)/uint64SizeBytes]
159-
}
160-
161130
var (
162131
// PrecedingBitmask is a convenience set of values as bitmasks for checking
163132
// prefix bits of a byte
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//go:build !go1.20 && !tinygo
17+
//go:build go1.20 || tinygo
1818

19-
package hashing
19+
package bitutil
2020

2121
import (
22-
"reflect"
2322
"unsafe"
2423
)
2524

26-
func hashString(val string, alg uint64) uint64 {
27-
if val == "" {
28-
return Hash([]byte{}, alg)
25+
func bytesToUint64(b []byte) []uint64 {
26+
if len(b) < uint64SizeBytes {
27+
return nil
2928
}
30-
// highly efficient way to get byte slice without copy before
31-
// the introduction of unsafe.StringData in go1.20
32-
// (https://stackoverflow.com/questions/59209493/how-to-use-unsafe-get-a-byte-slice-from-a-string-without-memory-copy)
33-
const MaxInt32 = 1<<31 - 1
34-
buf := (*[MaxInt32]byte)(unsafe.Pointer((*reflect.StringHeader)(
35-
unsafe.Pointer(&val)).Data))[: len(val)&MaxInt32 : len(val)&MaxInt32]
36-
return Hash(buf, alg)
29+
30+
ptr := unsafe.SliceData(b)
31+
if ptr == nil {
32+
return nil
33+
}
34+
35+
return unsafe.Slice((*uint64)(unsafe.Pointer(ptr)),
36+
len(b)/uint64SizeBytes)
3737
}

arrow/cdata/cdata_allocate.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
//go:build go1.20 || tinygo
18+
19+
package cdata
20+
21+
// #include <stdlib.h>
22+
// #include "arrow/c/abi.h"
23+
import "C"
24+
25+
import (
26+
"unsafe"
27+
)
28+
29+
func allocateArrowSchemaArr(n int) (out []CArrowSchema) {
30+
return unsafe.Slice((*CArrowSchema)(C.calloc(C.size_t(n),
31+
C.sizeof_struct_ArrowSchema)), n)
32+
}
33+
34+
func allocateArrowSchemaPtrArr(n int) (out []*CArrowSchema) {
35+
return unsafe.Slice((**CArrowSchema)(C.calloc(C.size_t(n),
36+
C.size_t(unsafe.Sizeof((*CArrowSchema)(nil))))), n)
37+
}
38+
39+
func allocateArrowArrayArr(n int) (out []CArrowArray) {
40+
return unsafe.Slice((*CArrowArray)(C.calloc(C.size_t(n),
41+
C.sizeof_struct_ArrowArray)), n)
42+
}
43+
44+
func allocateArrowArrayPtrArr(n int) (out []*CArrowArray) {
45+
return unsafe.Slice((**CArrowArray)(C.calloc(C.size_t(n),
46+
C.size_t(unsafe.Sizeof((*CArrowArray)(nil))))), n)
47+
}
48+
49+
func allocateBufferPtrArr(n int) (out []*C.void) {
50+
return unsafe.Slice((**C.void)(C.calloc(C.size_t(n),
51+
C.size_t(unsafe.Sizeof((*C.void)(nil))))), n)
52+
}
53+
54+
func allocateBufferSizeArr(n int) (out []C.int64_t) {
55+
return unsafe.Slice((*C.int64_t)(C.calloc(C.size_t(n),
56+
C.sizeof_int64_t)), n)
57+
}

arrow/cdata/cdata_exports.go

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"bytes"
4040
"encoding/binary"
4141
"fmt"
42-
"reflect"
4342
"runtime/cgo"
4443
"strconv"
4544
"strings"
@@ -291,60 +290,6 @@ func (exp *schemaExporter) export(field arrow.Field) {
291290
exp.exportMeta(&field.Metadata)
292291
}
293292

294-
func allocateArrowSchemaArr(n int) (out []CArrowSchema) {
295-
s := (*reflect.SliceHeader)(unsafe.Pointer(&out))
296-
s.Data = uintptr(C.calloc(C.size_t(n), C.sizeof_struct_ArrowSchema))
297-
s.Len = n
298-
s.Cap = n
299-
300-
return
301-
}
302-
303-
func allocateArrowSchemaPtrArr(n int) (out []*CArrowSchema) {
304-
s := (*reflect.SliceHeader)(unsafe.Pointer(&out))
305-
s.Data = uintptr(C.calloc(C.size_t(n), C.size_t(unsafe.Sizeof((*CArrowSchema)(nil)))))
306-
s.Len = n
307-
s.Cap = n
308-
309-
return
310-
}
311-
312-
func allocateArrowArrayArr(n int) (out []CArrowArray) {
313-
s := (*reflect.SliceHeader)(unsafe.Pointer(&out))
314-
s.Data = uintptr(C.calloc(C.size_t(n), C.sizeof_struct_ArrowArray))
315-
s.Len = n
316-
s.Cap = n
317-
318-
return
319-
}
320-
321-
func allocateArrowArrayPtrArr(n int) (out []*CArrowArray) {
322-
s := (*reflect.SliceHeader)(unsafe.Pointer(&out))
323-
s.Data = uintptr(C.calloc(C.size_t(n), C.size_t(unsafe.Sizeof((*CArrowArray)(nil)))))
324-
s.Len = n
325-
s.Cap = n
326-
327-
return
328-
}
329-
330-
func allocateBufferPtrArr(n int) (out []*C.void) {
331-
s := (*reflect.SliceHeader)(unsafe.Pointer(&out))
332-
s.Data = uintptr(C.calloc(C.size_t(n), C.size_t(unsafe.Sizeof((*C.void)(nil)))))
333-
s.Len = n
334-
s.Cap = n
335-
336-
return
337-
}
338-
339-
func allocateBufferSizeArr(n int) (out []C.int64_t) {
340-
s := (*reflect.SliceHeader)(unsafe.Pointer(&out))
341-
s.Data = uintptr(C.calloc(C.size_t(n), C.size_t(unsafe.Sizeof(int64(0)))))
342-
s.Len = n
343-
s.Cap = n
344-
345-
return
346-
}
347-
348293
func (exp *schemaExporter) finish(out *CArrowSchema) {
349294
out.dictionary = nil
350295
if exp.dict != nil {

arrow/compute/exec/span.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package exec
2020

2121
import (
22-
"reflect"
2322
"sync/atomic"
2423
"unsafe"
2524

@@ -250,22 +249,6 @@ func (a *ArraySpan) resizeChildren(i int) {
250249
}
251250
}
252251

253-
// convenience function for populating the offsets buffer from a scalar
254-
// value's size.
255-
func setOffsetsForScalar[T int32 | int64](span *ArraySpan, buf []T, valueSize int64, bufidx int) {
256-
buf[0] = 0
257-
buf[1] = T(valueSize)
258-
259-
b := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
260-
s := (*reflect.SliceHeader)(unsafe.Pointer(&span.Buffers[bufidx].Buf))
261-
s.Data = b.Data
262-
s.Len = 2 * int(unsafe.Sizeof(T(0)))
263-
s.Cap = s.Len
264-
265-
span.Buffers[bufidx].Owner = nil
266-
span.Buffers[bufidx].SelfAlloc = false
267-
}
268-
269252
// FillFromScalar populates this ArraySpan as if it were a 1 length array
270253
// with the single value equal to the passed in Scalar.
271254
func (a *ArraySpan) FillFromScalar(val scalar.Scalar) {

arrow/compute/exec/span_offsets.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
//go:build go1.20 || tinygo
18+
19+
package exec
20+
21+
import (
22+
"unsafe"
23+
)
24+
25+
// convenience function for populating the offsets buffer from a scalar
26+
// value's size.
27+
func setOffsetsForScalar[T int32 | int64](span *ArraySpan, buf []T, valueSize int64, bufidx int) {
28+
buf[0] = 0
29+
buf[1] = T(valueSize)
30+
31+
span.Buffers[bufidx].Buf = unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(buf))),
32+
2*int(unsafe.Sizeof(T(0))))
33+
34+
span.Buffers[bufidx].Owner = nil
35+
span.Buffers[bufidx].SelfAlloc = false
36+
}

arrow/compute/fieldref.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ import (
2020
"errors"
2121
"fmt"
2222
"hash/maphash"
23-
"math/bits"
2423
"reflect"
2524
"strconv"
2625
"strings"
2726
"unicode"
28-
"unsafe"
2927

3028
"github.com/apache/arrow/go/v16/arrow"
3129
"github.com/apache/arrow/go/v16/arrow/array"
@@ -168,21 +166,6 @@ func (f FieldPath) GetColumn(batch arrow.Record) (arrow.Array, error) {
168166
return f.getArray(batch.Columns())
169167
}
170168

171-
func (f FieldPath) hash(h *maphash.Hash) {
172-
raw := (*reflect.SliceHeader)(unsafe.Pointer(&f)).Data
173-
174-
var b []byte
175-
s := (*reflect.SliceHeader)(unsafe.Pointer(&b))
176-
s.Data = raw
177-
if bits.UintSize == 32 {
178-
s.Len = arrow.Int32Traits.BytesRequired(len(f))
179-
} else {
180-
s.Len = arrow.Int64Traits.BytesRequired(len(f))
181-
}
182-
s.Cap = s.Len
183-
h.Write(b)
184-
}
185-
186169
func (f FieldPath) findAll(fields []arrow.Field) []FieldPath {
187170
_, err := f.GetFieldFromSlice(fields)
188171
if err == nil {

arrow/compute/fieldref_hash.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
//go:build go1.20 || tinygo
18+
19+
package compute
20+
21+
import (
22+
"hash/maphash"
23+
"math/bits"
24+
"unsafe"
25+
26+
"github.com/apache/arrow/go/v16/arrow"
27+
)
28+
29+
func (f FieldPath) hash(h *maphash.Hash) {
30+
raw := unsafe.Pointer(unsafe.SliceData(f))
31+
var byteLen int
32+
if bits.UintSize == 32 {
33+
byteLen = arrow.Int32Traits.BytesRequired(len(f))
34+
} else {
35+
byteLen = arrow.Int64Traits.BytesRequired(len(f))
36+
}
37+
38+
h.Write(unsafe.Slice((*byte)(raw), byteLen))
39+
}

arrow/doc.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ array is valid (not null). If the array has no null entries, it is possible to o
3030
3131
# Requirements
3232
33-
Despite the go.mod stating go1.20, everything is able to be built with go1.19 or higher.
34-
3533
To build with tinygo include the noasm build tag.
3634
*/
3735
package arrow

arrow/flight/flightsql/driver/driver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ func (s *SqlTestSuite) TestRowsPrematureCloseDuringNextLoop() {
619619
require.NoError(t, err)
620620
require.Equal(t, int64(rowCount), insertedRows)
621621

622+
time.Sleep(200 * time.Millisecond)
622623
// Do query
623624
const sqlSelectAll = `SELECT id, name, value FROM ` + tableName
624625

0 commit comments

Comments
 (0)