@Override protected Object processDouble(Double value) { return new DoubleWritable(value); }
@Override public void checkDouble(Object typeFromJson) { assertEquals(new DoubleWritable(Double.MAX_VALUE), typeFromJson); }
@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); } } } }
@Test public void testDouble() { writableTypeToJson(new DoubleWritable(Double.MAX_VALUE)); }
return new DoubleWritable((double) o);
return new DoubleWritable((Double) object);
@Test public void testConvertDoubleWritable() { AvroDatumConverter<DoubleWritable, Double> converter = mFactory.create(DoubleWritable.class); assertEquals(2.0, converter.convert(new DoubleWritable(2.0)).doubleValue(), 0.00001); }
return new DoubleWritable((double) o);
@Test public void testConversionInSameGroup() throws HiveException { GenericUDFNullif udf = new GenericUDFNullif(); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(new DoubleWritable(4.0)), new DeferredJavaObject(new ByteWritable((byte) 4)) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); }
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 ) ); } }
static List<Tuple2<PairOfStrings, DoubleWritable>> toWritableList(Map<Tuple2<String,String>, Double> PT) { List<Tuple2<PairOfStrings, DoubleWritable>> list = new ArrayList<Tuple2<PairOfStrings, DoubleWritable>>(); for (Map.Entry<Tuple2<String,String>, Double> entry : PT.entrySet()) { list.add(new Tuple2<PairOfStrings, DoubleWritable>( new PairOfStrings(entry.getKey()._1, entry.getKey()._2), new DoubleWritable(entry.getValue()) )); } return list; }
public void map (final LongWritable key, final Text value, final OutputCollector<IntWritable, DoubleWritable> output, final Reporter reporter) throws IOException { String line_text = value.toString(); int tabpos = line_text.indexOf("\t"); int out_key = Integer.parseInt(line_text.substring(0, tabpos)); output.collect( new IntWritable(out_key) , new DoubleWritable( Double.parseDouble(line_text.substring(tabpos+1)) ) ); } }
public void map (final LongWritable key, final Text value, final OutputCollector<DoubleWritable, IntWritable> output, final Reporter reporter) throws IOException { String line_text = value.toString(); int tabpos = line_text.indexOf("\t"); int out_val = Integer.parseInt(line_text.substring(0, tabpos)); output.collect( new DoubleWritable( Double.parseDouble(line_text.substring(tabpos+1)) ), new IntWritable(out_val) ); } }
static List<Tuple2<PairOfStrings, DoubleWritable>> toWritableList(Map<Tuple2<String,String>, Double> PT) { List<Tuple2<PairOfStrings, DoubleWritable>> list = new ArrayList<Tuple2<PairOfStrings, DoubleWritable>>(); for (Map.Entry<Tuple2<String,String>, Double> entry : PT.entrySet()) { list.add(new Tuple2<PairOfStrings, DoubleWritable>( new PairOfStrings(entry.getKey()._1, entry.getKey()._2), new DoubleWritable(entry.getValue()) )); } return list; }
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 pagerank = Double.parseDouble(line[1].substring(1)); output.collect( new IntWritable(0) , new DoubleWritable( pagerank ) ); output.collect( new IntWritable(1) , new DoubleWritable( pagerank ) ); } }
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]) ) ); } }
public void reduce (final Text key, final Iterator<DoubleWritable> values, final OutputCollector<Text, DoubleWritable> output, final Reporter reporter) throws IOException { double sum = 0; while (values.hasNext()) { double cur_val = values.next().get(); sum += cur_val; } output.collect( key, new DoubleWritable( sum ) ); } }
public void reduce (final IntWritable key, final Iterator<DoubleWritable> values, final OutputCollector<IntWritable, DoubleWritable> output, final Reporter reporter) throws IOException { double sum = 0; int count = 0; while (values.hasNext()) { double cur_val = values.next().get(); sum += cur_val; count++; } output.collect( key, new DoubleWritable( sum/count ) ); } }
public void reduce (final IntWritable key, final Iterator<DoubleWritable> values, final OutputCollector<IntWritable, DoubleWritable> output, final Reporter reporter) throws IOException { double sum = 0; while (values.hasNext()) { double cur_val = values.next().get(); sum += cur_val; } output.collect( key, new DoubleWritable( sum ) ); } }
public void reduce(Text key, Iterable<PairOfLongInt> values, Context context) throws IOException, InterruptedException { long sum = 0; int count = 0; for (PairOfLongInt pair : values) { sum += pair.getLeftElement(); count += pair.getRightElement(); } context.write(key, new DoubleWritable(sum / count)); } }