What happened?
What I'm doing:
SELECT FROM table_alias1,
INNER JOIN table_alias2,
WHERE length of arrays in a column differ
What's happening:
The emulator crashes with the error “panic: runtime error: invalid memory address or nil pointer dereference”
What did you expect to happen?
The query is executed successfully.
How can we reproduce it (as minimally and precisely as possible)?
- Start the emulator container (I’m running on Apple M2 Pro)
docker run --platform linux/x86_64 -p 9050:9050 -p 9060:9060 ghcr.io/goccy/bigquery-emulator:latest --project=some_project --log-level debug
- Create the following python file and run it
from google.api_core.client_options import ClientOptions # using google-api-core v2.24.2
from google.auth.credentials import AnonymousCredentials # using google-auth v2.40.1
from google.cloud.bigquery import Client # using google-cloud-bigquery v3.13.0
qry="""
SELECT t1.*
FROM (
SELECT 1 as idx, 1 as col1, [1, 2, 3] as arr_col
UNION ALL
SELECT 2 as idx, 2 as col1, [1, 2, 3] as arr_col
UNION ALL
SELECT 3 as idx, 3 as col1, [1, 2, 3, 4] as arr_col
) as t1
LEFT JOIN (
SELECT 1 as idx, 1 as col1, [1, 2, 3] as arr_col
UNION ALL
SELECT 3 as idx, 3 as col1, [1, 2, 3] as arr_col
UNION ALL
SELECT 4 as idx, 4 as col1, [1, 2, 3] as arr_col
) as t2
ON t1.idx = t2.idx
WHERE ARRAY_LENGTH(t1.arr_col) <> ARRAY_LENGTH(t2.arr_col)
""".strip()
client = Client(
project="some_project",
credentials=AnonymousCredentials(),
client_options=ClientOptions(api_endpoint="http://0.0.0.0:9050"),
)
result=list(client.query(qry).result())
print(result)
Anything else we need to know?
Notes:
- The query
qry runs successfully on the BigQuery engine
- If I replace
ARRAY_LENGTH(t2.arr_col) with an integer (say 4), the query is executed successfully on the emulator
- If I replace
ARRAY_LENGTH(t2.arr_col) with ARRAY_LENGTH(IFNULL(t2.arr_col, [])), the query is executed successfully on the emulator
- I see the same behaviour if I use
ARRAY_TO_STRING() instead of ARRAY_LENGTH()
- The emulator crash error is:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x14ff744]
goroutine 114 [running]:
github.com/goccy/go-zetasqlite/internal.bindArrayLength({0xc0006dd8b0?, 0x1?, 0x3?})
/go/pkg/mod/github.com/goccy/go-zetasqlite@v0.19.3/internal/function_bind.go:2741 +0x24
github.com/goccy/go-zetasqlite/internal.setupNormalFuncMap.func1({0xc0006dd8a0?, 0xc000625950?, 0x2?})
/go/pkg/mod/github.com/goccy/go-zetasqlite@v0.19.3/internal/function_register.go:506 +0x38
reflect.Value.call({0x2b469c0?, 0xc000576a50?, 0x0?}, {0x2e6c7d7, 0x4}, {0xc0001adf68, 0x1, 0x0?})
/usr/local/go/src/reflect/value.go:596 +0xce7
reflect.Value.Call({0x2b469c0?, 0xc000576a50?, 0x1?}, {0xc0001adf68?, 0x0?, 0x14b51c0?})
/usr/local/go/src/reflect/value.go:380 +0xb9
github.com/mattn/go-sqlite3.(*functionInfo).Call(0xc000175740, 0x0?, {0x7fff7c03c958?, 0x0?, 0x0?})
/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/sqlite3.go:407 +0x75
github.com/mattn/go-sqlite3.callbackTrampoline(0x0?, 0x1, 0x7fff7c03c958)
/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/callback.go:39 +0x59
github.com/mattn/go-sqlite3._Cfunc__sqlite3_step_internal(0x7fff7c01cfa8)
_cgo_gotypes.go:367 +0x47
github.com/mattn/go-sqlite3.(*SQLiteRows).nextSyncLocked.func1(0x0?)
/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/sqlite3.go:2186 +0x45
github.com/mattn/go-sqlite3.(*SQLiteRows).nextSyncLocked(0xc000032fc0, {0xc0005e5500, 0x3, 0x0?})
/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/sqlite3.go:2186 +0x37
github.com/mattn/go-sqlite3.(*SQLiteRows).Next.func1()
/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/sqlite3.go:2167 +0x2c
created by github.com/mattn/go-sqlite3.(*SQLiteRows).Next in goroutine 82
/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/sqlite3.go:2166 +0x189
What happened?
What I'm doing:
SELECT FROM table_alias1,
INNER JOIN table_alias2,
WHERE length of arrays in a column differ
What's happening:
The emulator crashes with the error “panic: runtime error: invalid memory address or nil pointer dereference”
What did you expect to happen?
The query is executed successfully.
How can we reproduce it (as minimally and precisely as possible)?
Anything else we need to know?
Notes:
qryruns successfully on the BigQuery engineARRAY_LENGTH(t2.arr_col)with an integer (say 4), the query is executed successfully on the emulatorARRAY_LENGTH(t2.arr_col)withARRAY_LENGTH(IFNULL(t2.arr_col, [])), the query is executed successfully on the emulatorARRAY_TO_STRING()instead ofARRAY_LENGTH()