diff --git a/compiler/parser/ztests/shape.yaml b/compiler/parser/ztests/shape.yaml deleted file mode 100644 index 1aea39c97d..0000000000 --- a/compiler/parser/ztests/shape.yaml +++ /dev/null @@ -1,7 +0,0 @@ -spq: shape(this,<{s:string}>) - -input: | - {s:1} - -output: | - {s:"1"} diff --git a/compiler/rungen/expr.go b/compiler/rungen/expr.go index 360fe731ac..ae7efdccc7 100644 --- a/compiler/rungen/expr.go +++ b/compiler/rungen/expr.go @@ -308,9 +308,6 @@ func (b *Builder) compileAssignment(node *dag.Assignment) (expr.Assignment, erro } func (b *Builder) compileCall(call *dag.CallExpr) (expr.Evaluator, error) { - if tf := expr.NewShaperTransform(call.Tag); tf != 0 { - return b.compileShaper(call.Args, tf) - } // First check if call is to a user defined function, otherwise check for // builtin function. var fn expr.Function @@ -361,18 +358,6 @@ func (b *Builder) compileMapCall(a *dag.MapCallExpr) (expr.Evaluator, error) { return expr.NewMapCall(b.sctx(), e, lambda), nil } -func (b *Builder) compileShaper(args []dag.Expr, tf expr.ShaperTransform) (expr.Evaluator, error) { - field, err := b.compileExpr(args[0]) - if err != nil { - return nil, err - } - typExpr, err := b.compileExpr(args[1]) - if err != nil { - return nil, err - } - return expr.NewShaper(b.sctx(), field, typExpr, tf) -} - func (b *Builder) compileExprs(in []dag.Expr) ([]expr.Evaluator, error) { var exprs []expr.Evaluator for _, e := range in { diff --git a/compiler/rungen/vexpr.go b/compiler/rungen/vexpr.go index f956c0f833..ed00e34751 100644 --- a/compiler/rungen/vexpr.go +++ b/compiler/rungen/vexpr.go @@ -191,9 +191,6 @@ func (b *Builder) compileVamCall(call *dag.CallExpr) (vamexpr.Evaluator, error) if call.Tag == "cast" { return b.compileVamCast(call.Args) } - if tf := expr.NewShaperTransform(call.Tag); tf != 0 { - return b.compileVamShaper(call.Args, tf) - } var fn vamexpr.Function if f, ok := b.funcs[call.Tag]; ok { var err error @@ -256,14 +253,6 @@ func (b *Builder) compileVamCast(args []dag.Expr) (vamexpr.Evaluator, error) { return vamexpr.NewSamExpr(e), nil } -func (b *Builder) compileVamShaper(args []dag.Expr, tf expr.ShaperTransform) (vamexpr.Evaluator, error) { - shaper, err := b.compileShaper(args, tf) - if err != nil { - return nil, err - } - return vamexpr.NewSamExpr(shaper), nil -} - func (b *Builder) compileVamRecordExpr(e *dag.RecordExpr) (vamexpr.Evaluator, error) { var elems []vamexpr.RecordElem for _, elem := range e.Elems { diff --git a/compiler/semantic/expr.go b/compiler/semantic/expr.go index 1314697228..6c8bf3cda4 100644 --- a/compiler/semantic/expr.go +++ b/compiler/semantic/expr.go @@ -724,11 +724,6 @@ func (t *translator) semCallByName(call *ast.Call, name string, args []sem.Expr) } nameLower := strings.ToLower(name) switch { - case expr.NewShaperTransform(nameLower) != 0: - if err := function.CheckArgCount(nargs, 2, 2); err != nil { - t.error(call, err) - return badExpr() - } case nameLower == "map": return t.semMapCall(call, args) case nameLower == "grep": diff --git a/compiler/ztests/badshaper.yaml b/compiler/ztests/badshaper.yaml deleted file mode 100644 index a03d9a72fd..0000000000 --- a/compiler/ztests/badshaper.yaml +++ /dev/null @@ -1,21 +0,0 @@ -script: | - ! super -s -I badshaper.spq - - -inputs: - - name: stdin - data: | - {"_path": "bar", "testfield": null} - - name: badshaper.spq - data: | - type foo={_path:string,testfield:"null"} - values shape(foo) - -outputs: - - name: stderr - data: | - no such type name: "null" in badshaper.spq at line 1, column 10: - type foo={_path:string,testfield:"null"} - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - too few arguments in badshaper.spq at line 2, column 8: - values shape(foo) - ~~~~~~~~~~ diff --git a/runtime/sam/expr/shaper.go b/runtime/sam/expr/shaper.go index d65f18541e..eb6d76c085 100644 --- a/runtime/sam/expr/shaper.go +++ b/runtime/sam/expr/shaper.go @@ -25,82 +25,6 @@ const ( Order ) -func NewShaperTransform(s string) ShaperTransform { - switch s { - case "crop": - return Crop - case "fill": - return Fill - case "fit": - return Crop | Fill - case "order": - return Order - case "shape": - return Cast | Fill | Order - } - return 0 -} - -// NewShaper returns a shaper that will shape the result of expr -// to the type returned by typeExpr according to tf. -func NewShaper(sctx *super.Context, expr, typeExpr Evaluator, tf ShaperTransform) (Evaluator, error) { - if l, ok := typeExpr.(*Literal); ok { - typeVal := l.val - switch id := typeVal.Type().ID(); { - case id == super.IDType: - typ, err := sctx.LookupByValue(typeVal.Bytes()) - if err != nil { - return nil, err - } - return NewConstShaper(sctx, expr, typ, tf), nil - case id == super.IDString && tf == Cast: - name := super.DecodeString(typeVal.Bytes()) - if _, err := super.NewContext().LookupTypeNamed(name, super.TypeNull); err != nil { - return nil, err - } - return &casterNamedType{sctx, expr, name}, nil - } - return nil, fmt.Errorf("shaper type argument is not a type: %s", sup.FormatValue(typeVal)) - } - return &Shaper{ - sctx: sctx, - expr: expr, - typeExpr: typeExpr, - transforms: tf, - shapers: make(map[super.Type]*ConstShaper), - }, nil -} - -type Shaper struct { - sctx *super.Context - expr Evaluator - typeExpr Evaluator - transforms ShaperTransform - - shapers map[super.Type]*ConstShaper -} - -func (s *Shaper) Eval(this super.Value) super.Value { - typeVal := s.typeExpr.Eval(this) - switch id := typeVal.Type().ID(); { - case id == super.IDType: - typ, err := s.sctx.LookupByValue(typeVal.Bytes()) - if err != nil { - return s.sctx.NewError(err) - } - shaper, ok := s.shapers[typ] - if !ok { - shaper = NewConstShaper(s.sctx, s.expr, typ, s.transforms) - s.shapers[typ] = shaper - } - return shaper.Eval(this) - case id == super.IDString && s.transforms == Cast: - name := super.DecodeString(typeVal.Bytes()) - return (&casterNamedType{s.sctx, s.expr, name}).Eval(this) - } - return s.sctx.WrapError("shaper type argument is not a type", typeVal) -} - type ConstShaper struct { sctx *super.Context expr Evaluator diff --git a/runtime/ztests/expr/shape-crop-arrays-sets.yaml b/runtime/ztests/expr/shape-crop-arrays-sets.yaml deleted file mode 100644 index 51a6ea1d04..0000000000 --- a/runtime/ztests/expr/shape-crop-arrays-sets.yaml +++ /dev/null @@ -1,10 +0,0 @@ -spq: | - values crop(this, <{set:|[{b:string}]|,arr:[{a:string}]}>) - -vector: true - -input: | - {arr:[{a:"one",b:"two"},{a:"three",b:"four"}],set:|[{a:"one",b:"two"},{a:"three",b:"four"}]|} - -output: | - {arr:[{a:"one"},{a:"three"}],set:|[{b:"two"},{b:"four"}]|} diff --git a/runtime/ztests/expr/shape-crop-named.yaml b/runtime/ztests/expr/shape-crop-named.yaml deleted file mode 100644 index ac4dbc04f2..0000000000 --- a/runtime/ztests/expr/shape-crop-named.yaml +++ /dev/null @@ -1,15 +0,0 @@ -spq: | - type port=int64 - type prec={p:port} - type parr=[prec] - values crop(this, <{a:prec,b:parr}>) - -vector: true - -input: | - {a:{p:1::=port,q:null::port},b:[{p:1,q:2::port}],c:3::port} - {a:{p:1::(myport=int16),q:null::(port=int64)},b:[{p:1::myport,q:2::port}],c:3::port} - -output: | - {a:{p:1::=port},b:[{p:1}]} - {a:{p:1::(myport=int16)},b:[{p:1::myport}]} diff --git a/runtime/ztests/expr/shape-crop-null.yaml b/runtime/ztests/expr/shape-crop-null.yaml deleted file mode 100644 index 7f81af8d33..0000000000 --- a/runtime/ztests/expr/shape-crop-null.yaml +++ /dev/null @@ -1,12 +0,0 @@ -spq: values crop(this, <{f:null}>) - -vector: true - -input: &input | - {f:1::=int64_named}::=int64_record_named - {f:[1::=int64_named]::=array_named}::=array_record_named - {f:{g:1::=int64_named}::=record_named}::=record_record_named - {f:|[1::=int64_named]|::=set_named}::=set_record_named - {f:1::=int64_named::(union_named=int64|int64_named)}::=union_record_named - -output: *input diff --git a/runtime/ztests/expr/shape-crop.yaml b/runtime/ztests/expr/shape-crop.yaml deleted file mode 100644 index 3bf6fd21e8..0000000000 --- a/runtime/ztests/expr/shape-crop.yaml +++ /dev/null @@ -1,14 +0,0 @@ -spq: | - put - -- crop to type with same field order - id:=crop(id, <{orig_h:ip,orig_p:port=uint16}>), - -- crop to type with different field order, does not change output order - id2:=crop(id, <{orig_p:port=uint16,orig_h:ip}>) - -vector: true - -input: | - {id:{orig_h:ff02::fb,orig_p:5353::(port=uint16),resp_h:1.2.3.4,resp_p:5353::port},other:123.} - -output: | - {id:{orig_h:ff02::fb,orig_p:5353::(port=uint16)},other:123.,id2:{orig_h:ff02::fb,orig_p:5353::port}} diff --git a/runtime/ztests/expr/shape-fill-arrays-sets.yaml b/runtime/ztests/expr/shape-fill-arrays-sets.yaml deleted file mode 100644 index 080b18966f..0000000000 --- a/runtime/ztests/expr/shape-fill-arrays-sets.yaml +++ /dev/null @@ -1,10 +0,0 @@ -spq: | - values fill(this, <{arr:[{b:string,a:string}],set:|[{b:string,a:string}]|}>) - -vector: true - -input: | - {arr:[{a:"one"},{a:"three"}],set:|[{a:"one"},{a:"three"}]|} - -output: | - {arr:[{a:"one",b:null::string},{a:"three",b:null::string}],set:|[{a:"one",b:null::string},{a:"three",b:null::string}]|} diff --git a/runtime/ztests/expr/shape-fill-fit.yaml b/runtime/ztests/expr/shape-fill-fit.yaml deleted file mode 100644 index a355116c03..0000000000 --- a/runtime/ztests/expr/shape-fill-fit.yaml +++ /dev/null @@ -1,10 +0,0 @@ -spq: | - cut id_filled:=fill(id, <{orig_h:ip,orig_p:port=uint16}>), id_fitted:=fit(id, <{orig_h:ip,orig_p:port=uint16}>) - -vector: true - -input: | - {id:{orig_h:"ff02::fb",resp_h:"ff02::fb"}} - -output: | - {id_filled:{orig_h:"ff02::fb",resp_h:"ff02::fb",orig_p:null::(port=uint16)},id_fitted:{orig_h:"ff02::fb",orig_p:null::port}} diff --git a/runtime/ztests/expr/shape-fill-named.yaml b/runtime/ztests/expr/shape-fill-named.yaml deleted file mode 100644 index ab8190a16c..0000000000 --- a/runtime/ztests/expr/shape-fill-named.yaml +++ /dev/null @@ -1,15 +0,0 @@ -spq: | - type port=int64 - type prec={p:port,q:port} - type parr=[prec] - values fill(this, <{a:prec,b:parr,c:port}>) - -vector: true - -input: | - {a:{q:1},b:[{p:1}]} - {a:{q:1::(myport=int16)},b:[{p:1::myport}]} - -output: | - {a:{q:1,p:null::(port=int64)},b:[{p:1,q:null::port}],c:null::port} - {a:{q:1::(myport=int16),p:null::(port=int64)},b:[{p:1::myport,q:null::port}],c:null::port} diff --git a/runtime/ztests/expr/shape-fill-null.yaml b/runtime/ztests/expr/shape-fill-null.yaml deleted file mode 100644 index ee36d999cc..0000000000 --- a/runtime/ztests/expr/shape-fill-null.yaml +++ /dev/null @@ -1,12 +0,0 @@ -spq: values fill(this, <{f:null}>) - -vector: true - -input: &input | - {f:1::=int64_named}::=int64_record_named - {f:[1::=int64_named]::=array_named}::=array_record_named - {f:{g:1::=int64_named}::=record_named}::=record_record_named - {f:|[1::=int64_named]|::=set_named}::=set_record_named - {f:1::=int64_named::(union_named=int64|int64_named)}::=union_record_named - -output: *input diff --git a/runtime/ztests/expr/shape-fill.yaml b/runtime/ztests/expr/shape-fill.yaml deleted file mode 100644 index 3d0d899b3c..0000000000 --- a/runtime/ztests/expr/shape-fill.yaml +++ /dev/null @@ -1,13 +0,0 @@ -spq: values fill(this, <{a:{b:{c:string}}}>) - -vector: true - -input: | - {s:"x"} - {a:null::{s:string}} - {a:{s:null::string}} - -output: | - {s:"x",a:null::{b:{c:string}}} - {a:null::{s:string,b:{c:string}}} - {a:{s:null::string,b:null::{c:string}}} diff --git a/runtime/ztests/expr/shape-named.yaml b/runtime/ztests/expr/shape-named.yaml deleted file mode 100644 index 7c4f19e9b4..0000000000 --- a/runtime/ztests/expr/shape-named.yaml +++ /dev/null @@ -1,13 +0,0 @@ -spq: | - type port=int64 - type prec={p:port,q:port} - type parr=[prec] - values shape(this, <{c:port,b:parr,a:prec}>) - -vector: true - -input: | - {a:{q:1::(myport=int16),p:2::myport},b:[{q:1}],c:3} - -output: | - {c:3::=port,b:[{p:null::port,q:1::port}::=prec]::=parr,a:{p:2,q:1}::prec} diff --git a/runtime/ztests/expr/shape-nested.yaml b/runtime/ztests/expr/shape-nested.yaml deleted file mode 100644 index 26064a004b..0000000000 --- a/runtime/ztests/expr/shape-nested.yaml +++ /dev/null @@ -1,14 +0,0 @@ -spq: | - cut x := shape(this, <{a:{a:float64,b:float64}}>) - -vector: true - -input: | - {"a": {"a": 1}} - {"a": {"b": 1}} - {"a": {"c": 1, "b": 1}} - -output: | - {x:{a:{a:1.,b:null::float64}}} - {x:{a:{a:null::float64,b:1.}}} - {x:{a:{a:null::float64,b:1.,c:1}}} diff --git a/runtime/ztests/expr/shape-null-cast.yaml b/runtime/ztests/expr/shape-null-cast.yaml deleted file mode 100644 index 44ddd47b25..0000000000 --- a/runtime/ztests/expr/shape-null-cast.yaml +++ /dev/null @@ -1,10 +0,0 @@ -spq: | - values shape(this, <{a:string,b:string}>) - -vector: true - -input: | - {a:null,b:null::int64} - -output: | - {a:null::string,b:null::string} diff --git a/runtime/ztests/expr/shape-null-container.yaml b/runtime/ztests/expr/shape-null-container.yaml deleted file mode 100644 index 5679d09ecb..0000000000 --- a/runtime/ztests/expr/shape-null-container.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# issues #2853 #2879 - -spq: | - values shape(this, <{ - array:[string], - record:{c1:int64,c2:string,c3:time} - }>) - -vector: true - -input: | - {array:null,record:null} - -output-flags: -pretty=2 - -output: | - { - array: null::[string], - record: null::{c1:int64,c2:string,c3:time} - } diff --git a/runtime/ztests/expr/shape-order-arrays-sets.yaml b/runtime/ztests/expr/shape-order-arrays-sets.yaml deleted file mode 100644 index e7057f47af..0000000000 --- a/runtime/ztests/expr/shape-order-arrays-sets.yaml +++ /dev/null @@ -1,10 +0,0 @@ -spq: | - values order(this, <{set:|[{b:string,a:string}]|,arr:[{b:string,a:string}]}>) - -vector: true - -input: | - {arr:[{a:"one",b:"two"},{a:"three",b:"four"}],set:|[{a:"one",b:"two"},{a:"three",b:"four"}]|} - -output: | - {set:|[{b:"two",a:"one"},{b:"four",a:"three"}]|,arr:[{b:"two",a:"one"},{b:"four",a:"three"}]} diff --git a/runtime/ztests/expr/shape-order-named.yaml b/runtime/ztests/expr/shape-order-named.yaml deleted file mode 100644 index 0a161f31e6..0000000000 --- a/runtime/ztests/expr/shape-order-named.yaml +++ /dev/null @@ -1,15 +0,0 @@ -spq: | - type port=int64 - type prec={p:port,q:port} - type parr=[prec] - values order(this, <{c:port,b:parr,a:prec}>) - -vector: true - -input: | - {a:{q:1::=port,p:2::port},b:[{q:1,p:2::port}],c:3::port} - {a:{q:1::(myport=int16),p:2::myport},b:[{q:1::myport,p:2::myport}],c:3::myport} - -output: | - {c:3::=port,b:[{p:2::port,q:1}],a:{p:2::port,q:1::port}} - {c:3::(myport=int16),b:[{p:2::myport,q:1::myport}],a:{p:2::myport,q:1::myport}} diff --git a/runtime/ztests/expr/shape-order-null.yaml b/runtime/ztests/expr/shape-order-null.yaml deleted file mode 100644 index ff719d8af9..0000000000 --- a/runtime/ztests/expr/shape-order-null.yaml +++ /dev/null @@ -1,12 +0,0 @@ -spq: values order(this, <{f:null}>) - -vector: true - -input: &input | - {f:1::=int64_named}::=int64_record_named - {f:[1::=int64_named]::=array_named}::=array_record_named - {f:{g:1::=int64_named}::=record_named}::=record_record_named - {f:|[1::=int64_named]|::=set_named}::=set_record_named - {f:1::=int64_named::(union_named=int64|int64_named)}::=union_record_named - -output: *input diff --git a/runtime/ztests/expr/shape-order.yaml b/runtime/ztests/expr/shape-order.yaml deleted file mode 100644 index 0d25274be6..0000000000 --- a/runtime/ztests/expr/shape-order.yaml +++ /dev/null @@ -1,12 +0,0 @@ -spq: | - values order(this, <{id: {orig_h: string, orig_p: port=uint16, resp_h:ip,resp_p:port}}>) - -vector: true - -input: | - {id:{orig_h:"ff02::fb",orig_p:5353::(port=uint16),resp_p:5354::port,resp_h:"1.2.3.4"},other:123.} - {b:2,c:3,id:{resp_p:4,g:7,resp_h:"3",f:6,orig_p:2,orig_h:"1",e:5},a:1} - -output: | - {id:{orig_h:"ff02::fb",orig_p:5353::(port=uint16),resp_h:"1.2.3.4",resp_p:5354::port},other:123.} - {id:{orig_h:"1",orig_p:2,resp_h:"3",resp_p:4,e:5,f:6,g:7},a:1,b:2,c:3} diff --git a/runtime/ztests/expr/shape-string-time-err.yaml b/runtime/ztests/expr/shape-string-time-err.yaml deleted file mode 100644 index b42d4f5f74..0000000000 --- a/runtime/ztests/expr/shape-string-time-err.yaml +++ /dev/null @@ -1,10 +0,0 @@ -spq: | - values shape(this, <{a:time}>) - -vector: true - -input: | - {a:"a",b:"b"} - -output: | - {a:error({message:"cannot cast to time",on:"a"}),b:"b"} diff --git a/runtime/ztests/expr/shape-typedef.yaml b/runtime/ztests/expr/shape-typedef.yaml deleted file mode 100644 index d831ddbc50..0000000000 --- a/runtime/ztests/expr/shape-typedef.yaml +++ /dev/null @@ -1,10 +0,0 @@ -spq: name=='steve' | values shape(this,) - -vector: true - -input: | - {name:"jim",likes:"plain",age:30}::=person - {name:"steve",likes:"spicy",age:"52"} - -output: | - {name:"steve",likes:"spicy",age:52}::=person diff --git a/runtime/ztests/expr/shape.yaml b/runtime/ztests/expr/shape.yaml deleted file mode 100644 index a3be1205eb..0000000000 --- a/runtime/ztests/expr/shape.yaml +++ /dev/null @@ -1,12 +0,0 @@ -spq: | - type id={orig_h: ip, orig_p: port=uint16, vlan: uint16, resp_h:ip,resp_p:port} - type rec={id: id} - values shape(this, ) - -vector: true - -input: | - {id:{orig_h:"1.2.3.4",resp_h:"5.6.7.8",orig_p:1234::(port=uint16),resp_p:53::port,tag:0::uint16}} - -output: | - {id:{orig_h:1.2.3.4,orig_p:1234::(port=uint16),vlan:null::uint16,resp_h:5.6.7.8,resp_p:53::port,tag:0::uint16}}