PythonCallableAsArg.yqls 693 B

123456789101112131415161718192021222324252627282930
  1. (
  2. (let config (DataSource 'config))
  3. # common types
  4. (let ui64 (DataType 'Uint64))
  5. (let str (DataType 'String))
  6. # callable func
  7. (let funcType (CallableType '() '(str) '(str) '(ui64)))
  8. (let func (Udf 'SimpleUdf.Repeat))
  9. # python udf
  10. (let udfType (CallableType '() '(str) '(funcType) '(ui64)))
  11. (let udfScript (String '@@
  12. def new_string(func, x):
  13. return func(b'x', x) + b':' + func(b'y', x)
  14. @@))
  15. (let udf (ScriptUdf 'Python3 'new_string udfType udfScript))
  16. # call udf
  17. (let x (Uint64 '3))
  18. (let result (Apply udf func x))
  19. # output result with type
  20. (let res_sink (DataSink 'result))
  21. (let world (Write! world res_sink (Key) result '( '('type) )))
  22. # finish
  23. (return (Commit! world res_sink))
  24. )