Skip to content

[Go] BinaryBuilder Append() doesn't append the empty values correctly #625

@ysuliu

Description

@ysuliu

Describe the bug, including details regarding any error messages, version, and platform.

With a BinaryBuilder, I need to append some empty values (""), but not Null. The problem is when all the column data are empty (""), the data in the generated arrow table is Null.

Using the below sample code, issue could be reproduced easily.

func testTable() {
	pool := memory.NewGoAllocator()
	fields := []arrow.Field{
		{
			Name: "id",
			Type: arrow.BinaryTypes.Binary,
		},
	}
	schema := arrow.NewSchema(fields, nil)
	builder := array.NewRecordBuilder(pool, schema)

	defer builder.Release()

	idBuilder := builder.Field(0).(*array.BinaryBuilder)
	defer idBuilder.Release()

	// Case #1: Empty + Data
	//idBuilder.Append([]byte(""))
	//idBuilder.Append([]byte(""))
	//idBuilder.Append([]byte("SGVsbG8sIFdvcmxkIQ=="))

	// Case #2: All Empty
	idBuilder.Append([]byte(""))
	idBuilder.Append([]byte(""))
	idBuilder.Append([]byte(""))

	records := builder.NewRecordBatch()
	defer records.Release()

	table := array.NewTableFromRecords(schema, []arrow.RecordBatch{records})

	tr := array.NewTableReader(table, 0)
	defer tr.Release()

	for n := 0; tr.Next(); n++ {
		record := tr.RecordBatch()
		defer record.Release()

		for rowIdx := range int(record.NumRows()) {
			for _, col := range record.Columns() {
				data, _ := col.(*array.Binary)

				v := data.Value(rowIdx)

				if v == nil {
					fmt.Printf("NULL\n")
				} else {
					fmt.Printf("%v\n", v)
				}
			}
		}
	}
}

There are 2 cases in the code.

  1. When enable case 1, the column data includes the empty value and a real value. The output is
[]
[]
[83 71 86 115 98 71 56 115 73 70 100 118 99 109 120 107 73 81 61 61]
  1. When enable case 2, all the column data is empty value. The output is
NULL
NULL
NULL

You can see the case 2 has all values nil instead of []. Here the expected output of case 2 is

[]
[]
[]

Your reply is highly appreciated, thanks!

Component(s)

Other

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions