如何构建具有带布尔字段的结构的golang apache箭头记录

时间:2019-05-02 00:32:49

标签: go apache-arrow

当我建立一个具有结构的箭头记录,并且该结构具有类型为arrow.FixedWidthTypes.Boolean的字段时,稍后在尝试访问具有以下错误的布尔值时会出现恐慌:

    runtime error: invalid memory address or nil pointer dereference

以下代码成功读取了字符串值,但没有读取布尔值:

mem := memory.NewGoAllocator()

fields := []arrow.Field{
    {Name: "my struct", Type: arrow.StructOf([]arrow.Field{
        {Name: "my string", Type: arrow.BinaryTypes.String},
        {Name: "my bool", Type: arrow.FixedWidthTypes.Boolean},
    }...)},
}

schema := arrow.NewSchema(fields, nil)

bld := array.NewRecordBuilder(mem, schema)
defer bld.Release()

sb := bld.Field(0).(*array.StructBuilder)
f1b := sb.FieldBuilder(0).(*array.StringBuilder)
f2b := sb.FieldBuilder(1).(*array.BooleanBuilder)

sb.AppendValues([]bool{true})
f1b.AppendValues([]string{"someone", "was", "here"}, nil)
f2b.AppendValues([]bool{false, true, true}, nil)

r := bld.NewRecord()

struc := r.Column(0).(*array.Struct)

Expect(struc.Field(0).(*array.String).Value(0)).ToNot(Panic())
Expect(struc.Field(1).(*array.Boolean).Value(0)).To(Panic())

0 个答案:

没有答案