Github user Stibbons commented on a diff in the pull request:
https://github.com/apache/spark/pull/14830#discussion_r101263182
--- Diff: examples/src/main/python/streaming/network_wordjoinsentiments.py
---
@@ -54,22 +54,25 @@ def print_happiest_words(rdd):
# Read in the word-sentiment list and create a static RDD from it
word_sentiments_file_path = "data/streaming/AFINN-111.txt"
- word_sentiments = ssc.sparkContext.textFile(word_sentiments_file_path)
\
- .map(lambda line: tuple(line.split("\t")))
+ word_sentiments = (ssc.sparkContext
+ .textFile(word_sentiments_file_path)
+ .map(lambda line: tuple(line.split("\t"))))
lines = ssc.socketTextStream(sys.argv[1], int(sys.argv[2]))
- word_counts = lines.flatMap(lambda line: line.split(" ")) \
- .map(lambda word: (word, 1)) \
- .reduceByKey(lambda a, b: a + b)
+ word_counts = (lines
+ .flatMap(lambda line: line.split(" "))
+ .map(lambda word: (word, 1))
+ .reduceByKey(lambda a, b: a + b))
# Determine the words with the highest sentiment values by joining the
streaming RDD
# with the static RDD inside the transform() method and then
multiplying
# the frequency of the words by its sentiment value
- happiest_words = word_counts.transform(lambda rdd:
word_sentiments.join(rdd)) \
- .map(lambda word_tuples: (word_tuples[0], float(word_tuples[1][0])
* word_tuples[1][1])) \
- .map(lambda word_happiness: (word_happiness[1],
word_happiness[0])) \
- .transform(lambda rdd: rdd.sortByKey(False))
+ happiest_words = (word_counts
+ .map(lambda word_tuples: (word_tuples[0],
+ float(word_tuples[1][0]) *
word_tuples[1][1]))
--- End diff --
I agree, if you prefer I can change all at once. But like I said, I don't
know any autoformat that does it automatically
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]