Skip to content

Commit 029dda6

Browse files
review: switch build constraint to 1.22, use concise range syntax
1 parent 0f39025 commit 029dda6

7 files changed

Lines changed: 38 additions & 38 deletions

File tree

arrow/compute/internal/kernels/vector_sort.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//go:build go1.18
17+
//go:build go1.22
1818

1919
package kernels
2020

@@ -146,8 +146,8 @@ func newFixedSizeBinaryComparator(chunks []arrow.Array, numRows int, vn bool) (c
146146
return nil, fmt.Errorf("%w: expected *array.FixedSizeBinary chunk", arrow.ErrInvalid)
147147
}
148148
w := f0.DataType().(*arrow.FixedSizeBinaryType).ByteWidth
149-
for i := 1; i < len(chunks); i++ {
150-
fi, ok := chunks[i].(*array.FixedSizeBinary)
149+
for _, chunk := range chunks[1:] {
150+
fi, ok := chunk.(*array.FixedSizeBinary)
151151
if !ok {
152152
return nil, fmt.Errorf("%w: expected *array.FixedSizeBinary chunk", arrow.ErrInvalid)
153153
}
@@ -315,7 +315,7 @@ func alignedChunkBoundaries(columns []*arrow.Chunked) ([]int, bool) {
315315
return nil, false
316316
}
317317
offs := make([]int, n+1)
318-
for i := 0; i < n; i++ {
318+
for i := range n {
319319
chunkLength := ch0[i].Len()
320320
for _, col := range columns[1:] {
321321
cj := col.Chunks()
@@ -363,7 +363,7 @@ func sortIndicesSingleColumnChunked(indices []uint64, chunks []arrow.Array, comp
363363
func sortIndicesMultiColumnAlignedChunks(indices []uint64, offs []int, comparators []columnComparator, keys []SortKey, multiComp *multiColumnComparator, tmp []uint64, spanScratch []chunkIndexSpan) {
364364
nChunks := len(offs) - 1
365365
useRadix := len(keys) <= maxRadixSortKeys
366-
for c := 0; c < nChunks; c++ {
366+
for c := range nChunks {
367367
lo, hi := offs[c], offs[c+1]
368368
if useRadix {
369369
radixRecordBatchSortRange(indices, tmp, comparators, keys, 0, lo, hi)
@@ -376,7 +376,7 @@ func sortIndicesMultiColumnAlignedChunks(indices []uint64, offs []int, comparato
376376
}
377377
less := func(a, b uint64) bool { return multiComp.compare(a, b) < 0 }
378378
spans := make([]chunkIndexSpan, nChunks)
379-
for c := 0; c < nChunks; c++ {
379+
for c := range nChunks {
380380
spans[c] = chunkIndexSpan{offs[c], offs[c+1]}
381381
}
382382
pairwiseMergeSortedSpans(indices, tmp, spans, less, spanScratch)

arrow/compute/internal/kernels/vector_sort_bench_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//go:build go1.18
17+
//go:build go1.22
1818

1919
package kernels
2020

@@ -56,13 +56,13 @@ func makeChunkedInt64Split(tb testing.TB, mem memory.Allocator, n, numChunks int
5656
rem := n % numChunks
5757
chunks := make([]arrow.Array, 0, numChunks)
5858
global := 0
59-
for c := 0; c < numChunks; c++ {
59+
for c := range numChunks {
6060
sz := base
6161
if c < rem {
6262
sz++
6363
}
6464
bld := array.NewInt64Builder(mem)
65-
for i := 0; i < sz; i++ {
65+
for i := range sz {
6666
x := int64(global + i)
6767
bld.Append((x * 6364136223846793005) ^ (x >> 12))
6868
}
@@ -86,7 +86,7 @@ func BenchmarkSortIndices_Int64(b *testing.B) {
8686

8787
b.ReportAllocs()
8888
b.ResetTimer()
89-
for i := 0; i < b.N; i++ {
89+
for range b.N {
9090
res, err := SortIndices(ctx, columns, keys)
9191
if err != nil {
9292
b.Fatal(err)
@@ -111,7 +111,7 @@ func BenchmarkSortIndices_Int64_TwoKeys(b *testing.B) {
111111

112112
b.ReportAllocs()
113113
b.ResetTimer()
114-
for i := 0; i < b.N; i++ {
114+
for range b.N {
115115
res, err := SortIndices(ctx, columns, keys)
116116
if err != nil {
117117
b.Fatal(err)
@@ -132,13 +132,13 @@ func makeChunkedStringSplit(tb testing.TB, mem memory.Allocator, n, numChunks in
132132
rem := n % numChunks
133133
chunks := make([]arrow.Array, 0, numChunks)
134134
global := 0
135-
for c := 0; c < numChunks; c++ {
135+
for c := range numChunks {
136136
sz := base
137137
if c < rem {
138138
sz++
139139
}
140140
bld := array.NewStringBuilder(mem)
141-
for i := 0; i < sz; i++ {
141+
for i := range sz {
142142
x := global + i
143143
v := (x * 6364136223846793005) ^ (x >> 12)
144144
bld.Append(fmt.Sprintf("%016x", v))
@@ -163,7 +163,7 @@ func BenchmarkSortIndices_String(b *testing.B) {
163163

164164
b.ReportAllocs()
165165
b.ResetTimer()
166-
for i := 0; i < b.N; i++ {
166+
for range b.N {
167167
res, err := SortIndices(ctx, columns, keys)
168168
if err != nil {
169169
b.Fatal(err)

arrow/compute/internal/kernels/vector_sort_internal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//go:build go1.18
17+
//go:build go1.22
1818

1919
package kernels
2020

arrow/compute/internal/kernels/vector_sort_physical.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//go:build go1.18
18+
//go:build go1.22
1919

2020
package kernels
2121

arrow/compute/internal/kernels/vector_sort_support.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//go:build go1.18
17+
//go:build go1.22
1818

1919
// Support for vector_sort.go: ordering primitives for Apache Arrow compute sort semantics
2020
// (CompareTypeValues-style helpers).

arrow/compute/vector_sort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//go:build go1.18
17+
//go:build go1.22
1818

1919
package compute
2020

arrow/compute/vector_sort_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//go:build go1.18
17+
//go:build go1.22
1818

1919
package compute_test
2020

@@ -316,7 +316,7 @@ func TestSortIndices(t *testing.T) {
316316
uint64Arr := resultArr.(*array.Uint64)
317317
require.Equal(t, len(tc.expected), uint64Arr.Len(), "result length mismatch")
318318

319-
for i := 0; i < uint64Arr.Len(); i++ {
319+
for i := range uint64Arr.Len() {
320320
assert.Equal(t, tc.expected[i], uint64Arr.Value(i), "at index %d", i)
321321
}
322322
})
@@ -346,7 +346,7 @@ func TestSortArray(t *testing.T) {
346346
expected := []int32{1, 1, 2, 3, 4, 5, 6, 9}
347347
resultArr := result.(*array.Int32)
348348
require.Equal(t, len(expected), resultArr.Len())
349-
for i := 0; i < resultArr.Len(); i++ {
349+
for i := range resultArr.Len() {
350350
assert.Equal(t, expected[i], resultArr.Value(i))
351351
}
352352
},
@@ -364,7 +364,7 @@ func TestSortArray(t *testing.T) {
364364
expected := []int32{9, 6, 5, 4, 3, 2, 1, 1}
365365
resultArr := result.(*array.Int32)
366366
require.Equal(t, len(expected), resultArr.Len())
367-
for i := 0; i < resultArr.Len(); i++ {
367+
for i := range resultArr.Len() {
368368
assert.Equal(t, expected[i], resultArr.Value(i))
369369
}
370370
},
@@ -383,7 +383,7 @@ func TestSortArray(t *testing.T) {
383383
validity := []bool{true, true, true, true, false}
384384
resultArr := result.(*array.Int32)
385385
require.Equal(t, len(expected), resultArr.Len())
386-
for i := 0; i < resultArr.Len(); i++ {
386+
for i := range resultArr.Len() {
387387
if validity[i] {
388388
assert.Equal(t, expected[i], resultArr.Value(i), "at index %d", i)
389389
} else {
@@ -406,7 +406,7 @@ func TestSortArray(t *testing.T) {
406406
validity := []bool{false, true, true, true, true}
407407
resultArr := result.(*array.Int32)
408408
require.Equal(t, len(expected), resultArr.Len())
409-
for i := 0; i < resultArr.Len(); i++ {
409+
for i := range resultArr.Len() {
410410
if validity[i] {
411411
assert.Equal(t, expected[i], resultArr.Value(i), "at index %d", i)
412412
} else {
@@ -447,7 +447,7 @@ func TestSortArray(t *testing.T) {
447447
expected := []string{"apple", "banana", "cherry", "date"}
448448
resultArr := result.(*array.String)
449449
require.Equal(t, len(expected), resultArr.Len())
450-
for i := 0; i < resultArr.Len(); i++ {
450+
for i := range resultArr.Len() {
451451
assert.Equal(t, expected[i], resultArr.Value(i))
452452
}
453453
},
@@ -476,7 +476,7 @@ func TestSortArray(t *testing.T) {
476476
validateFunc: func(t *testing.T, result arrow.Array) {
477477
resultArr := result.(*array.Int32)
478478
require.Equal(t, 3, resultArr.Len())
479-
for i := 0; i < resultArr.Len(); i++ {
479+
for i := range resultArr.Len() {
480480
assert.True(t, resultArr.IsNull(i), "expected null at index %d", i)
481481
}
482482
},
@@ -494,7 +494,7 @@ func TestSortArray(t *testing.T) {
494494
expected := []int32{1, 1, 1, 2, 2}
495495
resultArr := result.(*array.Int32)
496496
require.Equal(t, len(expected), resultArr.Len())
497-
for i := 0; i < resultArr.Len(); i++ {
497+
for i := range resultArr.Len() {
498498
assert.Equal(t, expected[i], resultArr.Value(i))
499499
}
500500
},
@@ -512,7 +512,7 @@ func TestSortArray(t *testing.T) {
512512
expected := []uint64{25, 50, 100, 200}
513513
resultArr := result.(*array.Uint64)
514514
require.Equal(t, len(expected), resultArr.Len())
515-
for i := 0; i < resultArr.Len(); i++ {
515+
for i := range resultArr.Len() {
516516
assert.Equal(t, expected[i], resultArr.Value(i))
517517
}
518518
},
@@ -530,7 +530,7 @@ func TestSortArray(t *testing.T) {
530530
expected := [][]byte{{1, 2, 3}, {2, 2, 2}, {3, 2, 1}}
531531
resultArr := result.(*array.Binary)
532532
require.Equal(t, len(expected), resultArr.Len())
533-
for i := 0; i < resultArr.Len(); i++ {
533+
for i := range resultArr.Len() {
534534
assert.Equal(t, expected[i], resultArr.Value(i))
535535
}
536536
},
@@ -604,7 +604,7 @@ func TestSortRecordBatch(t *testing.T) {
604604
resultVal := result.Column(1).(*array.Int32)
605605
resultPri := result.Column(2).(*array.Int32)
606606

607-
for i := 0; i < int(result.NumRows()); i++ {
607+
for i := range int(result.NumRows()) {
608608
assert.Equal(t, expectedCat[i], resultCat.Value(i), "category at %d", i)
609609
assert.Equal(t, expectedVal[i], resultVal.Value(i), "value at %d", i)
610610
assert.Equal(t, expectedPri[i], resultPri.Value(i), "priority at %d", i)
@@ -659,7 +659,7 @@ func TestSortRecordBatch(t *testing.T) {
659659
expectedCol3 := []int32{200, 100, 400, 300}
660660

661661
require.Equal(t, 4, int(result.NumRows()))
662-
for i := 0; i < 4; i++ {
662+
for i := range 4 {
663663
assert.Equal(t, expectedCol1[i], resultCol1.Value(i), "col1 at %d", i)
664664
assert.Equal(t, expectedCol2[i], resultCol2.Value(i), "col2 at %d", i)
665665
assert.Equal(t, expectedCol3[i], resultCol3.Value(i), "col3 at %d", i)
@@ -750,7 +750,7 @@ func TestSortTable(t *testing.T) {
750750
nameData := result.Column(0).Data().Chunk(0).(*array.String)
751751
ageData := result.Column(1).Data().Chunk(0).(*array.Int32)
752752

753-
for i := 0; i < int(result.NumRows()); i++ {
753+
for i := range int(result.NumRows()) {
754754
assert.Equal(t, expectedNames[i], nameData.Value(i))
755755
assert.Equal(t, expectedAges[i], ageData.Value(i))
756756
}
@@ -822,7 +822,7 @@ func TestSortTable(t *testing.T) {
822822
idData := result.Column(2).Data().Chunk(0).(*array.Int32)
823823

824824
require.Equal(t, 4, int(result.NumRows()))
825-
for i := 0; i < int(result.NumRows()); i++ {
825+
for i := range int(result.NumRows()) {
826826
assert.Equal(t, expectedCategory[i], categoryData.Value(i), "category at %d", i)
827827
assert.Equal(t, expectedPriority[i], priorityData.Value(i), "priority at %d", i)
828828
assert.Equal(t, expectedId[i], idData.Value(i), "id at %d", i)
@@ -862,7 +862,7 @@ func TestSortIndicesChunked(t *testing.T) {
862862
// Expected: values [1, 1, 3, 4, 5] -> indices [1, 3, 0, 2, 4]
863863
expected := []uint64{1, 3, 0, 2, 4}
864864
require.Equal(t, len(expected), resultArr.Len())
865-
for i := 0; i < resultArr.Len(); i++ {
865+
for i := range resultArr.Len() {
866866
assert.Equal(t, expected[i], resultArr.Value(i), "index at %d", i)
867867
}
868868
})
@@ -895,7 +895,7 @@ func TestSortIndicesChunked(t *testing.T) {
895895
// Expected: ["a", "b", "c", null] -> indices [2, 0, 3, 1]
896896
expected := []uint64{2, 0, 3, 1}
897897
require.Equal(t, len(expected), resultArr.Len())
898-
for i := 0; i < resultArr.Len(); i++ {
898+
for i := range resultArr.Len() {
899899
assert.Equal(t, expected[i], resultArr.Value(i), "index at %d", i)
900900
}
901901
})
@@ -928,7 +928,7 @@ func TestSortIndicesChunked(t *testing.T) {
928928
// Expected: [0.5, 1.0, 2.0, NaN] -> indices [3, 0, 2, 1]
929929
expected := []uint64{3, 0, 2, 1}
930930
require.Equal(t, len(expected), resultArr.Len())
931-
for i := 0; i < resultArr.Len(); i++ {
931+
for i := range resultArr.Len() {
932932
assert.Equal(t, expected[i], resultArr.Value(i), "index at %d", i)
933933
}
934934
})
@@ -1003,7 +1003,7 @@ func TestSortTableChunked(t *testing.T) {
10031003
catData := result.Column(0).Data().Chunk(0).(*array.String)
10041004
valData := result.Column(1).Data().Chunk(0).(*array.Int32)
10051005

1006-
for i := 0; i < 3; i++ {
1006+
for i := range 3 {
10071007
assert.Equal(t, expectedCat[i], catData.Value(i), "category at %d", i)
10081008
assert.Equal(t, expectedVal[i], valData.Value(i), "value at %d", i)
10091009
}
@@ -1102,7 +1102,7 @@ func TestSortTableChunked(t *testing.T) {
11021102
col2Data := result.Column(1).Data().Chunk(0).(*array.String)
11031103
col3Data := result.Column(2).Data().Chunk(0).(*array.Int32)
11041104

1105-
for i := 0; i < 3; i++ {
1105+
for i := range 3 {
11061106
assert.Equal(t, expectedCol1[i], col1Data.Value(i), "col1 at %d", i)
11071107
assert.Equal(t, expectedCol2[i], col2Data.Value(i), "col2 at %d", i)
11081108
assert.Equal(t, expectedCol3[i], col3Data.Value(i), "col3 at %d", i)

0 commit comments

Comments
 (0)