Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix withValue on record column type #92

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions column_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ 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) (out any, has bool) {
if v, ok := c.columnString.Value(idx); ok {
out = c.pool.New()
has = out.(encoding.BinaryUnmarshaler).UnmarshalBinary(s2b(v.(string))) == nil
}
return
}

// --------------------------- 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