Skip to content

Commit dafd05b

Browse files
authored
fix(arrow): Allow empty and nil valid param in AppendValues (#847)
Follow-up for #823
1 parent 9426d11 commit dafd05b

File tree

8 files changed

+24
-8
lines changed

8 files changed

+24
-8
lines changed

types/inet.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ func (b *InetBuilder) UnsafeAppend(v *net.IPNet) {
3333
}
3434

3535
func (b *InetBuilder) AppendValues(v []*net.IPNet, valid []bool) {
36+
if len(v) != len(valid) && len(valid) != 0 {
37+
panic("len(v) != len(valid) && len(valid) != 0")
38+
}
39+
3640
data := make([]string, len(v))
3741
for i, v := range v {
38-
if !valid[i] {
42+
if len(valid) > 0 && !valid[i] {
3943
continue
4044
}
4145
data[i] = v.String()

types/inet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestInetBuilder(t *testing.T) {
3535
mustParseInet("192.168.0.0/26"),
3636
mustParseInet("192.168.0.0/27"),
3737
}
38-
b.AppendValues(values, []bool{true, true})
38+
b.AppendValues(values, nil)
3939

4040
require.Equal(t, 6, b.Len(), "unexpected Len()")
4141

types/json.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ func (b *JSONBuilder) AppendValueFromString(s string) error {
5454
}
5555

5656
func (b *JSONBuilder) AppendValues(v []any, valid []bool) {
57+
if len(v) != len(valid) && len(valid) != 0 {
58+
panic("len(v) != len(valid) && len(valid) != 0")
59+
}
60+
5761
data := make([][]byte, len(v))
5862
var err error
5963
for i := range v {
60-
if !valid[i] {
64+
if len(valid) > 0 && !valid[i] {
6165
continue
6266
}
6367
// per https://github.com/cloudquery/plugin-sdk/issues/622

types/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestJSONBuilder(t *testing.T) {
2828
map[string]any{"e": 5, "f": 6},
2929
map[string]any{"g": 7, "h": 8},
3030
}
31-
b.AppendValues(values, []bool{true, true})
31+
b.AppendValues(values, nil)
3232

3333
require.Equal(t, 6, b.Len(), "unexpected Len()")
3434

types/mac.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ func (b *MacBuilder) UnsafeAppend(v net.HardwareAddr) {
2929
}
3030

3131
func (b *MacBuilder) AppendValues(v []net.HardwareAddr, valid []bool) {
32+
if len(v) != len(valid) && len(valid) != 0 {
33+
panic("len(v) != len(valid) && len(valid) != 0")
34+
}
35+
3236
data := make([][]byte, len(v))
3337
for i, v := range v {
34-
if !valid[i] {
38+
if len(valid) > 0 && !valid[i] {
3539
continue
3640
}
3741
data[i] = v

types/mac_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestMacBuilder(t *testing.T) {
3535
mustParseMac("00:00:00:00:00:03"),
3636
mustParseMac("00:00:00:00:00:04"),
3737
}
38-
b.AppendValues(values, []bool{true, true})
38+
b.AppendValues(values, nil)
3939

4040
require.Equal(t, 6, b.Len(), "unexpected Len()")
4141

types/uuid.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ func (b *UUIDBuilder) AppendValueFromString(s string) error {
4242
}
4343

4444
func (b *UUIDBuilder) AppendValues(v []uuid.UUID, valid []bool) {
45+
if len(v) != len(valid) && len(valid) != 0 {
46+
panic("len(v) != len(valid) && len(valid) != 0")
47+
}
48+
4549
data := make([][]byte, len(v))
4650
for i := range v {
47-
if !valid[i] {
51+
if len(valid) > 0 && !valid[i] {
4852
continue
4953
}
5054
data[i] = v[i][:]

types/uuid_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestUUIDBuilder(t *testing.T) {
2727
uuid.MustParse("00000000-0000-0000-0000-000000000003"),
2828
uuid.MustParse("00000000-0000-0000-0000-000000000004"),
2929
}
30-
b.AppendValues(values, []bool{true, true})
30+
b.AppendValues(values, nil)
3131

3232
require.Equal(t, 6, b.Len(), "unexpected Len()")
3333

0 commit comments

Comments
 (0)