PythonGeneratorExprWithClosure.yqls 564 B

123456789101112131415161718192021222324
  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 g(input):
  8. def gen():
  9. return (int(x + 42) for x in input)
  10. return gen
  11. @@))
  12. (let udf (ScriptUdf 'Python3 'g udfType udfScript))
  13. # call udf
  14. (let result (Apply udf (AsList (Int64 '1) (Int64 '2) (Int64 '3))))
  15. # output result with type
  16. (let sink (DataSink 'result))
  17. (let world (Write! world sink (Key) result '( '('type) )))
  18. # finish
  19. (return (Commit! world sink))
  20. )