List of usage examples for org.apache.hadoop.io Text Text
public Text(byte[] utf8)
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueenPartialShotMapperReducerTest.java
@Test public void testMapper() throws IOException { mapDriver.getConfiguration().set(NQueenPartialShotMapper.NQueenRowSize_PROP, "4"); mapDriver.withInput(new LongWritable(), new Text("4#")); mapDriver.withOutput(new Text("4:1,3,0,2"), NullWritable.get()); mapDriver.withOutput(new Text("4:2,0,3,1"), NullWritable.get()); mapDriver.runTest();// ww w . ja v a2 s.c om }
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueenPartialShotMapperReducerTest.java
@Test public void testMapper2ndStep() throws IOException { mapDriver.withInput(new LongWritable(), new Text("6:0,2,4,1")); // mapDriver.withOutput(new Text(), NullWritable.get()); mapDriver.runTest();/*from w ww . j a v a 2s . c o m*/ }
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueenPartialShotMapperReducerTest.java
/** * 3,0,4,1 => 5,2/*from w w w . j ava 2s. c om*/ 1,3,5,0 => 2,5 2,5,1,4 => 0,3 4,2,0,5 => 3,1 * */ @Test public void testMapper2ndStepBoard6() throws IOException { mapDriver.withInput(new LongWritable(), new Text("6:1,3,5,0")); mapDriver.withInput(new LongWritable(), new Text("6:2,5,1,4")); mapDriver.withInput(new LongWritable(), new Text("6:3,0,4,1")); mapDriver.withInput(new LongWritable(), new Text("6:4,2,0,5")); mapDriver.withOutput(new Text("6:1,3,5,0,2,4"), NullWritable.get()); mapDriver.withOutput(new Text("6:2,5,1,4,0,3"), NullWritable.get()); mapDriver.withOutput(new Text("6:3,0,4,1,5,2"), NullWritable.get()); mapDriver.withOutput(new Text("6:4,2,0,5,3,1"), NullWritable.get()); mapDriver.runTest(); }
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueenPartialShotMapperReducerTest.java
/** * 3,0,4,1 => 5,2//from w w w .j a v a 2 s.c om 1,3,5,0 => 2,5 2,5,1,4 => 0,3 4,2,0,5 => 3,1 * */ @Test public void testMapper2ndStepBoard8() throws IOException { mapDriver.withInput(new LongWritable(), new Text("6:1,3,5,0")); mapDriver.withInput(new LongWritable(), new Text("6:2,5,1,4")); mapDriver.withInput(new LongWritable(), new Text("6:3,0,4,1")); mapDriver.withInput(new LongWritable(), new Text("6:4,2,0,5")); mapDriver.withOutput(new Text("6:1,3,5,0,2,4"), NullWritable.get()); mapDriver.withOutput(new Text("6:2,5,1,4,0,3"), NullWritable.get()); mapDriver.withOutput(new Text("6:3,0,4,1,5,2"), NullWritable.get()); mapDriver.withOutput(new Text("6:4,2,0,5,3,1"), NullWritable.get()); mapDriver.runTest(); }
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueensIncrementalSolutionCounterTest.java
@Test public void testMapFunction() throws IOException { mapDriver.withInput(new LongWritable(), new Text("5:")); mapDriver.withOutput(new Text("5:0,2,4,1"), new Text("5:0,2,4,1")); mapDriver.withOutput(new Text("5:0,3,1,4"), new Text("5:0,3,1,4")); mapDriver.withOutput(new Text("5:1,3,0,2"), new Text("5:1,3,0,2")); mapDriver.withOutput(new Text("5:1,4,0,3"), new Text("5:1,4,0,3")); mapDriver.withOutput(new Text("5:1,4,2,0"), new Text("5:1,4,2,0")); mapDriver.withOutput(new Text("5:2,0,3,1"), new Text("5:2,0,3,1")); mapDriver.withOutput(new Text("5:2,4,1,3"), new Text("5:2,4,1,3")); mapDriver.withOutput(new Text("5:3,0,2,4"), new Text("5:3,0,2,4")); mapDriver.withOutput(new Text("5:3,0,4,1"), new Text("5:3,0,4,1")); mapDriver.withOutput(new Text("5:3,1,4,2"), new Text("5:3,1,4,2")); mapDriver.withOutput(new Text("5:4,1,3,0"), new Text("5:4,1,3,0")); mapDriver.withOutput(new Text("5:4,2,0,3"), new Text("5:4,2,0,3")); mapDriver.runTest();/*from w w w. ja va 2s . c om*/ }
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueensIncrementalSolutionCounterTest.java
@Test public void testMapFunction2ndStep() throws IOException { // mapDriver.withInput(new Text(), new Text("256:0,2,4,7")); // mapDriver.withInput(new Text("256:0,2,4,7"), new Text("256:0,2,4,7,1,3,5,10,13,15,6,18,20,22,8,25,9,28,30,11,33,12,17,37,14,40,42,16,45,47,49,19,52,54,21,57,59,61,23,64,24,67,69,26,72,27,32,76,29,79,81,31,84,86,88,34,91,93,35,96,36,39,100,38,103,105,107,109,41,43,113,115,117,44,46,121,123,125,48,128,130,132,50,135,51,138,55,53,142,144,146,148,56,58,152,154,156,60,159,161,163,62,166,63,169,171,65,174,66,71,178,68,181,183,70,186,188,190,73,193,74,196,75,199,201,203,77,206,78,209,82,80,213,215,217,219,83,85,223,225,227,87,230,232,234,89,237,90,240,242,244,254,251,249,255,252,94,98,253,95,102,92,97=0")); mapDriver.withInput(new LongWritable(), new Text("12:0,2,4,1")); // mapDriver.withInput(new Text(), new Text("5:0,3,1,4")); // mapDriver.withInput(new Text(), new Text("5:1,3,0,2")); // mapDriver.withInput(new Text(), new Text("5:1,4,0,3")); // mapDriver.withInput(new Text(), new Text("5:1,4,2,0")); // mapDriver.withInput(new Text(), new Text("5:2,0,3,1")); // mapDriver.withInput(new Text(), new Text("5:2,4,1,3")); // mapDriver.withInput(new Text(), new Text("5:3,0,2,4")); // mapDriver.withInput(new Text(), new Text("5:3,0,4,1")); // mapDriver.withInput(new Text(), new Text("5:3,1,4,2")); // mapDriver.withInput(new Text(), new Text("5:4,1,3,0")); // mapDriver.withInput(new Text(), new Text("5:4,2,0,3")); ///*from w w w . j ava 2 s.c o m*/ // mapDriver.withOutput(new Text("5:0,2,4,1"), new Text("5:0,2,4,1=1;")); // mapDriver.withOutput(new Text("5:0,3,1,4"), new Text("5:0,3,1,4=1;")); // mapDriver.withOutput(new Text("5:1,3,0,2"), new Text("5:1,3,0,2=1;")); // mapDriver.withOutput(new Text("5:1,4,0,3"), new Text("5:1,4,0,3=0;")); // mapDriver.withOutput(new Text("5:1,4,2,0"), new Text("5:1,4,2,0=1;")); // mapDriver.withOutput(new Text("5:2,0,3,1"), new Text("5:2,0,3,1=1;")); // mapDriver.withOutput(new Text("5:2,4,1,3"), new Text("5:2,4,1,3=1;")); // mapDriver.withOutput(new Text("5:3,0,2,4"), new Text("5:3,0,2,4=1;")); // mapDriver.withOutput(new Text("5:3,0,4,1"), new Text("5:3,0,4,1=0;")); // mapDriver.withOutput(new Text("5:3,1,4,2"), new Text("5:3,1,4,2=1;")); // mapDriver.withOutput(new Text("5:4,1,3,0"), new Text("5:4,1,3,0=1;")); // mapDriver.withOutput(new Text("5:4,2,0,3"), new Text("5:4,2,0,3=1;")); mapDriver.runTest(); }
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueensIncrementalSolutionCounterTest.java
@Test public void testReduceFunction() throws IOException { List<Text> values = new ArrayList<Text>(); values.add(new Text("12:0,2,4,1,0,0,0,0=5;")); values.add(new Text("12:0,2,4,1,0,0,0,1=3;")); values.add(new Text("12:0,2,4,1,0,0,0,2,5,5=3")); reduceDriver.addInput(new Text("12:0,2,4,1"), values); reduceDriver.addOutput(NullWritable.get(), new Text("12:0,2,4,1,0,0,0,2,5,5=3")); reduceDriver.addOutput(NullWritable.get(), new Text("12:0,2,4,1=8;")); reduceDriver.runTest();// w w w . ja v a2 s. c om }
From source file:br.com.lassal.nqueens.grid.mapreduce.NQueensIncrementalSolutionCounterTest.java
@Test public void testMapReduce() throws IOException { mapReduceDriver.addInput(new LongWritable(), new Text("8")); List<Pair<NullWritable, Text>> firstResult = mapReduceDriver.run(); MapReduceDriver<LongWritable, Text, Text, Text, NullWritable, Text> secondRun = MapReduceDriver .newMapReduceDriver(mapReduceDriver.getMapper(), mapReduceDriver.getReducer()); ;// ww w . j av a 2 s.c o m for (Pair<NullWritable, Text> pair : firstResult) { secondRun.addInput(new LongWritable(), pair.getSecond()); //secondRun.addAll(firstResult); } List<Pair<NullWritable, Text>> partialResult = secondRun.run(); NQueenIncrementalCounterResultMapper finalMapper = new NQueenIncrementalCounterResultMapper(); NQueenIncrementalCounterResultReducer finalReducer = new NQueenIncrementalCounterResultReducer(); MapReduceDriver<LongWritable, Text, Text, Text, NullWritable, Text> finalRun = MapReduceDriver .newMapReduceDriver(finalMapper, finalReducer); //finalRun.addAll(partialResult); for (Pair<NullWritable, Text> pair : partialResult) { finalRun.addInput(new LongWritable(), pair.getSecond()); } List<Pair<NullWritable, Text>> finalResult = finalRun.run(); for (Pair<NullWritable, Text> value : finalResult) { System.out.println(value.getFirst().toString() + " : " + value.getSecond().toString()); } }
From source file:br.puc_rio.ele.lvc.interimage.common.udf.CompressedJsonStorage.java
License:Apache License
@SuppressWarnings("unchecked") public void putNext(Tuple t) throws IOException { // Build a ByteArrayOutputStream to write the JSON into ByteArrayOutputStream baos = new ByteArrayOutputStream(BUF_SIZE); // Build the generator JsonGenerator json = jsonFactory.createJsonGenerator(baos, JsonEncoding.UTF8); // Write the beginning of the top level tuple object json.writeStartObject();/*w ww . ja v a2s. c o m*/ ResourceFieldSchema[] fields = schema.getFields(); for (int i = 0; i < fields.length; i++) { int tupleLength = t.size(); //write col if exists in tuple, null otherwise if (i < tupleLength) { writeField(json, fields[i], t.get(i)); } else { writeField(json, fields[i], null); } } json.writeEndObject(); json.close(); // Hand a null key and our string to Hadoop try { ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputStream snappyOut = new SnappyOutputStream(out); snappyOut.write(baos.toByteArray()); snappyOut.close(); writer.write(null, new Text(out.toByteArray())); } catch (InterruptedException ie) { throw new IOException(ie); } }
From source file:br.ufrj.nce.recureco.distributedindex.indexer.IndexerMap.java
License:Open Source License
public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException { FileSplit fileSplit = (FileSplit) reporter.getInputSplit(); String filename = fileSplit.getPath().getName(); List<String> tokenizedLine = lineTokenizer.tokenize(value.toString()); for (String auxWord : tokenizedLine) { output.collect(new Text(auxWord), new Text(filename)); }//from ww w . ja va 2 s . co m }