@@ -46,6 +46,12 @@ def context(self):
46
46
"""
47
47
return self ._ssc
48
48
49
+ def context (self ):
50
+ """
51
+ Return the StreamingContext associated with this DStream
52
+ """
53
+ return self ._ssc
54
+
49
55
def count (self ):
50
56
"""
51
57
Return a new DStream which contains the number of elements in this DStream.
@@ -56,7 +62,7 @@ def _sum(self):
56
62
"""
57
63
Add up the elements in this DStream.
58
64
"""
59
- return self ._mapPartitions (lambda x : [sum (x )]).reduce (operator .add )
65
+ return self .mapPartitions (lambda x : [sum (x )]).reduce (operator .add )
60
66
61
67
def print_ (self , label = None ):
62
68
"""
@@ -75,7 +81,7 @@ def filter(self, f):
75
81
Return a new DStream containing only the elements that satisfy predicate.
76
82
"""
77
83
def func (iterator ): return ifilter (f , iterator )
78
- return self ._mapPartitions (func )
84
+ return self .mapPartitions (func )
79
85
80
86
def flatMap (self , f , preservesPartitioning = False ):
81
87
"""
@@ -86,7 +92,7 @@ def func(s, iterator):
86
92
return chain .from_iterable (imap (f , iterator ))
87
93
return self ._mapPartitionsWithIndex (func , preservesPartitioning )
88
94
89
- def map (self , f ):
95
+ def map (self , f , preservesPartitioning = False ):
90
96
"""
91
97
Return a new DStream by applying a function to each element of DStream.
92
98
"""
@@ -146,7 +152,7 @@ def combineLocally(iterator):
146
152
else :
147
153
combiners [k ] = mergeValue (combiners [k ], v )
148
154
return combiners .iteritems ()
149
- locally_combined = self ._mapPartitions (combineLocally )
155
+ locally_combined = self .mapPartitions (combineLocally )
150
156
shuffled = locally_combined .partitionBy (numPartitions )
151
157
152
158
def _mergeCombiners (iterator ):
@@ -474,4 +480,4 @@ def _jdstream(self):
474
480
return self ._jdstream_val
475
481
476
482
def _is_pipelinable (self ):
477
- return not ( self .is_cached )
483
+ return not self .is_cached
0 commit comments