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

index out of range error when doing GROUP BY on empty table #107

Open
nijssen opened this issue May 8, 2023 · 1 comment
Open

index out of range error when doing GROUP BY on empty table #107

nijssen opened this issue May 8, 2023 · 1 comment

Comments

@nijssen
Copy link

nijssen commented May 8, 2023

If you have an empty table, and try to group by on it, then this error will occur.
For example:

touch oops.csv # Maybe a previous step gave an empty output
csvq  'select a, max(b) from oops group by a'
[Fatal Error] runtime error: index out of range [-1]
An unexpected error has occurred. Please report this problem to: https://github.com/mithrandie/csvq/issues

Stack:
  0: github.com/mithrandie/csvq/lib/query.(*Processor).execute.func1 [github.com/mithrandie/csvq/lib/query/processor.go:95]
  1: runtime.gopanic [runtime/panic.go:884]
  2: runtime.goPanicIndex [runtime/panic.go:113]
  3: github.com/mithrandie/csvq/lib/query.(*View).group [github.com/mithrandie/csvq/lib/query/view.go:240]
  4: github.com/mithrandie/csvq/lib/query.(*View).GroupBy [github.com/mithrandie/csvq/lib/query/view.go:109]
  5: github.com/mithrandie/csvq/lib/query.selectEntity [github.com/mithrandie/csvq/lib/query/query.go:206]
  6: github.com/mithrandie/csvq/lib/query.Select [github.com/mithrandie/csvq/lib/query/query.go:122]
  7: github.com/mithrandie/csvq/lib/query.(*Processor).ExecuteStatement [github.com/mithrandie/csvq/lib/query/processor.go:197]
  8: github.com/mithrandie/csvq/lib/query.(*Processor).execute [github.com/mithrandie/csvq/lib/query/processor.go:103]
  9: github.com/mithrandie/csvq/lib/query.(*Processor).Execute [github.com/mithrandie/csvq/lib/query/processor.go:83]
  10: github.com/mithrandie/csvq/lib/action.Run [github.com/mithrandie/csvq/lib/action/run.go:60]
  11: github.com/mithrandie/csvq/lib/cli.Run.func5 [github.com/mithrandie/csvq/lib/cli/app.go:297]
  12: github.com/mithrandie/csvq/lib/cli.commandAction.func1 [github.com/mithrandie/csvq/lib/cli/app.go:373]
  13: github.com/urfave/cli/v2.(*App).RunContext [github.com/urfave/cli/v2@v2.10.3/app.go:350]
  14: github.com/urfave/cli/v2.(*App).Run [github.com/urfave/cli/v2@v2.10.3/app.go:247]
  15: github.com/mithrandie/csvq/lib/cli.Run [github.com/mithrandie/csvq/lib/cli/app.go:306]
  16: main.main [github.com/mithrandie/csvq/main.go:8]
  17: runtime.main [runtime/proc.go:250]
  18: runtime.goexit [runtime/asm_amd64.s:1594]

I guess the desired behavior isn't exactly clear: since the file is empty csvq cannot know the column names; on the other hand maybe we could add a flag to just assume any unknown columns are treated as null?

(NB: although I used csv in above example, my real use case is JSON; then the file would become just [] and the same problem occurs)

@mithrandie
Copy link
Owner

I checked the behavior. As you reported, specifying an non-existent column name in a grouping results a fatal error.

I also wanted a way to avoid raising errors when specifying a column that does not exist. I will consider your suggestion. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants