Join the discussion
Question 33/34
CORRECT TEXT
Problem Scenario 36 : You have been given a file named spark8/data.csv (type,name).
data.csv
1 ,Lokesh
2 ,Bhupesh
2 ,Amit
2 ,Ratan
2 ,Dinesh
1 ,Pavan
1 ,Tejas
2 ,Sheela
1 ,Kumar
1 ,Venkat
1. Load this file from hdfs and save it back as (id, (all names of same type)) in results directory. However, make sure while saving it should be
Problem Scenario 36 : You have been given a file named spark8/data.csv (type,name).
data.csv
1 ,Lokesh
2 ,Bhupesh
2 ,Amit
2 ,Ratan
2 ,Dinesh
1 ,Pavan
1 ,Tejas
2 ,Sheela
1 ,Kumar
1 ,Venkat
1. Load this file from hdfs and save it back as (id, (all names of same type)) in results directory. However, make sure while saving it should be
Correct Answer:
See the explanation for Step by Step Solution and configuration.
Explanation:
Solution :
Step 1 : Create file in hdfs (We will do using Hue). However, you can first create in local filesystem and then upload it to hdfs.
Step 2 : Load data.csv file from hdfs and create PairRDDs
val name = sc.textFile("spark8/data.csv")
val namePairRDD = name.map(x=> (x.split(",")(0),x.split(",")(1)))
Step 3 : Now swap namePairRDD RDD.
val swapped = namePairRDD.map(item => item.swap)
Step 4 : Now combine the rdd by key.
val combinedOutput = namePairRDD.combineByKey(List(_), (x:List[String], y:String) => y ::
x, (x:List[String], y:List[String]) => x ::: y)
Step 5 : Save the output as a Text file and output must be written in a single file.
:ombinedOutput.repartition(1).saveAsTextFile("spark8/result.txt")
Explanation:
Solution :
Step 1 : Create file in hdfs (We will do using Hue). However, you can first create in local filesystem and then upload it to hdfs.
Step 2 : Load data.csv file from hdfs and create PairRDDs
val name = sc.textFile("spark8/data.csv")
val namePairRDD = name.map(x=> (x.split(",")(0),x.split(",")(1)))
Step 3 : Now swap namePairRDD RDD.
val swapped = namePairRDD.map(item => item.swap)
Step 4 : Now combine the rdd by key.
val combinedOutput = namePairRDD.combineByKey(List(_), (x:List[String], y:String) => y ::
x, (x:List[String], y:List[String]) => x ::: y)
Step 5 : Save the output as a Text file and output must be written in a single file.
:ombinedOutput.repartition(1).saveAsTextFile("spark8/result.txt")
Add Comments
- Other Question (34q)
- Q1. CORRECT TEXT Problem Scenario 29 : Please accomplish the following exercises using HDFS co...
- Q2. CORRECT TEXT Problem Scenario 59 : You have been given below code snippet. val x = sc.para...
- Q3. CORRECT TEXT Problem Scenario 25 : You have been given below comma separated employee info...
- Q4. CORRECT TEXT Problem Scenario 50 : You have been given below code snippet (calculating an ...
- Q5. CORRECT TEXT Problem Scenario 95 : You have to run your Spark application on yarn with eac...
- Q6. CORRECT TEXT Problem Scenario 48 : You have been given below Python code snippet, with int...
- Q7. CORRECT TEXT Problem Scenario 37 : ABCTECH.com has done survey on their Exam Products feed...
- Q8. CORRECT TEXT Problem Scenario 40 : You have been given sample data as below in a file call...
- Q9. CORRECT TEXT Problem Scenario 9 : You have been given following mysql database details as ...
- Q10. CORRECT TEXT Problem Scenario 34 : You have given a file named spark6/user.csv. Data is gi...
- Q11. CORRECT TEXT Problem Scenario 41 : You have been given below code snippet. val aul = sc.pa...
- Q12. CORRECT TEXT Problem Scenario 53 : You have been given below code snippet. val a = sc.para...
- Q13. CORRECT TEXT Problem Scenario 51 : You have been given below code snippet. val a = sc.para...
- Q14. CORRECT TEXT Problem Scenario 2 : There is a parent organization called "ABC Group Inc", w...
- Q15. CORRECT TEXT Problem Scenario 19 : You have been given following mysql database details as...
- Q16. CORRECT TEXT Problem Scenario 56 : You have been given below code snippet. val a = sc.para...
- Q17. CORRECT TEXT Problem Scenario 93 : You have to run your Spark application with locally 8 t...
- Q18. CORRECT TEXT Problem Scenario 32 : You have given three files as below. spark3/sparkdir1/f...
- Q19. CORRECT TEXT Problem Scenario 18 : You have been given following mysql database details as...
- Q20. CORRECT TEXT Problem Scenario 22 : You have been given below comma separated employee info...
- Q21. CORRECT TEXT Problem Scenario 80 : You have been given MySQL DB with following details. us...
- Q22. CORRECT TEXT Problem Scenario 78 : You have been given MySQL DB with following details. us...
- Q23. CORRECT TEXT Problem Scenario 4: You have been given MySQL DB with following details. user...
- Q24. CORRECT TEXT Problem Scenario 20 : You have been given MySQL DB with following details. us...
- Q25. CORRECT TEXT Problem Scenario 68 : You have given a file as below. spark75/f ile1.txt File...
- Q26. CORRECT TEXT Problem Scenario 90 : You have been given below two files course.txt id,cours...
- Q27. CORRECT TEXT Problem Scenario 27 : You need to implement near real time solutions for coll...
- Q28. CORRECT TEXT Problem Scenario 81 : You have been given MySQL DB with following details. Yo...
- Q29. CORRECT TEXT Problem Scenario 74 : You have been given MySQL DB with following details. us...
- Q30. CORRECT TEXT Problem Scenario 10 : You have been given following mysql database details as...
- Q31. CORRECT TEXT Problem Scenario 79 : You have been given MySQL DB with following details. us...
- Q32. CORRECT TEXT Problem Scenario 45 : You have been given 2 files , with the content as given...
- Q33. CORRECT TEXT Problem Scenario 36 : You have been given a file named spark8/data.csv (type,...
- Q34. CORRECT TEXT Problem Scenario 5 : You have been given following mysql database details. us...
