Skip to content

Commit

Permalink
Fix withValue on record column type
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Jul 3, 2023
1 parent f9e0f03 commit 182e931
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions column_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func ForRecord[T recordType](new func() T, opts ...func(*option[T])) Column {
}
}

// Value returns the value at the given index
// TODO: should probably get rid of this and use an `rdRecord` instead
func (c *columnRecord) Value(idx uint32) (any, bool) {
if v, ok := c.columnString.Value(idx); ok {
out := c.pool.New().(encoding.BinaryUnmarshaler)
err := out.UnmarshalBinary(s2b(v.(string)))
return out, err == nil
}
return nil, false
}

// --------------------------- Writer ----------------------------

// rwRecord represents read-write accessor for primary keys.
Expand Down
18 changes: 18 additions & 0 deletions column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,24 @@ func TestNumberMerge(t *testing.T) {
})
}

func TestIssue87(t *testing.T) {
table := NewCollection()
table.CreateColumn("birthdate", ForRecord(func() *time.Time { return new(time.Time) }))

srcDate := time.Date(1999, 3, 2, 12, 0, 0, 0, time.Local)
table.Insert(func(r Row) error {
r.SetRecord("birthdate", srcDate)
return nil
})

table.Query(func(txn *Txn) error {
assert.Equal(t, txn.WithValue("birthdate", func(v any) bool {
return v.(*time.Time).Equal(srcDate)
}).Count(), 1)
return nil
})
}

// Tests the case where a column is created after inserting a large enough amount of data
func TestIssue89(t *testing.T) {
coll := NewCollection()
Expand Down

0 comments on commit 182e931

Please sign in to comment.