StrictCastOverStruct.yqls 882 B

12345678910111213141516171819202122
  1. (
  2. (let config (DataSource 'config))
  3. (let res_sink (DataSink 'result))
  4. # Struct<Int32, String, Utf8?> -> Struct<Uint8?, Utf8?> (good)
  5. (let targetType (StructType '('a (OptionalType (DataType 'Uint8))) '('b (OptionalType (DataType 'Utf8)))))
  6. (let value (AsStruct '('a (Int32 '1)) '('b (String 'one)) '('c (Nothing (OptionalType (DataType 'Utf8))))))
  7. (let cast (StrictCast value targetType))
  8. (let world (Write! world res_sink (Key) cast '('('type))))
  9. # Struct<Int32, String, String?> -> Struct<Int8, Utf8, Float?>? (fail)
  10. (let targetType (StructType '('a (DataType 'Int8)) '('b (DataType 'Utf8)) '('c (OptionalType (DataType 'Float)))))
  11. (let value (AsStruct '('a (Int32 '-1)) '('b (String 'one)) '('d (Just (String 'one)))))
  12. (let cast (StrictCast value targetType))
  13. (let world (Write! world res_sink (Key) cast '('('type))))
  14. (let world (Commit! world res_sink))
  15. (return world)
  16. )