As I said in my comment above, the documentation with examples can be found here. And quoting the description of the method saveAsTextFile
:
Save this RDD as a text file, using string representations of elements.
In the following example I save a simple RDD into a file, then I load it and print its content.
samples = sc.parallelize([
("[email protected]", "Alberto", "Bonsanto"),
("[email protected]", "Miguel", "Bonsanto"),
("[email protected]", "Stranger", "Weirdo"),
("[email protected]", "Dakota", "Bonsanto")
])
print samples.collect()
samples.saveAsTextFile("folder/here.txt")
read_rdd = sc.textFile("folder/here.txt")
read_rdd.collect()
The output will be
('[email protected]', 'Alberto', 'Bonsanto')
('[email protected]', 'Miguel', 'Bonsanto')
('[email protected]', 'Stranger', 'Weirdo')
('[email protected]', 'Dakota', 'Bonsanto')
[u"('[email protected]', 'Alberto', 'Bonsanto')",
u"('[email protected]', 'Miguel', 'Bonsanto')",
u"('[email protected]', 'Stranger', 'Weirdo')",
u"('[email protected]', 'Dakota', 'Bonsanto')"]
Let's take a look using a Unix-based terminal.
usr@host:~/folder/here.txt$ cat *
('[email protected]', 'Alberto', 'Bonsanto')
('[email protected]', 'Miguel', 'Bonsanto')
('[email protected]', 'Stranger', 'Weirdo')
('[email protected]', 'Dakota', 'Bonsanto')