forked from polytech-nantes-puddi/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart4.py
30 lines (22 loc) · 815 Bytes
/
part4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pyspark.sql import SparkSession
from pyspark.sql import functions as f
import re
import time
pattern = re.compile("^[a-z]+$")
spark = SparkSession.builder.master('local[*]').appName('BigDataTP').getOrCreate()
sc = spark.sparkContext
sc.setLogLevel("WARN")
print ("Start")
start_time = time.time()
gdelt_parquet = spark.read.parquet('dataset/parquet')
print(gdelt_parquet.printSchema)
gdelt_parquet.createTempView('gdelt')
print(spark.sql("SELECT count(1) FROM gdelt").explain())
# Add your implementation
# 1. Filter the rows where Actor1CountryCode does not have a value
# 2. Group them by Actor1CountryCode
# 3. Sum them by NumMentions
# 4. Order by NumMentions and get the 10 more mentioned
# 5. Write the results to a CSV file
print ("End")
print("--- %s seconds ---" % (time.time() - start_time))