Skip to content

Commit dc1e6be

Browse files
authored
fix: Nulls in lists (#1127)
Found in cloudquery/cloudquery#12725
1 parent 9de3b07 commit dc1e6be

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

plugin/nulls.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ import (
88

99
func stripNullsFromLists(list array.ListLike) array.ListLike {
1010
// TODO: handle Arrow maps separately if required
11-
12-
if list.NullN() == 0 {
13-
return list
14-
}
15-
1611
bldr := array.NewBuilder(memory.DefaultAllocator, list.DataType()).(array.ListLikeBuilder)
1712
for j := 0; j < list.Len(); j++ {
1813
if list.IsNull(j) {

plugin/nulls_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,44 @@ import (
1010
"time"
1111
)
1212

13+
func TestWithTestIgnoreNullsInLists(t *testing.T) {
14+
s := &WriterTestSuite{ignoreNullsInLists: true}
15+
16+
tg := schema.NewTestDataGenerator()
17+
source := schema.TestTable("ignore_nulls_in_lists", schema.TestSourceOptions{})
18+
resource := s.handleNulls(tg.Generate(source, schema.GenTestDataOptions{
19+
SourceName: "allow_null",
20+
SyncTime: time.Now(),
21+
MaxRows: 100,
22+
NullRows: false,
23+
})[0])
24+
for _, c := range resource.Columns() {
25+
assertNoNullsInLists(t, c)
26+
}
27+
28+
resource = s.handleNulls(tg.Generate(source, schema.GenTestDataOptions{
29+
SourceName: "ignore_nulls_in_lists",
30+
SyncTime: time.Now(),
31+
MaxRows: 100,
32+
NullRows: true,
33+
})[0])
34+
for _, c := range resource.Columns() {
35+
assertNoNullsInLists(t, c)
36+
}
37+
}
38+
39+
func assertNoNullsInLists(t *testing.T, arr arrow.Array) {
40+
// traverse
41+
switch arr := arr.(type) {
42+
case array.ListLike:
43+
assert.Zero(t, arr.ListValues().NullN())
44+
case *array.Struct:
45+
for i := 0; i < arr.NumField(); i++ {
46+
assertNoNullsInLists(t, arr.Field(i))
47+
}
48+
}
49+
}
50+
1351
func TestWithTestSourceAllowNull(t *testing.T) {
1452
s := &WriterTestSuite{allowNull: func(dt arrow.DataType) bool {
1553
switch dt.(type) {

0 commit comments

Comments
 (0)