Example usage for org.apache.hadoop.io Text toString

List of usage examples for org.apache.hadoop.io Text toString

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text toString.

Prototype

@Override
public String toString() 

Source Link

Document

Convert text back to string

Usage

From source file:com.intel.hadoop.graphbuilder.io.MultiDirOutputFormat.java

License:Open Source License

@Override
protected String generateFileNameForKeyValue(Text key, Text value, String name) {
    String[] path = key.toString().split(" ");
    if (path.length > 1) {
        return new Path(path[0], path[1]).toString();
    } else {/*from  www  .j av  a2s  .c om*/
        return new Path(key.toString(), name).toString();
    }
}

From source file:com.intel.hadoop.graphbuilder.partition.mapreduce.edge.EdgeIngressMapper.java

License:Open Source License

@Override
public void map(LongWritable key, Text value, OutputCollector<KeyType, ValueType> out, Reporter reporter)
        throws IOException {

    String text = value.toString();
    if (text.startsWith("!")) {
        // Remove vertex escape character ! before parsing
        text = text.substring(1);/*from  w w w .  j av a2  s  .  c om*/
        if (graphparser.isVertexData(text))
            mapVertexInput(text, out, reporter);
    } else if (graphparser.isEdgeData(text)) {
        mapEdgeInput(text, out, reporter);
    } else {
        LOG.error("Fail to parse: " + value.toString());
    }
}

From source file:com.intel.hadoop.graphbuilder.partition.mapreduce.vrecord.VrecordIngressMapper.java

License:Open Source License

@Override
public void map(LongWritable arg0, Text arg1, OutputCollector<IntWritable, Text> out, Reporter reporter)
        throws IOException {

    JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
    JSONObject obj;/*w  w  w. j a  v  a 2s. c o m*/
    try {
        String rec = arg1.toString();
        obj = (JSONObject) parser.parse(rec);

        short owner = ((Long) obj.get("owner")).shortValue();
        out.collect(new IntWritable(owner), new Text(rec));
        JSONArray mirrors = (JSONArray) obj.get("mirrors");
        for (int j = 0; j < mirrors.size(); j++) {
            out.collect(new IntWritable(((Long) mirrors.get(j)).intValue()), new Text(rec));
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:com.intel.hadoop.graphbuilder.partition.mapreduce.vrecord.VrecordIngressReducer.java

License:Open Source License

@Override
public void reduce(IntWritable key, Iterator<Text> value, OutputCollector<Text, Text> out, Reporter reporter)
        throws IOException {
    int numVertices = 0;
    int numOwnVertices = 0;

    JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
    while (value.hasNext()) {
        Text vrecString = value.next();
        JSONObject obj;/*www .  j a  v a 2 s . c  o m*/
        try {
            obj = (JSONObject) parser.parse(vrecString.toString());
            int owner = ((Long) obj.get("owner")).intValue();
            if (owner == key.get()) {
                numOwnVertices++;
                reporter.incrCounter(COUNTER.OWN_VERTICES, 1);
            }
            out.collect(new Text("partition" + key.get() + " vrecord"), vrecString);
            numVertices++;
            reporter.incrCounter(COUNTER.VERTICES, 1);
        } catch (ParseException e) {
            e.printStackTrace();
        } // end try parsing
    } // end while

    JSONObject summary = new JSONObject();
    summary.put("numVertices", numVertices);
    summary.put("numOwnVertices", numOwnVertices);
    out.collect(new Text("partition" + key.get() + " meta"), new Text(summary.toJSONString()));
}

From source file:com.intel.hadoop.graphbuilder.preprocess.mapreduce.CreateGraphMapper.java

License:Open Source License

@Override
public void map(LongWritable key, Text value, OutputCollector<IntWritable, VertexEdgeUnionType> out,
        Reporter arg3) throws IOException {

    tokenizer.parse(value.toString());
    Iterator<Edge> eiter = tokenizer.getEdges();
    Iterator<Vertex> viter = tokenizer.getVertices();
    try {// w  w w  .  j  a  v a2 s . c o m

        while (eiter.hasNext()) {
            Edge e = eiter.next();
            mapVal.init(VertexEdgeUnionType.EDGEVAL, e);
            out.collect(new IntWritable(e.hashCode()), mapVal);
        }

        while (viter.hasNext()) {
            Vertex v = viter.next();
            mapVal.init(VertexEdgeUnionType.VERTEXVAL, v);
            out.collect(new IntWritable(v.hashCode()), mapVal);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.intel.hadoop.graphbuilder.preprocess.mapreduce.EdgeTransformMapper.java

License:Open Source License

@Override
public void map(LongWritable key, Text value, OutputCollector<VidType, PairListType> out, Reporter report)
        throws IOException {
    String line = value.toString();
    try {//from  w w w.  ja  v  a2  s  .com

        if (graphparser.isEdgeData(line)) {
            Edge e = graphparser.parseEdge(line, vidparser, edataparser);
            if (reduceEndPoint == EdgeTransformMR.SOURCE) {
                val.init(e.target(), e.EdgeData());
                out.collect((VidType) e.source(), val);
            } else {
                val.init(e.source(), e.EdgeData());
                out.collect((VidType) e.target(), val);
            }
        } else {
            LOG.error("Skip line: " + line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.intel.hadoop.graphbuilder.types.StringType.java

License:Open Source License

@Override
public void readFields(DataInput arg0) throws IOException {
    Text text = new Text();
    text.readFields(arg0);/*w ww.ja  va2s  .c  o  m*/
    this.str = text.toString();
}

From source file:com.j.distributed.counter.CounterMapper.java

@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String fileName = ((FileSplit) context.getInputSplit()).getPath().getName();
    context.write(new Text(fileName), new IntWritable(countOccurrencies(value.toString())));
}

From source file:com.j.distributed.sorter.SorterMapper.java

@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String[] data = value.toString().split("\t");
    context.write(new LongWritable(Long.parseLong(data[1])), new Text(data[0]));
}

From source file:com.javiertordable.mrif.SieveMapper.java

License:Apache License

/**
 * Perform the map phase of the MapReduce.
 *
 * @param key is the input key, the line number of the input file. Ignored.
 * @param value is a serialized {@link SieveArray}.
 * @param context is the Mapper context, with common information for all the
 *     mapper jobs./*  w w w .  java2 s .  c  o  m*/
 */
public void map(LongWritable key, Text value, Context context) {
    // Extract the sieve interval from the input.
    SieveArray sieveInterval;
    try {
        sieveInterval = SieveArray.fromString(value.toString(), 0);
    } catch (ParseException e) {
        mapper_invalid_sieve_array.increment(1);
        LOGGER.severe("Unable to parse the input SieveArray. Exiting.");
        LOGGER.info(value.toString());
        return;
    }

    // Sieve
    SieveArray sieved = sieve(N, sieveInterval, factorBase);

    // Output the sieved results
    Text outputKey = new Text("1");
    Text outputValue = new Text(sieved.toString());
    try {
        context.write(outputKey, outputValue);
    } catch (IOException e) {
        mapper_unable_to_output.increment(1);
        LOGGER.severe("Unable to write the map output. IOException: " + e);
        return;
    } catch (InterruptedException e) {
        mapper_unable_to_output.increment(1);
        LOGGER.severe("Unable to write the map output. InterruptedException: " + e);
        return;
    }
}