Skip to content

Commit f0fcfa8

Browse files
committed
fix(arrow/cdata): handle export struct with no fields
1 parent 56b794f commit f0fcfa8

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

arrow/cdata/cdata_exports.go

+3
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ func exportArray(arr arrow.Array, out *CArrowArray, outSchema *CArrowSchema) {
401401
out.children = (**CArrowArray)(unsafe.Pointer(&childPtrs[0]))
402402
case *array.Struct:
403403
out.n_children = C.int64_t(arr.NumField())
404+
if arr.NumField() == 0 {
405+
return
406+
}
404407
childPtrs := allocateArrowArrayPtrArr(arr.NumField())
405408
children := allocateArrowArrayArr(arr.NumField())
406409
for i := 0; i < arr.NumField(); i++ {

arrow/cdata/cdata_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,14 @@ func createTestStructArr() arrow.Array {
598598
return bld.NewArray()
599599
}
600600

601+
func createTestEmptyStructArr() arrow.Array {
602+
bld := array.NewStructBuilder(memory.DefaultAllocator, arrow.StructOf())
603+
defer bld.Release()
604+
605+
bld.AppendNull()
606+
return bld.NewArray()
607+
}
608+
601609
func createTestRunEndsArr() arrow.Array {
602610
bld := array.NewRunEndEncodedBuilder(memory.DefaultAllocator,
603611
arrow.PrimitiveTypes.Int32, arrow.PrimitiveTypes.Int8)
@@ -687,6 +695,7 @@ func TestNestedArrays(t *testing.T) {
687695
{"sparse union", createTestSparseUnion},
688696
{"dense union", createTestDenseUnion},
689697
{"run-end encoded", createTestRunEndsArr},
698+
{"empty struct", createTestEmptyStructArr},
690699
}
691700

692701
for _, tt := range tests {

arrow/cdata/cdata_test_framework.go

+3
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ func createCArr(arr arrow.Array, alloc *mallocator.Mallocator) *CArrowArray {
309309
children = (**CArrowArray)(unsafe.Pointer(&clist[0]))
310310
nchildren += 1
311311
case *array.Struct:
312+
if arr.NumField() == 0 {
313+
break
314+
}
312315
clist := allocateChildrenPtrArr(alloc, arr.NumField())
313316
for i := 0; i < arr.NumField(); i++ {
314317
clist[i] = createCArr(arr.Field(i), alloc)

0 commit comments

Comments
 (0)