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 comparison against nil for the UUID type #295

Merged
merged 2 commits into from
Oct 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions appender_test.go
taniabogatsch marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,34 @@ func TestAppenderUUID(t *testing.T) {
c, con, a := prepareAppender(t, `CREATE TABLE test (id UUID)`)

id := UUID(uuid.New())
otherId := UUID(uuid.New())
require.NoError(t, a.AppendRow(id))
require.NoError(t, a.AppendRow(otherId))
require.NoError(t, a.AppendRow((*UUID)(nil)))
require.NoError(t, a.AppendRow(nil))
require.NoError(t, a.Flush())

// Verify results.
row := sql.OpenDB(c).QueryRowContext(context.Background(), `SELECT id FROM test`)
res, err := sql.OpenDB(c).QueryContext(context.Background(), `SELECT id FROM test`)
require.NoError(t, err)

var res UUID
require.NoError(t, row.Scan(&res))
require.Equal(t, id, res)
i := 0
for res.Next() {
if i == 0 {
var r UUID
require.NoError(t, res.Scan(&r))
require.Equal(t, id, r)
} else {
var r *UUID
require.NoError(t, res.Scan(&r))
if i == 1 {
require.Equal(t, otherId, *r)
} else {
require.Nil(t, r)
}
}
i++
}
cleanupAppender(t, c, con, a)
}

Expand Down
2 changes: 1 addition & 1 deletion vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func (vec *vector) initUUID() {
return hugeIntToUUID(hugeInt)
}
vec.setFn = func(vec *vector, rowIdx C.idx_t, val any) error {
if val == nil {
if val == nil || val == (*UUID)(nil) {
vec.setNull(rowIdx)
return nil
}
Expand Down
Loading