Difference between revisions of "MapReduce Mapper Assignment"

From CSE231 Wiki
Jump to navigation Jump to search
Line 98: Line 98:
  
 
=Testing Your Solution=
 
=Testing Your Solution=
==Correctness: IntSumStudioTestSuite==
+
==Correctness: _IntSumExerciseTestSuite==
{{TestSuite|IntSumStudioTestSuite|mapreduce.intsum.studio}}
+
{{TestSuite|_IntSumExerciseTestSuite|mapreduce}}
 
===CardMapperTestSuite===
 
===CardMapperTestSuite===
{{TestSuite|CardMapperTestSuite|mapreduce.apps.cards.studio}}
+
{{TestSuite|_CardMapperTestSuite|mapreduce.apps.cards.exercise}}
 
===KMerMapperTestSuite===
 
===KMerMapperTestSuite===
{{TestSuite|KMerMapperTestSuite|mapreduce.apps.kmer.studio}}
+
{{TestSuite|_KMerMapperTestSuite|mapreduce.apps.kmer.exercise}}
 
===WordCountStudioTestSuite===
 
===WordCountStudioTestSuite===
{{TestSuite|WordCountStudioTestSuite|mapreduce.apps.wordcount.studio}}
+
{{TestSuite|_WordCountStudioTestSuite|mapreduce.apps.wordcount.exercise}}
 
===IntSumClassicReducerStudioTestSuite===
 
===IntSumClassicReducerStudioTestSuite===
{{TestSuite|IntSumClassicReducerStudioTestSuite|mapreduce.apps.intsum.studio}}
+
{{TestSuite|_IntSumReduceOnlyTestSuite|mapreduce.apps.reducer.listaccumulating.intsum.exercise}}

Revision as of 16:36, 22 February 2022

Motivation

In previous semesters the MapReduce lab has proven to be the most challenging. We have split things up to allow you to get familiar with the how Mappers and Reducers work first. We will build a card mapper that matches the spec outlined in the prep video, a simple word counting mapper, an analogous k-mer counting mapper, and an integer sum reducer to wrap things up.

The k-mer counting mapper will prepare us for (and hopefully lessen the burden of) upcoming lab 6.

Code To Use

BiConsumer

accept(t,u) (note: closest relative to "emit" from RiceX prep)

Collector

finisher() (note: closest relative to "reduce" from RiceX prep)

Deck (note: Iterable<Card>)

Card

getRank()
getSuit()

Rank

isNumeric()
getNumericValue()

Suit

TextSection

getWords()

Code To Implement

Card Mapper

The specification for this mapper is outlined in the prep video:

Non-numeric cards are considered to be bad data and ignored. Numeric cards should be emitted with their suit as the key and the numeric value as the value.

Emitting a key and a value would look something like:

Suit key = // appropriate code here
int value = // appropriate code here
keyValuePairConsumer.accept(key, value);
class: CardMapper.java Java.png
methods: map
package: mapreduce.app.cards.exercise
source folder: student/src/main/java

method: public void map(Deck deck, BiConsumer<Suit, Integer> keyValuePairConsumer) Sequential.svg (sequential implementation only)

Word Count Mapper

Counting occurrences of words in text is a classic example of mapreduce. We will ignore any zero length words and convert the remaining words to lower-case so as to get a case insensitive count. Emitting each lower-cased word as the key with the value of 1 should do the trick here.

class: WordCountMapper.java Java.png
methods: map
package: mapreduce.apps.wordcount.exercise
source folder: student/src/main/java

method: public void map(TextSection textSection, BiConsumer<String, Integer> keyValuePairConsumer) Sequential.svg (sequential implementation only)

The goal of this implementation is to count the number of times a word appears in a given text, using MapReduce. To accomplish this, you will need to create both the mapper and the reducer. Navigate to the WordCountMapper.java and IntSumClassicReducer.java classes. You will specifically define how the framework accomplishes the map and reduce methods.

The only method you will need to alter is the map method. In this method, you need to record every instance of a given word and feed it into the keyValuePairConsumer. To do this, access all of the words in the TextSection and if the length of the word is greater than zero (meaning it is not just blank space), convert it into lower-case and accept it into the consumer.

Hint: Look at the methods in TextSection and the toLowerCase() method for strings for assistance.

K-mer Count Mapper

K-mer counting is a useful technique in bioinformatics: http://www.csbio.unc.edu/mcmillan/Comp555S17/Lecture02.pdf

Background information on k-mer counting can be found here: https://en.wikipedia.org/wiki/K-mer

The 3-mers in the chromosome:

ACTCATGAG

are:

ACT
 CTC
  TCA
   CAT
    ATG
     TGA
      GAG
class: KMerMapper.java Java.png
methods: map
package: mapreduce.apps.kmer.studio
source folder: student/src/main/java

method: public void map(byte[] sequence, BiConsumer<String, Integer> keyValuePairConsumer) Sequential.svg (sequential implementation only)

Be sure to use the provided toStringKMer(sequence, offset, kMerLength) method to generate your k-mers:

	private static String toStringKMer(byte[] sequence, int offset, int kMerLength) {
		return new String(sequence, offset, kMerLength, StandardCharsets.UTF_8);
	}

This mapper is similar to the #Word Count Mapper except that the k-mers overlap with each other while words are separate.

As the emitted values for each key will be later summed up in the reduction phase, what value makes sense to emit with each key?

Int Sum Reducer

class: IntSumListAccumulatingReducer.java Java.png
methods: reduce
package: mapreduce.apps.reducer.listaccumulating.intsum.exercise
source folder: student/src/main/java

method: public Integer reduce(List<Integer> container) Sequential.svg (sequential implementation only)

The reduce method is passed a list of integers which it should simply sum up and return.

Testing Your Solution

Correctness: _IntSumExerciseTestSuite

class: _IntSumExerciseTestSuite.java Junit.png
package: mapreduce
source folder: testing/src/test/java

CardMapperTestSuite

class: _CardMapperTestSuite.java Junit.png
package: mapreduce.apps.cards.exercise
source folder: testing/src/test/java

KMerMapperTestSuite

class: _KMerMapperTestSuite.java Junit.png
package: mapreduce.apps.kmer.exercise
source folder: testing/src/test/java

WordCountStudioTestSuite

class: _WordCountStudioTestSuite.java Junit.png
package: mapreduce.apps.wordcount.exercise
source folder: testing/src/test/java

IntSumClassicReducerStudioTestSuite

class: _IntSumReduceOnlyTestSuite.java Junit.png
package: mapreduce.apps.reducer.listaccumulating.intsum.exercise
source folder: testing/src/test/java