Question : You have following data in a hive table ID:INT,COLOR:TEXT,WIDTH:INT 1,green,190 2,blue,300 3,yellow,299 4,blue,199 5,green,199 6,yellow,299 7,green,799
Select the correct MapReduce program which can produce the output similar to below Hive Query(Assuming single reducer). Select distinct color,width from table; 1. 1 2. 2 3. Access Mostly Uused Products by 50000+ Subscribers 4. 4
Correct Answer : Get Lastest Questions and Answer : Explanation: In 4th option Mappper emits the values like.. green green,190 blue blue,300 yellow yellow,299 ..... -- In the reducer part, it stores all the combination of color and width in the allColorWidth ArrayList, Hence , allColorWidth will have following values in it. blue,199 blue,300 green,190 green,199 green,799 .... -- After sorting this ArrayList , it will produce the output as below, for each reduce call blue,199 blue,300 green,190 ..... --And now iterate over the each elements in the ArrayList to produce the desired output, by comparing width for each color. blue,199 blue,300 green,190 green,199 green,799
Question : You have following data in a hive table
Explanation: In option 1, Mapper produces the output as A green,190 A blue,300 A yellow,299 A blue,199 ... As all the keys are same , hence single reducer will be called as below. in the reducer method, it creates a new ArrayList which stores all the combination of color and width as below. green,190 blue,300 yellow,299 ... After calling Collections.sort(allColorWidth), ArrayList will have values stored as belwo. blue,199 blue,300 green,190 ... So reducer will emit these as keys, which produces the desired output.s
Explanation: Mapper produces the following output A 190,green A 300,blue A 299,yellow A 199,blue A 199,green A 299,yellow A 799,green -- As all the keys are same, hence single reducer will be called. In the reducer we add combination of width and color in the ArrayList and first sort and then reverse the ArrayList which produce the following results. 799,green 300,blue 299,yellow 299,yellow 199,green .... -- And iterating over this ArrayList, it will produce the desired output as below. green,799 blue,300 yellow,299 yellow,299 green,199 blue,199 green,190