Skip to content

Commit

Permalink
explode: move "as" check to semantic pass (#4772)
Browse files Browse the repository at this point in the history
Move the "as" check on explode proc from kernel compilation phase to
semantic phase where this belongs.
  • Loading branch information
mattnibs authored Sep 19, 2023
1 parent aaf9752 commit aa06e5b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion compiler/ast/dag/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type (
Kind string `json:"kind" unpack:""`
Args []Expr `json:"args"`
Type string `json:"type"`
As Expr `json:"as"`
As string `json:"as"`
}
Filter struct {
Kind string `json:"kind" unpack:""`
Expand Down
9 changes: 1 addition & 8 deletions compiler/kernel/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,7 @@ func (b *Builder) compileLeaf(o dag.Op, parent zbuf.Puller) (zbuf.Puller, error)
if err != nil {
return nil, err
}
as, err := compileLval(v.As)
if err != nil {
return nil, err
}
if len(as) != 1 {
return nil, errors.New("explode field must be a top-level field")
}
return explode.New(b.octx.Zctx, parent, args, typ, as.Leaf())
return explode.New(b.octx.Zctx, parent, args, typ, v.As)
case *dag.Over:
return b.compileOver(parent, v)
case *dag.Yield:
Expand Down
16 changes: 10 additions & 6 deletions compiler/semantic/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,17 +692,21 @@ func (a *analyzer) semOp(o ast.Op, seq dag.Seq) (dag.Seq, error) {
if err != nil {
return nil, err
}
var as dag.Expr
var as string
if o.As == nil {
as = &dag.This{
Kind: "This",
Path: field.Path{"value"},
}
as = "value"
} else {
as, err = a.semExpr(o.As)
e, err := a.semExpr(o.As)
if err != nil {
return nil, err
}
this, ok := e.(*dag.This)
if !ok {
return nil, errors.New("explode: as clause must be a field reference")
} else if len(this.Path) != 1 {
return nil, errors.New("explode: field must be a top-level field")
}
as = this.Path[0]
}
return append(seq, &dag.Explode{
Kind: "Explode",
Expand Down

0 comments on commit aa06e5b

Please sign in to comment.