Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit f85e262

Browse files
Diego Rodriguez ManciniDiego Rodriguez Mancini
Diego Rodriguez Mancini
authored and
Diego Rodriguez Mancini
committed
fix: write binary table keeping data
1 parent f776914 commit f85e262

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

column.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,15 @@ func (col *Column) writeBin(table *Table, icol int, irow int64, ptr interface{})
417417
}
418418

419419
case reflect.Array:
420+
rvPtr := reflect.New(rv.Type()).Elem()
421+
rvPtr.Set(rv)
420422

421423
beg := table.rowsz*int(irow) + col.offset
422424
end := beg + (col.dtype.dsize * col.dtype.len)
423425

424426
w := newWriter(table.data[beg:end])
425-
switch slice := rv.Slice(0, rv.Len()).Interface().(type) {
427+
428+
switch slice := rvPtr.Slice(0, rv.Len()).Interface().(type) {
426429
case []bool:
427430
w.writeBools(slice)
428431

table.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,10 @@ func (t *Table) writeMap(data map[string]interface{}) error {
412412

413413
for _, icol := range icols {
414414
col := t.Col(icol)
415-
val := reflect.New(col.Type())
416-
err = col.write(t, icol, t.nrows, val.Interface())
415+
err = col.write(t, icol, t.nrows, data[col.Name])
417416
if err != nil {
418417
return err
419418
}
420-
data[col.Name] = val.Elem().Interface()
421419
}
422420
return err
423421
}

table_test.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,21 @@ func TestTableSliceRW(t *testing.T) {
11131113
table interface{}
11141114
}{
11151115
// binary table
1116+
{
1117+
name: "bin-strings",
1118+
cols: []Column{
1119+
{
1120+
Name: "strings",
1121+
Format: "10A",
1122+
},
1123+
},
1124+
htype: BINARY_TBL,
1125+
table: [][]string{
1126+
{"a", "b", "c", "d"},
1127+
{"e", "f", "g", "h"},
1128+
{"i", "j", "k", "l"},
1129+
},
1130+
},
11161131
{
11171132
name: "bin-b",
11181133
cols: []Column{
@@ -2046,6 +2061,10 @@ func TestTableMapsRW(t *testing.T) {
20462061
},
20472062
{
20482063
Name: "E",
2064+
Format: "10A",
2065+
},
2066+
{
2067+
Name: "F",
20492068
Format: "2D",
20502069
},
20512070
},
@@ -2056,28 +2075,32 @@ func TestTableMapsRW(t *testing.T) {
20562075
"B": float64(10),
20572076
"C": []int64{10, 10},
20582077
"D": []float64{10, 10},
2059-
"E": [2]float64{10, 10},
2078+
"E": string("10"),
2079+
"F": [2]float64{10, 10},
20602080
},
20612081
{
20622082
"A": int64(11),
20632083
"B": float64(11),
20642084
"C": []int64{11, 11},
20652085
"D": []float64{11, 11},
2066-
"E": [2]float64{11, 11},
2086+
"E": string("11"),
2087+
"F": [2]float64{11, 11},
20672088
},
20682089
{
20692090
"A": int64(12),
20702091
"B": float64(12),
20712092
"C": []int64{12, 12},
20722093
"D": []float64{12, 12},
2073-
"E": [2]float64{12, 12},
2094+
"E": string("12"),
2095+
"F": [2]float64{12, 12},
20742096
},
20752097
{
20762098
"A": int64(13),
20772099
"B": float64(13),
20782100
"C": []int64{13, 13},
20792101
"D": []float64{13, 13},
2080-
"E": [2]float64{13, 13},
2102+
"E": string("13"),
2103+
"F": [2]float64{13, 13},
20812104
},
20822105
},
20832106
},

0 commit comments

Comments
 (0)