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

panic: runtime error: invalid memory address or nil pointer dereference when calling some numbering functions over columns containing null value. #351

Open
Yhkwkm opened this issue Aug 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Yhkwkm
Copy link

Yhkwkm commented Aug 22, 2024

What happened?

When I tried to call numbering window functions such as DENSE_RANK, RANK, or PERCENT_RANK over columns containing null values, the emulator panics and gets the following (the container logs):

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x90 pc=0x1522eba]

goroutine 299 [running]:
github.com/goccy/go-zetasqlite/internal.(*WINDOW_DENSE_RANK).Done.func1({0x2aacf00?, 0xc0011b0180?, 0x1?}, 0x0, 0x0)
	/go/pkg/mod/github.com/goccy/[email protected]/internal/function_window.go:873 +0x2fa
github.com/goccy/go-zetasqlite/internal.(*WindowFuncAggregatedStatus).Done(0xc00116eab0, 0xc000a9b420)
	/go/pkg/mod/github.com/goccy/[email protected]/internal/function_window_option.go:458 +0x328
github.com/goccy/go-zetasqlite/internal.(*WINDOW_DENSE_RANK).Done(0x1?, 0x0?)
	/go/pkg/mod/github.com/goccy/[email protected]/internal/function_window.go:833 +0x4b
github.com/goccy/go-zetasqlite/internal.bindWindowDenseRank.func1.2(0xc000586300?)
	/go/pkg/mod/github.com/goccy/[email protected]/internal/function_bind.go:4064 +0x1d
github.com/goccy/go-zetasqlite/internal.(*WindowAggregator).Done(0x2?)
	/go/pkg/mod/github.com/goccy/[email protected]/internal/function_bind.go:141 +0x1e
reflect.Value.call({0x2b8f160?, 0xc00119e9f0?, 0x0?}, {0x2e50b54, 0x4}, {0x0, 0x0, 0x30fd748?})
	/usr/local/go/src/reflect/value.go:596 +0xce7
reflect.Value.Call({0x2b8f160?, 0xc00119e9f0?, 0xc000a9bbe8?}, {0x0?, 0x2b66680?, 0xc000054450?})
	/usr/local/go/src/reflect/value.go:380 +0xb9
github.com/mattn/go-sqlite3.(*aggInfo).Done(0xc0005211d0, 0x7f57800639a8?)
	/go/pkg/mod/github.com/mattn/[email protected]/sqlite3.go:481 +0x9b
github.com/mattn/go-sqlite3.doneTrampoline(0xc001186d00?)
	/go/pkg/mod/github.com/mattn/[email protected]/callback.go:52 +0x37
github.com/matte/go-sqlite3._Cfunc__sqlite3_step_internal(0x7f5780055b18)
	_cgo_gotypes.go:367 +0x47
github.com/mattn/go-sqlite3.(*SQLiteRows).nextSyncLocked.func1(0x0?)
	/go/pkg/mod/github.com/mattn/[email protected]/sqlite3.go:2186 +0x45
github.com/matte/go-sqlite3.(*SQLiteRows).nextSyncLocked(0xc00117a720, {0xc0008a05e0, 0x1, 0x0?})
	/go/pkg/mod/github.com/mattn/[email protected]/sqlite3.go:2186 +0x37
github.com/mattn/go-sqlite3.(*SQLiteRows).Next.func1()
	/go/pkg/mod/github.com/mattn/[email protected]/sqlite3.go:2167 +0x2c
created by github.com/mattn/go-sqlite3.(*SQLiteRows).Next in Goroutine 93
	/go/pkg/mod/github.com/mattn/[email protected]/sqlite3.go:2166 +0x189
[bigquery-emulator] REST server listening at 0.0.0.0:9050
[bigquery-emulator] gRPC server listening at 0.0.0.0:9060
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x90 pc=0x1522eba]

Finally, the emulator crashed with SEGV, and the connection was terminated.

What did you expect to happen?

It should never crash and return the rank (dense rank) values.

How can we reproduce it (as minimally and precisely as possible)?

Preparing a table with null values and running a query with RANK() functions:

$ bq --api http://0.0.0.0:9050/ query --project_id=test "SELECT * FROM dataset1.table_a"
+------+-------+
|  id  | name  |
+------+-------+
|    1 | alice |
| NULL | bob   |
+------+-------+
$ bq --api http://0.0.0.0:9050 query --project_id=test \
      "SELECT RANK() OVER(PARTITION BY name ORDER BY id DESC) AS rnk FROM dataset1.table_a"

BigQuery error in query operation: Could not connect with BigQuery server due to: RemoteDisconnected('Remote end closed connection without response')

Anything else we need to know?

It seems that the error doesn't happen when I use other number functions like ROW_NUMBER, CUME_DIST, or NTILE.

@Yhkwkm Yhkwkm added the bug Something isn't working label Aug 22, 2024
@Yhkwkm Yhkwkm changed the title panic: runtime error: invalid memory address or nil pointer dereference when DENSE_RANK or RANK function over columns containing null value. panic: runtime error: invalid memory address or nil pointer dereference when some numbering functions over columns containing null value. Aug 22, 2024
@Yhkwkm Yhkwkm changed the title panic: runtime error: invalid memory address or nil pointer dereference when some numbering functions over columns containing null value. panic: runtime error: invalid memory address or nil pointer dereference when calling some numbering functions over columns containing null value. Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant