Skip to content

Commit

Permalink
[Array] Handle null ARRAY fields (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq committed Feb 28, 2024
1 parent c21c1de commit 6d98454
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 @@ -419,6 +419,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 @@ -2734,6 +2734,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 6d98454

Please sign in to comment.