Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
spark:recipes:writing-text-files [2014/11/04 14:36] straka created |
spark:recipes:writing-text-files [2014/11/04 14:59] (current) straka |
||
|---|---|---|---|
| Line 3: | Line 3: | ||
| Text files can be written easily by Spark. | Text files can be written easily by Spark. | ||
| - | ===== Reading | + | ===== Writing |
| To write an '' | To write an '' | ||
| Line 11: | Line 11: | ||
| The '' | The '' | ||
| - | Several output files, named '' | + | Several output files, named '' |
| ==== Sorting Output ==== | ==== Sorting Output ==== | ||
| Line 30: | Line 30: | ||
| ==== One Output File ==== | ==== One Output File ==== | ||
| + | |||
| + | In many cases, only one output file is desirable. In that case, '' | ||
| + | <file python> | ||
| + | lines.coalesce(1).saveAsTextFile(" | ||
| + | </ | ||
| + | |||
| + | In case sorting is also used, use '' | ||
| + | |||
| + | ===== Writing Text Files by Paragraphs | ||
| + | |||
| + | The '' | ||
| + | <file python> | ||
| + | lines.map(lambda line: str(line) + " | ||
| + | </ | ||
| + | <file scala> | ||
| + | lines.map(_.toString + " | ||
| + | </ | ||
