Skip to content

Scala to Python - pairRdd folder #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added pairRdd/create/*.py
  • Loading branch information
Pedro Bernardo committed Oct 2, 2017
commit c6a3a82cdc24f6908cc6de7cad2cb8600216a085
12 changes: 12 additions & 0 deletions pairRdd/create/PairRddFromRegularRdd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pyspark import SparkContext

if __name__ == "__main__":

sc = SparkContext("local", "create")
sc.setLogLevel("ERROR")

inputStrings = ["Lily 23", "Jack 29", "Mary 29", "James 8"]
regularRDDs = sc.parallelize(inputStrings)

pairRDD = regularRDDs.map(lambda s: (s.split(" ")[0], s.split(" ")[1]))
pairRDD.coalesce(1).saveAsTextFile("out/pair_rdd_from_regular_rdd")
11 changes: 11 additions & 0 deletions pairRdd/create/PairRddFromTupleList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pyspark import SparkContext

if __name__ == "__main__":

sc = SparkContext("local", "create")
sc.setLogLevel("ERROR")

tuples = [("Lily", 23), ("Jack", 29), ("Mary", 29), ("James", 8)]
pairRDD = sc.parallelize(tuples)

pairRDD.coalesce(1).saveAsTextFile("out/pair_rdd_from_tuple_list")