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
5 changes: 4 additions & 1 deletion runtime/vam/expr/cast/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ type numeric interface {
}

func castToNumber(vec vector.Any, typ super.Type, index []uint32) (vector.Any, []uint32, string, bool) {
if vec.Type().ID() == super.IDString {
switch id := vec.Type().ID(); {
case id == super.IDString:
out, errs := castStringToNumber(vec, typ, index)
return out, errs, "", true
case !super.IsNumber(id) && id != super.IDBool:
return nil, nil, "", false
}
switch id := typ.ID(); {
case super.IsSigned(id):
Expand Down
8 changes: 8 additions & 0 deletions runtime/ztests/expr/cast/bool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ input: |
null
"1"
error("bad")
{x:1}
[1,2]
|[1,2]|
|{"x":1}|

output: |
true
Expand All @@ -37,3 +41,7 @@ output: |
error({message:"cannot cast to bool",on:null})
true
error("bad")
error({message:"cannot cast to bool",on:{x:1}})
error({message:"cannot cast to bool",on:[1,2]})
error({message:"cannot cast to bool",on:|[1,2]|})
error({message:"cannot cast to bool",on:|{"x":1}|})
8 changes: 8 additions & 0 deletions runtime/ztests/expr/cast/duration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ input: |
1e+19
null
error("bad")
{x:1}
[1,2]
|[1,2]|
|{"x":1}|

output: |
10d
Expand All @@ -23,3 +27,7 @@ output: |
error({message:"cannot cast to duration",on:1e+19})
error({message:"cannot cast to duration",on:null})
error("bad")
error({message:"cannot cast to duration",on:{x:1}})
error({message:"cannot cast to duration",on:[1,2]})
error({message:"cannot cast to duration",on:|[1,2]|})
error({message:"cannot cast to duration",on:|{"x":1}|})
26 changes: 20 additions & 6 deletions runtime/ztests/expr/cast/float.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ input: |
2::=named
false
true
null
error("bad")

output: |
1.5::float16
Expand All @@ -39,9 +37,25 @@ output: |
1.::float16
1.::float32
1.
error({message:"cannot cast to float16",on:null})
error({message:"cannot cast to float32",on:null})
error({message:"cannot cast to float64",on:null})
error("bad")

---

spq: cast(this, <float64>)

vector: true

input: |
null
error("bad")
{x:1}
[1,2]
|[1,2]|
|{"x":1}|

output: |
error({message:"cannot cast to float64",on:null})
error("bad")
error({message:"cannot cast to float64",on:{x:1}})
error({message:"cannot cast to float64",on:[1,2]})
error({message:"cannot cast to float64",on:|[1,2]|})
error({message:"cannot cast to float64",on:|{"x":1}|})
23 changes: 20 additions & 3 deletions runtime/ztests/expr/cast/int.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ input: |
1e8
false
true
error("bad")

output: |
-1::int8
Expand Down Expand Up @@ -57,7 +56,25 @@ output: |
1::int16
1::int32
1

---

spq: cast(this, <int64>)

vector: true

input: |
null
error("bad")
{x:1}
[1,2]
|[1,2]|
|{"x":1}|

output: |
error({message:"cannot cast to int64",on:null})
error("bad")
error("bad")
error("bad")
error({message:"cannot cast to int64",on:{x:1}})
error({message:"cannot cast to int64",on:[1,2]})
error({message:"cannot cast to int64",on:|[1,2]|})
error({message:"cannot cast to int64",on:|{"x":1}|})
8 changes: 8 additions & 0 deletions runtime/ztests/expr/cast/time.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ input: |
null
1e200
error("bad")
{x:1}
[1,2]
|[1,2]|
|{"x":1}|

output: |
2023-10-19T23:11:20.999803Z
Expand All @@ -29,3 +33,7 @@ output: |
error({message:"cannot cast to time",on:null})
error({message:"cannot cast to time",on:1e+200})
error("bad")
error({message:"cannot cast to time",on:{x:1}})
error({message:"cannot cast to time",on:[1,2]})
error({message:"cannot cast to time",on:|[1,2]|})
error({message:"cannot cast to time",on:|{"x":1}|})
22 changes: 22 additions & 0 deletions runtime/ztests/expr/cast/uint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ output: |
error("bad")
error("bad")
error("bad")

---

spq: cast(this, <uint64>)

vector: true

input: |
null
error("bad")
{x:1}
[1,2]
|[1,2]|
|{"x":1}|

output: |
error({message:"cannot cast to uint64",on:null})
error("bad")
error({message:"cannot cast to uint64",on:{x:1}})
error({message:"cannot cast to uint64",on:[1,2]})
error({message:"cannot cast to uint64",on:|[1,2]|})
error({message:"cannot cast to uint64",on:|{"x":1}|})