Skip to content

Commit

Permalink
[Array] Handle null ARRAY fields (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq authored Mar 9, 2024
1 parent b4408b0 commit 40c4c39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/function_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ func RegisterFunctions(conn *sqlite3.SQLiteConn) error {
if err != nil {
return "", err
}
if decoded == nil {
return "[]", nil
}
array, err := decoded.ToArray()
if err != nil {
return "", err
Expand Down
16 changes: 16 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,22 @@ FROM
},
},
},
// Regression test for goccy/go-zetasqlite#179
{
name: "null array scan",
query: `
WITH file AS (
SELECT 1 AS file_id, ARRAY<STRING>["r", "w"] AS modes
UNION ALL SELECT 2, ARRAY<STRING>["w"]
)
SELECT id,
(SELECT mode FROM UNNEST(modes) AS mode WHERE mode = 'w') IS NOT NULL AS write_mode,
(SELECT mode FROM UNNEST(modes) AS mode WHERE mode = 'r') IS NOT NULL AS read_mode
FROM UNNEST([1, 2, 3]) id
LEFT JOIN file on file.file_id = id`,
expectedRows: [][]interface{}{{int64(1), true, true}, {int64(2), true, false}, {int64(3), false, false}},
},

{
name: "array_reverse function",
query: `
Expand Down

0 comments on commit 40c4c39

Please sign in to comment.