Skip to content

Commit

Permalink
fix SQL NULL in nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
taniabogatsch committed Sep 17, 2024
1 parent 31ef67c commit 97f620c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions scalar_udf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ func TestANYScalarUDF(t *testing.T) {
require.NoError(t, err)

var count int
row := db.QueryRow(`SELECT my_null_count(10, 42, 2, 2, 2) AS msg`)
row := db.QueryRow(`SELECT my_null_count(10, 'hello', 2, [2], 2) AS msg`)
require.NoError(t, row.Scan(&count))
require.Equal(t, 0, count)

row = db.QueryRow(`SELECT my_null_count(10, NULL, NULL) AS msg`)
row = db.QueryRow(`SELECT my_null_count(10, NULL, NULL, [NULL], {'hello': NULL}) AS msg`)
require.NoError(t, row.Scan(&count))
require.Equal(t, 2, count)

row = db.QueryRow(`SELECT my_null_count(10) AS msg`)
row = db.QueryRow(`SELECT my_null_count(10, True) AS msg`)
require.NoError(t, row.Scan(&count))
require.Equal(t, 0, count)

Expand Down
16 changes: 12 additions & 4 deletions vector_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ func (vec *vector) getList(rowIdx C.idx_t) []any {

// Fill the slice with all child values.
for i := C.idx_t(0); i < entry.length; i++ {
val := child.getFn(child, i+entry.offset)
slice = append(slice, val)
if child.isSQLNull {
slice = append(slice, nil)
} else {
val := child.getFn(child, i+entry.offset)
slice = append(slice, val)
}
}
return slice
}
Expand All @@ -158,8 +162,12 @@ func (vec *vector) getStruct(rowIdx C.idx_t) map[string]any {
m := map[string]any{}
for i := 0; i < len(vec.childVectors); i++ {
child := &vec.childVectors[i]
val := child.getFn(child, rowIdx)
m[vec.structEntries[i].Name()] = val
if child.isSQLNull {
m[vec.structEntries[i].Name()] = nil
} else {
val := child.getFn(child, rowIdx)
m[vec.structEntries[i].Name()] = val
}
}
return m
}
Expand Down

0 comments on commit 97f620c

Please sign in to comment.