-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathproblem78
More file actions
60 lines (47 loc) · 1.6 KB
/
problem78
File metadata and controls
60 lines (47 loc) · 1.6 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
1. Copy "retail_db.order_items" table to hdfs in respective directory p90_order_items .
[cloudera@quickstart ~]$ sqoop import --connect jdbc:mysql://quickstart:3306/retail_db --username=retail_dba --password=cloudera --table=order_items --target-dir=p90_orderItems -m 1
17/10/27 22:00:49 INFO mapreduce.ImportJobBase: Transferred 5.1583 MB in 19.5046 seconds (270.8132 KB/sec)
17/10/27 22:00:49 INFO mapreduce.ImportJobBase: Retrieved 172198 records.
2. Do the summation of entire revenue in this table using pyspark.
>>> tableRDD = sc.textFile("p90_orderItems")
>>> revenue = tableRDD.map(lambda line: float(line.split(",")[4]))
>>> for rev in revenue.collect():
>>> print rev
1999.99
129.99
179.97
299.98
129.99
129.99
129.99
999.99
149.94
250.0
199.99
249.9
149.94
129.99
59.99
50.0
1999.99
150.0
>>> total = revenue.reduce(lambda a,b: a + b)
>>> total
34322619.930029497
>>> max = revenue.reduce(lambda a,b: a if a >= b else b)
>>> max
1999.99
>>> min = revenue.reduce(lambda a,b: a if a <= b else b)
>>> min
9.9900000000000002
3. Find the maximum and minimum revenue as well.
>>> max = revenue.reduce(lambda a,b: a if a >= b else b)
>>> max
1999.99
>>> min = revenue.reduce(lambda a,b: a if a <= b else b)
>>> min
9.9900000000000002
4. Calculate average revenue
>>> avg = total / (revenue.count())
>>> avg
199.32066533890927