From bd130268e3c3e59a0230d24999c69cd1d5b21b15 Mon Sep 17 00:00:00 2001 From: Davies Liu Date: Fri, 26 Sep 2014 08:32:12 -0700 Subject: [PATCH] fix examples --- .../python/streaming/network_wordcount.py | 8 ++++---- .../src/main/python/streaming/wordcount.py | 8 ++++---- python/pyspark/streaming/__init__.py | 19 +++++++++++++++++++ python/pyspark/streaming/context.py | 2 ++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/examples/src/main/python/streaming/network_wordcount.py b/examples/src/main/python/streaming/network_wordcount.py index 8cc21fcf89adf..633e63172bad6 100644 --- a/examples/src/main/python/streaming/network_wordcount.py +++ b/examples/src/main/python/streaming/network_wordcount.py @@ -1,14 +1,14 @@ import sys -from pyspark.streaming.context import StreamingContext -from pyspark.streaming.duration import * +from pyspark import SparkContext +from pyspark.streaming import StreamingContext if __name__ == "__main__": if len(sys.argv) != 3: print >> sys.stderr, "Usage: wordcount " exit(-1) - ssc = StreamingContext(appName="PythonStreamingNetworkWordCount", - duration=Seconds(1)) + sc = SparkContext(appName="PythonStreamingNetworkWordCount") + ssc = StreamingContext(sc, 1) lines = ssc.socketTextStream(sys.argv[1], int(sys.argv[2])) counts = lines.flatMap(lambda line: line.split(" "))\ diff --git a/examples/src/main/python/streaming/wordcount.py b/examples/src/main/python/streaming/wordcount.py index 4c62835ed8025..c794711845af0 100644 --- a/examples/src/main/python/streaming/wordcount.py +++ b/examples/src/main/python/streaming/wordcount.py @@ -1,15 +1,15 @@ import sys -from pyspark.streaming.context import StreamingContext -from pyspark.streaming.duration import * +from pyspark import SparkContext +from pyspark.streaming import StreamingContext if __name__ == "__main__": if len(sys.argv) != 2: print >> sys.stderr, "Usage: wordcount " exit(-1) - ssc = StreamingContext(appName="PythonStreamingWordCount", - duration=Seconds(1)) + sc = SparkContext(appName="PythonStreamingWordCount") + ssc = StreamingContext(sc, 1) lines = ssc.textFileStream(sys.argv[1]) counts = lines.flatMap(lambda line: line.split(" "))\ diff --git a/python/pyspark/streaming/__init__.py b/python/pyspark/streaming/__init__.py index e69de29bb2d1d..00d2823525992 100644 --- a/python/pyspark/streaming/__init__.py +++ b/python/pyspark/streaming/__init__.py @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from pyspark.streaming.context import StreamingContext +from pyspark.streaming.dstream import DStream diff --git a/python/pyspark/streaming/context.py b/python/pyspark/streaming/context.py index fddef0d802670..1c7cb5604e5cc 100644 --- a/python/pyspark/streaming/context.py +++ b/python/pyspark/streaming/context.py @@ -22,6 +22,8 @@ from py4j.java_collections import ListConverter +__all__ = ["StreamingContext"] + class StreamingContext(object): """