PythonGeneratorWithClosure.yqls 574 B

12345678910111213141516171819202122232425
  1. (
  2. (let config (DataSource 'config))
  3. # prepare python udf
  4. (let i64 (DataType 'Int64))
  5. (let udfType (CallableType '() '((ListType i64)) '((ListType i64))))
  6. (let udfScript (String '@@
  7. def h(input):
  8. def gen():
  9. for x in input:
  10. yield int(x + 42)
  11. return gen
  12. @@))
  13. (let udf (ScriptUdf 'Python3 'h udfType udfScript))
  14. # call udf
  15. (let result (Apply udf (AsList (Int64 '1) (Int64 '2) (Int64 '3))))
  16. # output result with type
  17. (let sink (DataSink 'result))
  18. (let world (Write! world sink (Key) result '( '('type) )))
  19. # finish
  20. (return (Commit! world sink))
  21. )