@@ -5,12 +5,14 @@ import (
55
66 "github.com/brimdata/zed"
77 "github.com/brimdata/zed/pkg/field"
8+ "github.com/brimdata/zed/runtime/expr/dynfield"
89 "github.com/brimdata/zed/zson"
910)
1011
1112type Lval struct {
12- Elems []LvalElem
13- cache field.Path
13+ Elems []LvalElem
14+ cache []zed.Value
15+ fieldCache field.Path
1416}
1517
1618func NewLval (evals []LvalElem ) * Lval {
@@ -19,18 +21,36 @@ func NewLval(evals []LvalElem) *Lval {
1921
2022// Eval returns the path of the lval. If there's an error the returned *zed.Value
2123// will not be nill.
22- func (l * Lval ) Eval (ectx Context , this * zed.Value ) (field .Path , error ) {
24+ func (l * Lval ) Eval (ectx Context , this * zed.Value ) (dynfield .Path , error ) {
2325 l .cache = l .cache [:0 ]
2426 for _ , e := range l .Elems {
25- name , err := e .Eval (ectx , this )
27+ val , err := e .Eval (ectx , this )
2628 if err != nil {
2729 return nil , err
2830 }
29- l .cache = append (l .cache , name )
31+ l .cache = append (l .cache , * val )
3032 }
3133 return l .cache , nil
3234}
3335
36+ func (l * Lval ) EvalAsRecordPath (ectx Context , this * zed.Value ) (field.Path , error ) {
37+ l .fieldCache = l .fieldCache [:0 ]
38+ for _ , e := range l .Elems {
39+ val , err := e .Eval (ectx , this )
40+ if err != nil {
41+ return nil , err
42+ }
43+ if ! val .IsString () {
44+ // XXX Add context to error so we know what element is failing but
45+ // let's wait until we can test this so we have a feel for what we
46+ // want to see.
47+ return nil , errors .New ("field reference is not a string" )
48+ }
49+ l .fieldCache = append (l .fieldCache , val .AsString ())
50+ }
51+ return l .fieldCache , nil
52+ }
53+
3454// Path returns the receiver's path. Path returns false when the receiver
3555// contains a dynamic element.
3656func (l * Lval ) Path () (field.Path , bool ) {
@@ -46,15 +66,15 @@ func (l *Lval) Path() (field.Path, bool) {
4666}
4767
4868type LvalElem interface {
49- Eval (ectx Context , this * zed.Value ) (string , error )
69+ Eval (ectx Context , this * zed.Value ) (* zed. Value , error )
5070}
5171
5272type StaticLvalElem struct {
5373 Name string
5474}
5575
56- func (l * StaticLvalElem ) Eval (_ Context , _ * zed.Value ) (string , error ) {
57- return l .Name , nil
76+ func (l * StaticLvalElem ) Eval (_ Context , _ * zed.Value ) (* zed. Value , error ) {
77+ return zed . NewString ( l .Name ) , nil
5878}
5979
6080type ExprLvalElem struct {
@@ -69,17 +89,12 @@ func NewExprLvalElem(zctx *zed.Context, e Evaluator) *ExprLvalElem {
6989 }
7090}
7191
72- func (l * ExprLvalElem ) Eval (ectx Context , this * zed.Value ) (string , error ) {
92+ func (l * ExprLvalElem ) Eval (ectx Context , this * zed.Value ) (* zed. Value , error ) {
7393 val := l .eval .Eval (ectx , this )
7494 if val .IsError () {
75- return "" , lvalErr (ectx , val )
76- }
77- if ! val .IsString () {
78- if val = l .caster .Eval (ectx , val ); val .IsError () {
79- return "" , errors .New ("field reference is not a string" )
80- }
95+ return nil , lvalErr (ectx , val )
8196 }
82- return val . AsString () , nil
97+ return val , nil
8398}
8499
85100func lvalErr (ectx Context , errVal * zed.Value ) error {
0 commit comments