blob: 7a7a6a995a2f4895789804d71a45c65235ef121a (
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
34
35
36
37
38
39
|
(
(let config (DataSource 'config))
(let world (Configure! world config 'PureDataSource 'yt))
# prepare python udf
(let ui64 (DataType 'Uint64))
(let str (DataType 'String))
(let funcType (CallableType '() '(ui64) '(ui64)))
(let udfType (CallableType '() '(funcType) '(ui64)))
(let udfScript (String '@@
def create_counter(start):
def counter(step):
v = counter.x
counter.x += step
return v
counter.x = start
return counter
@@))
(let udf (ScriptUdf 'Python 'create_counter udfType udfScript))
# call udf
(let counter (Apply udf (Uint64 '1)))
(let result (AsList
(Apply counter (Uint64 '1))
(Apply counter (Uint64 '2))
(Apply counter (Uint64 '3))
(Apply counter (Uint64 '4))
))
# output result with type
(let res_sink (DataSink 'result))
(let world (Write! world res_sink (Key) result '( '('type) )))
# finish
(return (Commit! world res_sink))
)
|