return new IntWritable((int) o); return new BooleanWritable((boolean) o); return new LongWritable((long) o); return new FloatWritable((float) o); return new DoubleWritable((double) o); return new Text(o.toString()); return new BytesWritable(((ByteBuffer) o).array());
@Override public Object set(Object o, double value) { ((org.apache.hadoop.io.DoubleWritable) o).set(value); return o; }
public void map (final LongWritable key, final Text value, final OutputCollector<IntWritable, DoubleWritable> output, final Reporter reporter) throws IOException { String line_text = value.toString(); if (line_text.startsWith("#")) // ignore comments in edge file return; final String[] line = line_text.split("\t"); double rwr = Double.parseDouble(line[1].substring(1)); output.collect( new IntWritable(0) , new DoubleWritable( rwr ) ); output.collect( new IntWritable(1) , new DoubleWritable( rwr ) ); } }
CompressionType.BLOCK); Reporter.NULL); IntWritable iwritable = new IntWritable(); DoubleWritable dwritable = new DoubleWritable(); DataOutputBuffer outbuf = new DataOutputBuffer(); LOG.info("Creating data by SequenceFileAsBinaryOutputFormat"); try { for (int i = 0; i < RECORDS; ++i) { iwritable = new IntWritable(r.nextInt()); iwritable.write(outbuf); bkey.set(outbuf.getData(), 0, outbuf.getLength()); outbuf.reset(); dwritable = new DoubleWritable(r.nextDouble()); dwritable.write(outbuf); bval.set(outbuf.getData(), 0, outbuf.getLength()); outbuf.reset(); "Keys don't match: " + "*" + iwritable.get() + ":" + sourceInt + "*", sourceInt, iwritable.get()); assertTrue( "Vals don't match: " + "*" + dwritable.get() + ":" + sourceDouble + "*", Double.compare(dwritable.get(), sourceDouble) == 0 ); ++count;
public WritableComparable set(final String s) { if (null == s) return NULL_TEXT; if (type.equals(Text.class)) { text.set(s); return text; } else if (type.equals(LongWritable.class)) { longWritable.set(Long.valueOf(s)); return longWritable; } else if (type.equals(IntWritable.class)) { intWritable.set(Integer.valueOf(s)); return intWritable; } else if (type.equals(DoubleWritable.class)) { doubleWritable.set(Double.valueOf(s)); return doubleWritable; } else if (type.equals(FloatWritable.class)) { floatWritable.set(Float.valueOf(s)); return floatWritable; } else { throw new IllegalArgumentException("The provided type is not supported: " + type.getName()); } }
generator.writeUTF8String(text.getBytes(), 0, text.getLength()); generator.writeNumber(((IntWritable) writable).get()); generator.writeNumber(((LongWritable) writable).get()); generator.writeNumber(((DoubleWritable) writable).get()); generator.writeNumber(((FloatWritable) writable).get()); generator.writeBoolean(((BooleanWritable) writable).get()); generator.writeBinary(bw.getBytes(), 0, bw.getLength());
return new Text((String) object); return new DoubleWritable((Double) object); return new FloatWritable((Float) object); return new BooleanWritable((Boolean) object); return new BytesWritable((byte[]) object); return new BytesWritable(object.toString().getBytes(StringUtils.UTF_8));
@Override public void writeVertex( Vertex<LongWritable, DoubleWritable, NullWritable> vertex) throws IOException, InterruptedException { StringBuilder output = new StringBuilder(); output.append(vertex.getId().get()); output.append('\t'); output.append(vertex.getValue().get()); getRecordWriter().write(new Text(output.toString()), null); } }
String line_text = values.next().toString(); final String[] line = line_text.split("\t"); while(iter.hasNext()){ Map.Entry<Long, Double> entry = iter.next(); output.collect( new LongWritable( entry.getKey() ), new DoubleWritable( vector_val * entry.getValue() ) ); to_map.put(Long.parseLong(line[0]), new Double(1.0) ); else { output.collect(new LongWritable(Long.parseLong(line[0])), new DoubleWritable(vector_val) ); to_map.put(Long.parseLong(line[0]), Double.parseDouble(line[1]) ); else { output.collect(new LongWritable(Long.parseLong(line[0])), new DoubleWritable(vector_val * Double.parseDouble(line[1])) );
@Override protected void reduce(LongWritable key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException { double totalRate = 0; int activeMappers = 0; for (DoubleWritable value : values) { totalRate += value.get(); activeMappers++; } context.write(key, new Text(String.format("%f\t%d", totalRate, activeMappers))); } }
public void write(DataOutput out) throws IOException { new Text(context.getSplitId()).write(out); double[] u = context.getUInitial(); new IntWritable(u.length).write(out); for (double e : u) { new DoubleWritable(e).write(out); } double[] x = context.getXInitial(); new IntWritable(x.length).write(out); for (double e : x) { new DoubleWritable(e).write(out); } double[] z = context.getZInitial(); new IntWritable(z.length).write(out); for (double e : z) { new DoubleWritable(e).write(out); } new DoubleWritable(context.getRho()).write(out); new DoubleWritable(context.getLambdaValue()).write(out); new DoubleWritable(context.getPrimalObjectiveValue()).write(out); new DoubleWritable(context.getRNorm()).write(out); new DoubleWritable(context.getSNorm()).write(out); } }
@Override public Vertex<LongWritable, DoubleWritable, FloatWritable> getCurrentVertex() throws IOException, InterruptedException { Vertex<LongWritable, DoubleWritable, FloatWritable> vertex = conf.createVertex(); String[] tokens = neighborSeparator.split(getRecordReader() .getCurrentValue().toString()); List<Edge<LongWritable, FloatWritable>> edges = Lists.newArrayListWithCapacity(tokens.length - 1); for (int n = 1; n < tokens.length; n++) { String[] parts = weightSeparator.split(tokens[n]); edges.add(EdgeFactory.create( new LongWritable(Long.parseLong(parts[0])), new FloatWritable(Float.parseFloat(parts[1])))); } LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0])); vertex.initialize(vertexId, new DoubleWritable(), edges); return vertex; }
public void map (final LongWritable key, final Text value, final OutputCollector<LongWritable, DoubleWritable> output, final Reporter reporter) throws IOException { String line_text = value.toString(); if (line_text.startsWith("#")) // ignore comments in edge file return; final String[] line = line_text.split("\t"); from_node_int.set( Long.parseLong(line[0]) ); output.collect( from_node_int, new DoubleWritable( Double.parseDouble(line[1]) ) ); } }
@Override protected void map(LongWritable key, Text value,Context context) throws IOException, InterruptedException { // TODO Auto-generated method stub int index = context.getConfiguration().getInt("index", 0); String[] values = value.toString().split(delim); double val = Double.parseDouble(values[index]); IndexPair indexPair=new IndexPair(key.get(), index); context.write(indexPair, new DoubleWritable(val)); }
@Override public void run() { DescriptiveStatistics stats = this.limiter.getRateStatsSinceLastReport(); long now = System.currentTimeMillis(); this.runs++; if (stats != null) { long key; if (this.relativeKey) { key = 15 * this.runs; } else { DateTime nowTime = new DateTime(now).withMillisOfSecond(0); DateTime rounded = nowTime.withSecondOfMinute(15 * (nowTime.getSecondOfMinute() / 15)); key = rounded.getMillis() / 1000; } try { this.context.write(new LongWritable(key), new DoubleWritable(stats.getSum())); } catch (IOException | InterruptedException ioe) { log.error("Error: ", ioe); } } } }
@Override protected void reduce(Text key, Iterable<DoubleWritable> recordings, Context context) throws IOException, InterruptedException { double maxPrice = Double.MIN_VALUE; for (DoubleWritable recording : recordings) { if (maxPrice < recording.get()) { maxPrice = recording.get(); } } final StockWritable stock = new StockWritable(); stock.setStockName(key.toString()); stock.setMaxPrice(maxPrice); context.write(NullWritable.get(), stock); }
public void reduce (final IntWritable key, final Iterator<DoubleWritable> values, final OutputCollector<IntWritable, DoubleWritable> output, final Reporter reporter) throws IOException { int i; double min_value = 1.0; double max_value = 0.0; int min_or_max = key.get(); // 0 : min, 1: max while (values.hasNext()) { double cur_value = values.next().get(); if( min_or_max == 0 ) { // find min if( cur_value < min_value ) min_value = cur_value; } else { // find max if( cur_value > max_value ) max_value = cur_value; } } if( min_or_max == 0) output.collect( key, new DoubleWritable(min_value) ); else output.collect( key, new DoubleWritable(max_value) ); } }
public void write(DataOutput out) throws IOException { new BooleanWritable(null != context.getXUpdated()).write(out); if (null != context.getXUpdated()) { writer.set(context.getXUpdated()); writer.write(out); } new BooleanWritable(null != context.getUInitial()).write(out); if (null != context.getUInitial()) { writer.set(context.getUInitial()); writer.write(out); } new BooleanWritable(null != context.getZUpdated()).write(out); if (null != context.getZUpdated()) { writer.set(context.getZUpdated()); writer.write(out); } new DoubleWritable(context.getRho()).write(out); new DoubleWritable(context.getLambdaValue()).write(out); new DoubleWritable(context.getPrimalObjectiveValue()).write(out); new LongWritable(context.getCount()).write(out); }
@Override protected void map(NullWritable key, StockWritable stockWritable, Context context) throws IOException, InterruptedException { double[] recordings = stockWritable.getRecordings(); final String stockName = stockWritable.getStockName(); double maxPrice = Double.MIN_VALUE; for (double recording : recordings) { if (maxPrice < recording) { maxPrice = recording; } } stock.set(stockName); price.set(maxPrice); context.write(stock, price); } }