microsoft / yardl

Tooling for streaming instrument data
https://microsoft.github.io/yardl/
MIT License
29 stars 5 forks source link

Unable to create switch expression of type string #113

Closed naegelejd closed 7 months ago

naegelejd commented 7 months ago

Using yardl v0.4.0, I expect to be able to use a computed field switch expression to produce a string value:

RecordWithComputedFields: !record
  fields:
    myField: [null, string, float]
  computedFields:
    myResult:
      !switch myField:
        null: "null"
        string: "string"
        float: "float"

But yardl complains with:

❌ /workspaces/yardl/joe/switch-case-string/model/model.yml:6:14: there is no variable in scope with the name 'null' nor does the record 'RecordWithComputedFields' does not have a field or computed field named 'null'
❌ /workspaces/yardl/joe/switch-case-string/model/model.yml:7:18: there is no variable in scope with the name 'string' nor does the record 'RecordWithComputedFields' does not have a field or computed field named 'string'
❌ /workspaces/yardl/joe/switch-case-string/model/model.yml:8:17: there is no variable in scope with the name 'float' nor does the record 'RecordWithComputedFields' does not have a field or computed field named 'float'
johnstairs commented 7 months ago

This is not great, but it has to do with fact that the YAML parser interprets "null" and "string" the same as null and string since they are in YAML nodes. The workaround is to write "'null'" and "'string'" like we do in the nullableIntFloatUnionString computed field in unittests.yml.

naegelejd commented 7 months ago

Got it! I missed that existing example. Happy to close this one and refer to it in the future if necessary.