cube2222 / octosql

OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Mozilla Public License 2.0
4.75k stars 201 forks source link

Panic in count(1), count(*) queries #285

Closed eatonphil closed 2 years ago

eatonphil commented 2 years ago

Hey as mentioned on HN I was trying to count standard library functions and both of these functions panic-ed. While it's understandable some syntax might not be supported yet, I assumed panic-ing might mean an unintentional issue. So I figured I'd share the stack trace in case you'd like to know about it.

If this is the behavior that you expect though feel free to close!

$ octosql 'SELECT count(*) FROM docs.functions fs'
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/cube2222/octosql/datasources/docs.(*functionsExecuting).Run.func1(0xc000460030?, 0x0?)
        /home/runner/work/octosql/octosql/datasources/docs/functions.go:52 +0x90
sort.medianOfThree_func({0xc0002923e8?, 0xc000460030?}, 0xc0001a5d70?, 0x18?, 0x18?)
        /opt/hostedtoolcache/go/1.18.2/x64/src/sort/zfuncversion.go:53 +0x4a
sort.doPivot_func({0xc0002923e8?, 0xc000460030?}, 0x0, 0x1d)
        /opt/hostedtoolcache/go/1.18.2/x64/src/sort/zfuncversion.go:80 +0x115
sort.quickSort_func({0xc0002923e8?, 0xc000460030?}, 0xc0001a5d70?, 0x0?, 0x180?)
        /opt/hostedtoolcache/go/1.18.2/x64/src/sort/zfuncversion.go:143 +0x85
sort.Slice({0xca4460, 0xc0001a5d70}, 0x20?)
        /opt/hostedtoolcache/go/1.18.2/x64/src/sort/slice.go:20 +0x9f
github.com/cube2222/octosql/datasources/docs.(*functionsExecuting).Run(0xc0001a5cb0, {{0xf63f28?, 0xc0001f8e00?}, 0x0?}, 0xc0002dfbf0, 0x7?)
        /home/runner/work/octosql/octosql/datasources/docs/functions.go:51 +0x2e8
github.com/cube2222/octosql/execution/nodes.(*SimpleGroupBy).Run(0xc0002f00c0, {{0xf63f28?, 0xc0001f8e00?}, 0x0?}, 0xc0002dfbc0, 0xc0002dfb60)
        /home/runner/work/octosql/octosql/execution/nodes/simple_group_by.go:38 +0x228
github.com/cube2222/octosql/execution/nodes.(*Map).Run(0xc0002dfb00, {{0xf63f28?, 0xc0001f8e00?}, 0x0?}, 0xc0002dfb90, 0x0?)
        /home/runner/work/octosql/octosql/execution/nodes/map.go:23 +0xfc
github.com/cube2222/octosql/execution/nodes.(*Limit).Run(0xc000031720, {{0xf63f28?, 0xc0001f8e00?}, 0x0?}, 0xc0002dfb30, 0xc0000b8a00?)
        /home/runner/work/octosql/octosql/execution/nodes/limit.go:34 +0x3a6
github.com/cube2222/octosql/outputs/batch.(*OutputPrinter).Run(0xc0000b8a00, {{0xf63f28?, 0xc0001f8e00?}, 0x0?})
        /home/runner/work/octosql/octosql/outputs/batch/live_output.go:81 +0x396
github.com/cube2222/octosql/cmd.glob..func4(0x1574a00, {0xc0002ac6b0, 0x1, 0x1?})
        /home/runner/work/octosql/octosql/cmd/root.go:464 +0x3693
github.com/spf13/cobra.(*Command).execute(0x1574a00, {0xc000030030, 0x1, 0x1})
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:856 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0x1574a00)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:895
github.com/cube2222/octosql/cmd.Execute({0xf63f28?, 0xc0001f8e00?})
        /home/runner/work/octosql/octosql/cmd/root.go:477 +0x53
main.main()
        /home/runner/work/octosql/octosql/main.go:24 +0xe8
$ octosql 'SELECT count(fs.name) FROM docs.functions fs'
+---------------+
| count_fs.name |
+---------------+
|            29 |
+---------------+
$ octosql --version
octosql version 0.7.3
cube2222 commented 2 years ago

Thanks for the report!

I've already replicated it, should be fixed soon.

cube2222 commented 2 years ago

This is now fixed in https://github.com/cube2222/octosql/commit/f7a1b92ba65584bc6a2cb274a3c919b881d0fcfc.