-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbowassertion.go
More file actions
86 lines (81 loc) · 1.84 KB
/
Copy pathbowassertion.go
File metadata and controls
86 lines (81 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package bow
import (
"github.com/apache/arrow/go/v8/arrow/array"
)
const (
orderUndefined = iota
orderASC
orderDESC
)
// IsColSorted returns a boolean whether the column colIndex is sorted or not, skipping nil values.
// An empty column or an unsupported data type returns false.
func (b *bow) IsColSorted(colIndex int) bool {
if b.IsColEmpty(colIndex) {
return false
}
var rowIndex int
var order = orderUndefined
switch b.ColumnType(colIndex) {
case Int64:
arr := array.NewInt64Data(b.Column(colIndex).Data())
values := arr.Int64Values()
for arr.IsNull(rowIndex) {
rowIndex++
}
curr := values[rowIndex]
var next int64
rowIndex++
for ; rowIndex < len(values); rowIndex++ {
if !arr.IsValid(rowIndex) {
continue
}
next = values[rowIndex]
if order == orderUndefined {
if curr < next {
order = orderASC
} else if curr > next {
order = orderDESC
}
}
if order == orderASC && next < curr ||
order == orderDESC && next > curr {
return false
}
curr = next
}
case Float64:
arr := array.NewFloat64Data(b.Column(colIndex).Data())
values := arr.Float64Values()
for arr.IsNull(rowIndex) {
rowIndex++
}
curr := values[rowIndex]
var next float64
rowIndex++
for ; rowIndex < len(values); rowIndex++ {
if !arr.IsValid(rowIndex) {
continue
}
next = values[rowIndex]
if order == orderUndefined {
if curr < next {
order = orderASC
} else if curr > next {
order = orderDESC
}
}
if order == orderASC && next < curr ||
order == orderDESC && next > curr {
return false
}
curr = next
}
default:
return false
}
return true
}
// IsColEmpty returns false if the column has at least one non-nil value, and true otherwise.
func (b *bow) IsColEmpty(colIndex int) bool {
return b.Column(colIndex).NullN() == b.Column(colIndex).Len()
}