Skip to content

Commit

Permalink
Handle single-precision float values in the standard coders tests pro…
Browse files Browse the repository at this point in the history
…perly (#22716)
  • Loading branch information
jrmccluskey authored Aug 16, 2022
1 parent 67cb87e commit 91c4b87
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sdks/go/test/regression/coders/fromyaml/fromyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ var unimplementedCoders = map[string]bool{
var filteredCases = []struct{ filter, reason string }{
{"logical", "BEAM-9615: Support logical types"},
{"30ea5a25-dcd8-4cdb-abeb-5332d15ab4b9", "https://github.com/apache/beam/issues/21206: Support encoding position."},
{"8c97b6c5-69e5-4733-907b-26cd8edae612", "https://github.com/apache/beam/issues/22629: Support single-precision float."},
}

// Coder is a representation a serialized beam coder.
Expand Down Expand Up @@ -339,6 +338,7 @@ var nameToType = map[string]reflect.Type{
"f_bool": reflectx.Bool,
"f_bytes": reflect.PtrTo(reflectx.ByteSlice),
"f_map": reflect.MapOf(reflectx.String, reflect.PtrTo(reflectx.Int64)),
"f_float": reflectx.Float32,
}

func setField(rv reflect.Value, i int, v interface{}) {
Expand All @@ -356,6 +356,12 @@ func setField(rv reflect.Value, i int, v interface{}) {
rf.SetString(v.(string))
case reflect.Int32:
rf.SetInt(int64(v.(int)))
case reflect.Float32:
c, err := strconv.ParseFloat(v.(string), 32)
if err != nil {
panic(err)
}
rf.SetFloat(c)
case reflect.Float64:
c, err := strconv.ParseFloat(v.(string), 64)
if err != nil {
Expand Down

0 comments on commit 91c4b87

Please sign in to comment.