Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runtime/sam/expr/function/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func NewCaster(sctx *super.Context) Caster {

func (c *cast) Call(args []super.Value) super.Value {
from, to := args[0], args[1]
from = from.SuperDeunion()
if from.IsError() {
return from
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/vam/expr/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type casterPrimitive struct {
}

func (c *casterPrimitive) Eval(this vector.Any) vector.Any {
return vector.Apply(vector.ApplyRipUnions, func(vecs ...vector.Any) vector.Any {
return vector.Apply(vector.ApplyRipFusions|vector.ApplyRipUnions, func(vecs ...vector.Any) vector.Any {
return cast.To(c.sctx, vecs[0], c.typ)
}, c.expr.Eval(this))
}
Expand All @@ -51,7 +51,7 @@ type casterNamedType struct {
}

func (c *casterNamedType) Eval(this vector.Any) vector.Any {
return vector.Apply(vector.ApplyNone, c.eval, c.expr.Eval(this))
return vector.Apply(vector.ApplyRipFusions|vector.ApplyRipUnions, c.eval, c.expr.Eval(this))
}

func (c *casterNamedType) eval(vecs ...vector.Any) vector.Any {
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/bool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ input: |
"true"
"F"
"false"
fusion("false"::(string|null),<string>)
"blah"
null
null::({}|null)
Expand All @@ -38,6 +39,7 @@ output: |
true
false
false
false
error({message:"cannot cast to bool",on:"blah"})
null::(bool|null)
null::(bool|null)
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/bytes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ input: |
type named=string
"bar"::named
""
fusion("a"::(string|null),<string>)
null
null::({}|null)
{x:"foo"}
Expand All @@ -17,6 +18,7 @@ output: |
0x666f6f
0x626172
0x
0x61
null::(bytes|null)
null::(bytes|null)
error({message:"cannot cast to bytes",on:{x:"foo"}})
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/duration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ input: |
-1.5e12
type named=int64
1::named
fusion(2::named::(named|null),<named>)
1e+19
null
null::({}|null)
Expand All @@ -25,6 +26,7 @@ output: |
error({message:"cannot cast to duration",on:""})
-25m
1ns
2ns
error({message:"cannot cast to duration",on:1e+19})
null::(duration|null)
null::(duration|null)
Expand Down
4 changes: 3 additions & 1 deletion runtime/ztests/expr/cast/enum.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
spq: this::enum(e1,e2)

input: |
"e2"
"e1"
fusion("e2"::(string|null),<string>)
"e3"
0
null
null::({}|null)
error("bad")

output: |
"e1"::enum(e1,e2)
"e2"::enum(e1,e2)
error({message:"no such symbol in enum(e1,e2)",on:"e3"})
error({message:"cannot cast to enum",on:0})
Expand Down
4 changes: 4 additions & 0 deletions runtime/ztests/expr/cast/float.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ input: |
2::named
false
true
fusion("2"::(string|null),<string>)
null
null::({}|null)

Expand Down Expand Up @@ -38,6 +39,9 @@ output: |
1.::float16
1.::float32
1.
2.::float16
2.::float32
2.
null::(float16|null)
null::(float32|null)
null::(float64|null)
Expand Down
5 changes: 5 additions & 0 deletions runtime/ztests/expr/cast/int.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ input: |
1e8
false
true
fusion("2"::(string|null),<string>)
null
null::({}|null)

Expand Down Expand Up @@ -52,6 +53,10 @@ output: |
1::int16
1::int32
1
2::int8
2::int16
2::int32
2
null::(int8|null)
null::(int16|null)
null::(int32|null)
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/ip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ input: |
"foo"
"127.0.0.1"
"2001:0000:130F:0000:0000:09C0:876A:130B"
fusion("3000::"::(string|null),<string>)
null
null::({}|null)
1.1.1.1
Expand All @@ -18,6 +19,7 @@ output: |
error({message:"cannot cast to ip",on:"foo"})
127.0.0.1
2001:0:130f::9c0:876a:130b
3000::
null::(ip|null)
null::(ip|null)
1.1.1.1
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spq: |

input: |
map{}
fusion(map{1:map{2:3}}::(null|map{int64:map{int64:int64}}),<map{int64:map{int64:int64}}>)
map{1:map{"2":3,4:"5"},"7":8,"9":map{10:[],[]:11,null:null}}
null
null::({}|null)
Expand All @@ -12,6 +13,7 @@ input: |

output: |
map{}
map{1:map{"2":3}}
map{1:map{"2":3,"4":5},7:error({message:"cannot cast to map{string:int64}",on:8}),9:map{null:null,"10":error({message:"cannot cast to int64",on:[]}),"[]":11}}
null::(null|map{int64:map{string:int64}})
null::(null|map{int64:map{string:int64}})
Expand Down
3 changes: 3 additions & 0 deletions runtime/ztests/expr/cast/named.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ spq: |
input: |
{x:1}
{x:2}
fusion({x:3}::(null|{x:int64}),<{x:int64}>)
"foo"
"bar"
type a=string
Expand All @@ -18,6 +19,7 @@ output: |
type named={x:int64}
{x:1}::named
{x:2}::named
{x:3}::named
error("type \"named\" redefined")
error("type \"named\" redefined")
error("type \"named\" redefined")
Expand All @@ -41,3 +43,4 @@ output: |
type foo=int64
{str:1::foo,named:1::foo}
{str:2::foo,named:2::foo}

2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spq: this::net
input: |
"192.168.1.0/24"
"2001:db8::/32"
fusion("2001:db8::/33"::(string|null),<string>)
null
null::({}|null)
10.0.0.0/8
Expand All @@ -16,6 +17,7 @@ input: |
output: |
192.168.1.0/24
2001:db8::/32
2001:db8::/33
null::(net|null)
null::(net|null)
10.0.0.0/8
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/record.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ input: |
{b:1,c:2}
{a:"1",b:2,c:{cc:3},d:[{e:4,f:"5"},{f:6,e:"7"},8]}
{d:[{e:1,f:"2"},{f:3,e:"4"},5],c:null,b:6,a:"7"}
fusion({a:1,b:2,c:{},d:[]}::(null|{a:int64,b:int64,c:{},d:[none]}),<{a:int64,b:int64,c:{},d:[none]}>)
null
null::({}|null)
1
Expand All @@ -19,6 +20,7 @@ output: |
{a:error("missing"),b:"1",c:error({message:"cannot cast to {}",on:2}),d:error("missing")}
{a:1,b:"2",c:{},d:[{e:"4",f:5},{e:"7",f:6},error({message:"cannot cast to {e:string,f:int64}",on:8})]}
{a:7,b:"6",c:null::(null|{}),d:[{e:"1",f:2},{e:"4",f:3},error({message:"cannot cast to {e:string,f:int64}",on:5})]}
{a:1,b:"2",c:{},d:[]::[{e:string,f:int64}]}
null::(null|{a:int64,b:string,c:{},d:[{e:string,f:int64}]})
null::(null|{a:int64,b:string,c:{},d:[{e:string,f:int64}]})
error({message:"cannot cast to {a:int64,b:string,c:{},d:[{e:string,f:int64}]}",on:1})
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/string.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ input: |
{foo:"bar"}
[1,2,3]
"e2"::enum(e1,e2)
fusion(1::(int64|null),<int64>)
error("bad")

output: |
Expand Down Expand Up @@ -61,4 +62,5 @@ output: |
"{foo:\"bar\"}"
"[1,2,3]"
"e2"
"1"
error("bad")
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/time.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ input: |
"foo"
-1e9
1
fusion(1::(int64|null),<int64>)
null
null::({}|null)
1e200
Expand All @@ -31,6 +32,7 @@ output: |
error({message:"cannot cast to time",on:"foo"})
1969-12-31T23:59:59Z
1970-01-01T00:00:00.000000001Z
1970-01-01T00:00:00.000000001Z
null::(time|null)
null::(time|null)
error({message:"cannot cast to time",on:1e+200})
Expand Down
4 changes: 4 additions & 0 deletions runtime/ztests/expr/cast/type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ input: |
"<int64>"
<ip>
"<{x:string}>"
fusion("<{x:string}>"::(string|null),<string>)
"{x:\"foo\"}"
"<int>"
1
"e2"::enum(e1,e2)
null
null::({}|null)
error("bad")
fusion(error(1)::(error(int64)|int64),<error(int64)>)

output: |
<int64>
<ip>
<{x:string}>
<{x:string}>
error({message:"cannot cast to type",on:"{x:\"foo\"}"})
error({message:"cannot cast to type",on:"<int>"})
error({message:"cannot cast to type",on:1})
error({message:"cannot cast to type",on:"e2"::enum(e1,e2)})
null::(type|null)
null::(type|null)
error("bad")
error(1)
5 changes: 5 additions & 0 deletions runtime/ztests/expr/cast/uint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ spq: |
input: |
false
true
fusion(true::(bool|null),<bool>)
-1
null
null::({}|null)
Expand All @@ -18,6 +19,10 @@ output: |
1::uint16
1::uint32
1::uint64
1::uint8
1::uint16
1::uint32
1::uint64
error({message:"cannot cast to uint8",on:-1})
error({message:"cannot cast to uint16",on:-1})
error({message:"cannot cast to uint32",on:-1})
Expand Down
Loading