kelindar / column

High-performance, columnar, in-memory store with bitmap indexing in Go
MIT License
1.44k stars 57 forks source link

Adding record column #73

Closed kelindar closed 1 year ago

kelindar commented 1 year ago

This PR contains some refactoring and a new record column that allows you to use a BinaryMarshaler and BinaryUnmarshaler type to be stored. As such, it supports types that implement this standard way of encoding, for example time.Time.

col := NewCollection()
col.CreateColumn("timestamp", ForRecord(func() *time.Time {
    return new(time.Time)
}, nil))

// Insert the time, it implements binary marshaler
idx, _ := col.Insert(func(r Row) error {
    now := time.Unix(1667745766, 0)
    r.SetRecord("timestamp", &now)
    return nil
})

// We should be able to read back the time
col.QueryAt(idx, func(r Row) error {
    ts, ok := r.Record("timestamp")
    assert.True(t, ok)
    assert.Equal(t, "November", ts.(*time.Time).UTC().Month().String())
    return nil
})