blob: 38a484a4c3ca371e79cf327be9dd56aff6852bb8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
(
(let config (DataSource 'config))
(let world (Configure! world config 'PureDataSource 'yt))
# prepare python udf
(let ui32 (DataType 'Uint32))
(let str (DataType 'String))
(let personType (StructType '('name str) '('age ui32)))
(let udfType (CallableType '() '(personType) '(str) '(ui32)))
(let udfScript (String '@@
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def NewPerson(name, age):
return Person(name, age)
@@))
(let udf (ScriptUdf 'Python 'NewPerson udfType udfScript))
# call udf
(let result (Apply udf (String 'Jamel) (Uint32 '99)))
# output result with type
(let res_sink (DataSink 'result))
(let world (Write! world res_sink (Key) result '()))
# finish
(let world (Commit! world res_sink))
(return world)
)
|