Skip to content

Commit 7175e5a

Browse files
authored
fix(scalar): Don't pass typed nils in list values (#1226)
Fixes issues like cloudquery/cloudquery-issues#595
1 parent e05afc6 commit 7175e5a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

scalar/list.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ func (s *List) Set(val any) error {
9393
s.Value = make(Vector, length)
9494
for i := 0; i < length; i++ {
9595
s.Value[i] = NewScalar(s.Type.(*arrow.ListType).Elem())
96-
if err := s.Value[i].Set(reflectedValue.Index(i).Interface()); err != nil {
96+
iVal := reflectedValue.Index(i)
97+
if isReflectValueNil(iVal) {
98+
continue
99+
}
100+
if err := s.Value[i].Set(iVal.Interface()); err != nil {
97101
return err
98102
}
99103
}
@@ -102,3 +106,16 @@ func (s *List) Set(val any) error {
102106
s.Valid = true
103107
return nil
104108
}
109+
110+
func isReflectValueNil(v reflect.Value) bool {
111+
switch v.Kind() {
112+
case reflect.Pointer,
113+
reflect.UnsafePointer,
114+
reflect.Map,
115+
reflect.Slice,
116+
reflect.Interface:
117+
return v.IsNil()
118+
default:
119+
return false
120+
}
121+
}

scalar/list_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package scalar
22

33
import (
4+
"net"
45
"testing"
56

67
"github.com/apache/arrow/go/v14/arrow"
8+
"github.com/cloudquery/plugin-sdk/v4/types"
79
)
810

911
func TestListSet(t *testing.T) {
12+
ipOne := net.IP{192, 168, 1, 1}
13+
ipNet := net.IPNet{IP: ipOne, Mask: net.IPMask{255, 255, 255, 255}}
14+
typedNil := (*net.IP)(nil)
1015
successfulTests := []struct {
1116
source any
1217
result List
@@ -23,6 +28,15 @@ func TestListSet(t *testing.T) {
2328
&Int{Value: 1, Valid: true},
2429
&Int{Value: 2, Valid: true},
2530
}, Valid: true, Type: arrow.ListOf(arrow.PrimitiveTypes.Int64)}},
31+
{source: []*net.IPNet{&ipNet, nil}, result: List{Value: []Scalar{
32+
&Inet{Value: &ipNet, Valid: true},
33+
&Inet{Valid: false},
34+
}, Valid: true, Type: arrow.ListOf(types.ExtensionTypes.Inet)}},
35+
{source: []*net.IP{&ipOne, typedNil, nil}, result: List{Value: []Scalar{
36+
&Inet{Value: &ipNet, Valid: true},
37+
&Inet{Valid: false},
38+
&Inet{Valid: false},
39+
}, Valid: true, Type: arrow.ListOf(types.ExtensionTypes.Inet)}},
2640
}
2741

2842
for i, tt := range successfulTests {

0 commit comments

Comments
 (0)