Skip to content
Newer
Older
100644 45 lines (33 sloc) 1.28 KB
f58458d @ebernhardson allow functions to be passed as arguments to a DecoratedFunction
ebernhardson authored Dec 28, 2011
1 #
2 # Copyright 2011 Twitter, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15
16 """
76085e6 Cleaned up feature to pass in Python callback functions to UDFs
Gabor Szabo authored Jan 12, 2012
17 Contrived example showing that you can pass functions as args to a UDF.
18 Also shows how to use keyword args (just the way it's expected).
058383c Removed some spaces
Gabor Szabo authored Mar 8, 2012
19
20 Thanks to ebernhardson.
f58458d @ebernhardson allow functions to be passed as arguments to a DecoratedFunction
ebernhardson authored Dec 29, 2011
21 """
22
23 from pycascading.helpers import *
24
76085e6 Cleaned up feature to pass in Python callback functions to UDFs
Gabor Szabo authored Jan 12, 2012
25
f58458d @ebernhardson allow functions to be passed as arguments to a DecoratedFunction
ebernhardson authored Dec 29, 2011
26 def word_count_callback(value):
27 return len(value.split())
28
76085e6 Cleaned up feature to pass in Python callback functions to UDFs
Gabor Szabo authored Jan 12, 2012
29
898ad13 Examples rewritten using the new operators and decorators
Gabor Szabo authored Apr 29, 2012
30 @udf_map
76085e6 Cleaned up feature to pass in Python callback functions to UDFs
Gabor Szabo authored Jan 12, 2012
31 def word_count(tuple, inc, second_inc, callback=None):
32 return [inc + second_inc + callback(tuple.get(1)), tuple.get(1)]
f58458d @ebernhardson allow functions to be passed as arguments to a DecoratedFunction
ebernhardson authored Dec 29, 2011
33
34
35 def main():
36 flow = Flow()
37 input = flow.source(Hfs(TextLine(), 'pycascading_data/town.txt'))
38 output = flow.tsv_sink('pycascading_data/out')
058383c Removed some spaces
Gabor Szabo authored Mar 9, 2012
39
898ad13 Examples rewritten using the new operators and decorators
Gabor Szabo authored Apr 30, 2012
40 p = input | map_replace(
41 word_count(100, second_inc=200, callback=word_count_callback),
42 ['word_count', 'line']) | output
058383c Removed some spaces
Gabor Szabo authored Mar 9, 2012
43
3a9de62 Updated examples cache and callback
Gabor Szabo authored Apr 8, 2012
44 flow.run(num_reducers=1)
Something went wrong with that request. Please try again.