forked from databricks/learning-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeParquetFile.py
More file actions
22 lines (21 loc) · 808 Bytes
/
Copy pathMakeParquetFile.py
File metadata and controls
22 lines (21 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Createas a parquet file and loads an input file into it
# For input you can use files/favourite_animal.csv as the iput
from pyspark import SparkContext
from pyspark.sql import SQLContext
import json
import sys
if __name__ == "__main__":
if len(sys.argv) != 4:
print "Error usage: LoadHive [sparkmaster] [inputFile] [parquetfile]"
sys.exit(-1)
master = sys.argv[1]
inputFile = sys.argv[2]
parquetFile = sys.argv[3]
sc = SparkContext(master, "MakeParquetFile")
sqlCtx = SQLContext(sc)
# Load some data into an RDD
rdd = sc.textFile(inputFile).map(lambda l: l.split(","))
namedRdd = rdd.map(lambda r: {"name": r[0], "favouriteAnimal": r[1]})
schemaNamedRdd = sqlCtx.inferSchema(namedRdd)
# Save it
schemaNamedRdd.saveAsParquetFile(parquetFile)