Package org.apache.hadoop.io

Examples of org.apache.hadoop.io.Text


public class TestNGramReducer {
 
  @Test(expected = IOException.class)
  public final void testReducerForNullValues() throws IOException, InterruptedException {
    ArrayList<Text> values = new ArrayList<Text>();
    values.add(new Text("This is a bookdelimiterBetweenKeyAndValuevalue1"));
    values.add(new Text("This is not a bookdelimiterBetweenKeyAndValuevalue2"));
    Reducer.Context context = mock(Reducer.Context.class);
    NGramReducer reducer = new NGramReducer();
    reducer.reduce(null, values, context);
  }
View Full Code Here


  }
 
  @Test
  public void testReducerValidValues() throws IOException, InterruptedException {
    ArrayList<Text> values = new ArrayList<Text>();
    values.add(new Text("This is a bookdelimiterBetweenKeyAndValuevalue1"));
    values.add(new Text("This is not a bookdelimiterBetweenKeyAndValuevalue2"));
    Reducer.Context context = mock(Reducer.Context.class);
    NGramReducer reducer = new NGramReducer();
    reducer.reduce(new Text("This is"), values, context);
    ValuePair valuePair = new ValuePair();
    valuePair.setValue1(new Text("This is a bookdelimiterBetweenKeyAndValuevalue1"));
    valuePair.setValue2(new Text("This is not a bookdelimiterBetweenKeyAndValuevalue2"));
    verify(context).write(valuePair, new IntWritable(1));   
  }
View Full Code Here

 
  @Test(expected = IOException.class)
  public final void testMapperForNullValues() throws IOException, InterruptedException {
    Mapper.Context context = mock(Mapper.Context.class);
    NGramMapper mapper = new NGramMapper();
    mapper.map(null, new Text("value1"), context)
  }
View Full Code Here

 
  @Test
  public final void testMapperForValidValues() throws IOException, InterruptedException {
    Mapper.Context context = mock(Mapper.Context.class);
    NGramMapper mapper = new NGramMapper();
    mapper.map(new Text("This is a book"), new Text("value1"), context);
    verify(context).write(new Text("a book"), new Text("This is a bookdelimiterBetweenKeyAndValuevalue1"));
    verify(context).write(new Text("This is"), new Text("This is a bookdelimiterBetweenKeyAndValuevalue1"));
    verify(context).write(new Text("is a"), new Text("This is a bookdelimiterBetweenKeyAndValuevalue1"));
    }
View Full Code Here

    this.value2 = value2;
  }

  @Override
  public void readFields(DataInput in) throws IOException {
    value1 = new Text();
    value1.readFields(in);

    value2 = new Text();
    value2.readFields(in);
  }
View Full Code Here

    HashSet<String> nGramList = new HashSet<String>();
    int gramSize = 2;
    nGramList = getNGrams(key, gramSize);
    for (String nGrams : nGramList) {
      String value = key.toString() + "delimiterBetweenKeyAndValue" + val.toString();
      context.write(new Text(nGrams), new Text(value));
      logger.info("Key and Value in NGram Mapper is: " + new Text(nGrams)
          + ", " + new Text(value));
    }
  }
View Full Code Here

    ArrayList<Text> value = new ArrayList<Text>();
   
    Iterator<Text> iterator = values.iterator();
    while (iterator.hasNext()) {
      Text valueInIterator = iterator.next();
      logger.info("Value in NGram Reducer is: " + valueInIterator);
      value.add(new Text(valueInIterator));
    }

    for (Text valueInList : value) {
      logger.info("Value added in list is: " + valueInList);
    }
View Full Code Here

    return student;
  }
 
  @Test
  public void testMergeByCustomObjectKeyWithSequenceFileInputFormat() throws Exception {   
    Student student1 = setStudent(new Text("Sam"),new Text("US"),new IntWritable(1),
        new LongWritable(9999999998l),new DoubleWritable(99.12));       
    Student student2 = setStudent(new Text("John"),new Text("AUS"),new IntWritable(2),
        new LongWritable(9999999999l),new DoubleWritable(90.12));       
    Student student3 = setStudent(new Text("Mary"),new Text("UK"),new IntWritable(3),
        new LongWritable(9999999988l),new DoubleWritable(69.12));   
    Student student4 = setStudent(new Text("Kelvin"),new Text("UK"),new IntWritable(4),
        new LongWritable(9999998888l),new DoubleWritable(59.12));
 
    HashMap<Student, Text> inputData1 = new HashMap<Student, Text>();
    inputData1.put(student1, new Text("Macon Kent,6269 Aenean St.,1-247-399-1051,08253"));
    inputData1.put(student2, new Text("Dale Zamora,521-7792 Mauris Rd.,1-214-625-6970,90510"));
    inputData1.put(student3, new Text("Charles Wood,525-9709 In Rd.,1-370-528-4758,62714"));
    createSequenceFileInHdfs(inputData1, "/input1", "testFile1.seq");
   
    HashMap<Student, Text> inputData2 = new HashMap<Student, Text>();
    inputData2.put(student2, new Text("Austin Farley,4794 Donec Ave,1-230-823-8164,13508"));
    inputData2.put(student3, new Text("Macaulay Jackson,5435 Dui. Avenue,1-770-395-6446,31584"));
    inputData2.put(student4, new Text("Timon Leonard,716 Ac Ave,1-857-935-3882,62240"));
    createSequenceFileInHdfs(inputData2, "/input2", "testFile2.seq");
 

    String[] args = new String[] {
        "-newPath""/input1",
View Full Code Here

 
  @Test
  public void testMergeByIntWritableKeyWithSequenceFileInputFormat() throws Exception {
    HashMap<IntWritable, Text> inputData1 = new HashMap<IntWritable, Text>();
    inputData1.put(new IntWritable(1), new Text("Macon Kent,6269 Aenean St.,1-247-399-1051,08253"));
    inputData1.put(new IntWritable(2), new Text("Dale Zamora,521-7792 Mauris Rd.,1-214-625-6970,90510"));
    inputData1.put(new IntWritable(3), new Text("Charles Wood,525-9709 In Rd.,1-370-528-4758,62714"));
    createSequenceFileInHdfs(inputData1, "/input1", "testFile1.seq");
   
    HashMap<IntWritable, Text> inputData2 = new HashMap<IntWritable, Text>();
    inputData2.put(new IntWritable(1), new Text("Macaulay Jackson,5435 Dui. Avenue,1-770-395-6446,31584"));
    inputData2.put(new IntWritable(2), new Text("Timon Leonard,716 Ac Ave,1-857-935-3882,62240"));
    inputData2.put(new IntWritable(4), new Text("Charles Wood,525-9709 In Rd.,1-370-528-4758,62714"));
    createSequenceFileInHdfs(inputData2, "/input2", "testFile2.seq");
 

    String[] args = new String[] {
        "-newPath""/input1",
View Full Code Here

  }
 
  @Test
  public void testMergeByLongWritableKeyWithSequenceFileInputFormat() throws Exception {
    HashMap<LongWritable, Text> inputData1 = new HashMap<LongWritable, Text>();
    inputData1.put(new LongWritable(1), new Text("Macon Kent,6269 Aenean St.,1-247-399-1051,08253"));
    inputData1.put(new LongWritable(2), new Text("Dale Zamora,521-7792 Mauris Rd.,1-214-625-6970,90510"));
    inputData1.put(new LongWritable(3), new Text("Charles Wood,525-9709 In Rd.,1-370-528-4758,62714"));
    createSequenceFileInHdfs(inputData1, "/input1", "testFile1.seq");
   
    HashMap<LongWritable, Text> inputData2 = new HashMap<LongWritable, Text>();
    inputData2.put(new LongWritable(1), new Text("Macaulay Jackson,5435 Dui. Avenue,1-770-395-6446,31584"));
    inputData2.put(new LongWritable(2), new Text("Timon Leonard,716 Ac Ave,1-857-935-3882,62240"));
    inputData2.put(new LongWritable(4), new Text("Charles Wood,525-9709 In Rd.,1-370-528-4758,62714"));
    createSequenceFileInHdfs(inputData2, "/input2", "testFile2.seq");
 

    String[] args = new String[] {
        "-newPath""/input1",
View Full Code Here

TOP

Related Classes of org.apache.hadoop.io.Text

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.