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 when accessing variable inside switch-in-lateral-query-in-a-switch #5076

Closed
philrz opened this issue Mar 15, 2024 · 1 comment · Fixed by #5080
Closed

Panic when accessing variable inside switch-in-lateral-query-in-a-switch #5076

philrz opened this issue Mar 15, 2024 · 1 comment · Fixed by #5080
Labels
bug Something isn't working community

Comments

@philrz
Copy link
Contributor

philrz commented Mar 15, 2024

Repro is with Zed commit f1be6a4.

This is a simplified [ 🤪 ] example of a panic I bumped into while trying to come up with a response to a community user's inquiry in a Slack thread.

$ zq -version
Version: v1.14.0-17-gf1be6a4a

$ cat repro.zed 
const a = 1
const b = 2
switch a (
  case 1 => over this with val=this => (
    switch b (
      case 2 => yield val
    )
  )
)

$ echo '[1,2]' | zq -I repro.zed -
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
runtime/debug.Stack()
	/usr/local/opt/go@1.21/libexec/src/runtime/debug/stack.go:24 +0x5e
github.com/brimdata/zed/runtime/sam/op.(*Catcher).Pull.func1()
	/Users/phil/work/zed/runtime/sam/op/catcher.go:25 +0x3d
panic({0x2550000?, 0xc000916000?})
	/usr/local/opt/go@1.21/libexec/src/runtime/panic.go:914 +0x21f
github.com/brimdata/zed/runtime/sam/expr.Var.Eval(...)
	/Users/phil/work/zed/runtime/sam/expr/var.go:14
github.com/brimdata/zed/runtime/sam/op/yield.(*Op).Pull(0xc0006e0a20, 0x10?)
	/Users/phil/work/zed/runtime/sam/op/yield/yield.go:31 +0x432
github.com/brimdata/zed/runtime/sam/op/traverse.(*Exit).pullPlatoon(0xc0006e0a50)
	/Users/phil/work/zed/runtime/sam/op/traverse/scope.go:222 +0x32
github.com/brimdata/zed/runtime/sam/op/traverse.(*Exit).Pull(0xc0006e0a50, 0x5?)
	/Users/phil/work/zed/runtime/sam/op/traverse/scope.go:208 +0x2b
github.com/brimdata/zed/runtime/sam/op.(*Single).Pull(0xc000407398, 0x60)
	/Users/phil/work/zed/runtime/sam/op/mux.go:134 +0x2b
github.com/brimdata/zed/runtime/sam/op.(*Catcher).Pull(0x3cc1108?, 0xc0?)
	/Users/phil/work/zed/runtime/sam/op/catcher.go:28 +0x62
github.com/brimdata/zed/runtime/exec.(*Query).Pull(0x4abf4498?, 0xd8?)
	/Users/phil/work/zed/runtime/exec/query.go:59 +0x3e
github.com/brimdata/zed/zbuf.CopyPuller({0x4abf4498, 0xc000406ee8}, {0x28c1520, 0xc0006e0a80})
	/Users/phil/work/zed/zbuf/batch.go:162 +0x4d
github.com/brimdata/zed/cli/zq.(*Command).Run(0xc000124a80, {0xc0000400b0, 0x1, 0x1})
	/Users/phil/work/zed/cli/zq/command.go:162 +0x79e
github.com/brimdata/zed/pkg/charm.path.run({0xc00007a2d0?, 0x1, 0x1}, {0xc0000400b0?, 0x1, 0x0?})
	/Users/phil/work/zed/pkg/charm/path.go:11 +0x79
github.com/brimdata/zed/pkg/charm.(*Spec).ExecRoot(0x100874b?, {0xc000040090, 0x3, 0x3})
	/Users/phil/work/zed/pkg/charm/charm.go:63 +0x3f
main.main()
	/Users/phil/work/zed/cmd/zq/main.go:11 +0x5b
@philrz philrz added bug Something isn't working community labels Mar 15, 2024
mattnibs added a commit that referenced this issue Mar 18, 2024
Fix issue with exprswitch op where batch variables where not getting propagated
to inner batches.

Closes #5076
mattnibs added a commit that referenced this issue Mar 19, 2024
Fix issue with exprswitch op where batch variables where not getting propagated
to inner batches.

Closes #5076
@philrz
Copy link
Contributor Author

philrz commented Mar 19, 2024

Verified in Zed commit 3e5febe.

The program shown in the repro above no longer generates a panic.

$ zq -version
Version: v1.14.0-21-g3e5febe7

$ echo '[1,2]' | zq -I repro.zed -
[1,2]
[1,2]

Thanks @mattnibs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant