-
-
Save huasanyelao/2dab0c2059249c5fe172 to your computer and use it in GitHub Desktop.
Example of how to save Spark RDDs to disk using GZip compression in response to https://twitter.com/rjurney/status/533061960128929793.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyspark import SparkContext | |
def main(): | |
sc = SparkContext(appName="Test Compression") | |
# RDD has to be key, value pairs | |
data = sc.parallelize([ | |
("key1", "value1"), | |
("key2", "value2"), | |
("key3", "value3"), | |
]) | |
data.saveAsHadoopFile("/tmp/spark_compressed", | |
"org.apache.hadoop.mapred.TextOutputFormat", | |
compressionCodecClass="org.apache.hadoop.io.compress.GzipCodec") | |
sc.stop() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment