X-Git-Url: https://code.communitydata.science/cdsc_reddit.git/blobdiff_plain/34185337c9c6f073ce8f8cb0e1b7ea605861b6e8..fc6575a28716f6d1611f988c48d15e64a22687ac:/comments_2_parquet.py diff --git a/comments_2_parquet.py b/comments_2_parquet.py index bd853f7..069434e 100755 --- a/comments_2_parquet.py +++ b/comments_2_parquet.py @@ -1,5 +1,5 @@ - #!/usr/bin/env python3 + import pyspark from pyspark.sql import functions as f from pyspark.sql.types import * @@ -128,6 +128,10 @@ df = df.withColumn("Month",f.month(f.col("CreatedAt"))) df = df.withColumn("Year",f.year(f.col("CreatedAt"))) df = df.withColumn("Day",f.dayofmonth(f.col("CreatedAt"))) df = df.withColumn("subreddit_hash",f.sha2(f.col("subreddit"), 256)[0:3]) + +# cache so we don't have to extract everythin twice +df = df.cache() + df2 = df.sort(["subreddit","author","link_id","parent_id","Year","Month","Day"],ascending=True) df2.write.parquet("/gscratch/comdata/output/reddit_comments_by_subreddit.parquet", partitionBy=["Year",'Month'],mode='overwrite')