List of usage examples for org.apache.hadoop.io FloatWritable get
public float get()
From source file:Assignment2_P2_StockExchangeCount.StockPrice_Reducer.java
public void reduce(Text key, Iterable<FloatWritable> values, Context context) throws IOException, InterruptedException { float sum = 0; float count = 0; for (FloatWritable val : values) { sum += val.get(); count = count + 1;//w w w . j ava 2s .co m } float average = sum / count; result.set(average); context.write(key, result); }
From source file:Assignment3_P2_MergeStockAverageCount.StockPriceMerge_Reducer.java
public void reduce(Text key, Iterable<FloatWritable> values, Context context) throws IOException, InterruptedException { float sum = 0; float count = 0; for (FloatWritable val : values) { sum += val.get(); count = count + 1;//from w w w .jav a 2 s. c o m } float average = sum / count; result.set(average); context.write(key, result); }
From source file:Assignment3_P5_Top25Movies.Top25MovieRating_Reducer.java
public void reduce(IntWritable key, Iterable<FloatWritable> values, Context context) throws IOException, InterruptedException { float sum = 0; int count = 0; for (FloatWritable val : values) { sum += val.get(); count = count + 1;/* ww w . ja v a 2 s . c o m*/ } float avg = sum / count; result.set(avg); context.write(key, result); }
From source file:Assignment4_P3_InMemoryStdDeviation.MovieRatingStdDev_Reducer.java
public void reduce(IntWritable key, Iterable<FloatWritable> values, Context context) throws IOException, InterruptedException { int running_sum = 0; int running_count = 0; float median = 0; for (FloatWritable val : values) { list.add((float) val.get()); running_sum += val.get(); running_count++;//from w w w . j a v a 2 s . co m } Collections.sort(list); // calculating median if (list.size() % 2 == 0) { median = (list.get((running_count / 2) - 1) + list.get((running_count / 2))) / 2; } else { median = list.get((running_count / 2)); } // calculating mean float mean = running_sum / running_count; // calculating standard deviation float sumSquare = 0; float stdDev = 0; for (Float oneValue : list) { sumSquare += (oneValue - mean) * (oneValue - mean); } // finally, std dev stdDev = (float) Math.sqrt(sumSquare / (running_count - 1)); //.append(median) String outcome = new StringBuilder().append("\t").append(stdDev).append("\t").append(running_sum) .append("\t").append(running_count).toString(); result = new Text(outcome); context.write(key, result); }
From source file:Assignment4_P4_MemoryConscious.MovieRatingMemConscious_Reducer.java
public void reduce(IntWritable key, Iterable<SortedMapWritable> values, Context context) throws IOException, InterruptedException { int running_count = 0; long running_sum = 0; float median = 0; list = new TreeMap<>(); // loop through all ratings in received hashmap for this movieID for (SortedMapWritable val : values) { // iterate through every entry consisting of movieRating, countOfRating for ex (4.5, 10) i.e 10 people rated it 4.5 for (Map.Entry<WritableComparable, Writable> entry : val.entrySet()) { // extract movieRating for ex : 4.5 FloatWritable number = (FloatWritable) entry.getKey(); float movieRating = number.get(); //extract countOfRating for ex : 10 LongWritable counter = (LongWritable) entry.getValue(); long count = counter.get(); // calculate running sum by multiplying movieRating and countRating i.e (4.5 * 10 = 45) running_sum += (movieRating * count); // increment running count for getting average later i.e 10 running_count += count;//from w w w . j a va 2 s . co m // make <count> entries for <movieRating> in new hashmap i.e (4.5, 10) if (list.containsKey(movieRating)) { list.put(movieRating, list.get(movieRating) + count); } else { list.put(movieRating, count); } } } System.out.println("Running count for movieID " + key + " is :- " + running_count); System.out.println("Rating List size for movieID " + key + " is :- " + list.size()); // calculating mean float mean = running_sum / running_count; System.out.println("Mean for movieID " + key + " is :- " + mean); // calculating standard deviation float sumSquare = 0; float stdDev = 0; for (Map.Entry<Float, Long> entry : list.entrySet()) { sumSquare += (entry.getKey() - mean) * (entry.getKey() - mean) * (entry.getValue()); } // finally, std dev stdDev = (float) Math.sqrt(sumSquare / (running_count - 1)); System.out.println("Standard deviation for movieID " + key + " is :- " + stdDev); //.append(median) String outcome = new StringBuilder().append("\t").append(stdDev).append("\t").append(running_sum) .append("\t").append(running_count).toString(); result = new Text(outcome); context.write(key, result); }
From source file:cn.com.diditaxi.hive.cf.UDFToChar.java
License:Apache License
public Text evaluate(FloatWritable i, Text format) { if (i == null || format == null) { return null; } else {//from ww w.j a v a2 s . co m String pattern = format.toString().replace("9", "#"); decimalFormat.applyPattern(pattern); result.set(decimalFormat.format(i.get())); return result; } }
From source file:com.axiomine.largecollections.kryo.serializers.FloatWritableSerializer.java
License:Apache License
public void write(Kryo kryo, Output output, FloatWritable object) { output.writeFloat(object.get()); }
From source file:com.cloudera.impala.hive.executor.TestUdf.java
License:Apache License
public FloatWritable evaluate(FloatWritable a) { if (a == null) return null; return new FloatWritable(a.get()); }
From source file:com.facebook.hive.orc.lazy.OrcLazyFloatObjectInspector.java
License:Open Source License
@Override public Object getPrimitiveJavaObject(Object o) { FloatWritable writable = getPrimitiveWritableObject(o); return writable == null ? null : Float.valueOf(writable.get()); }
From source file:com.facebook.hive.orc.TestOrcFile.java
License:Apache License
private void compareRowsWithoutNextIsNull(OrcStruct row, RandomRowInputs inputs, int rowNumber, NumberOfNulls numNulls, boolean usingPrimitives) throws Exception { ReallyBigRow expected = null;/*from w w w .j a v a 2 s . c om*/ switch (numNulls) { case MANY: case SOME: expected = createRandomRowWithNulls(inputs.intValues, inputs.doubleValues, inputs.stringValues, inputs.byteValues, inputs.words, rowNumber, numNulls); break; case NONE: expected = createRandomRow(inputs.intValues, inputs.doubleValues, inputs.stringValues, inputs.byteValues, inputs.words, rowNumber); break; } OrcLazyBoolean lazyBoolean1 = (OrcLazyBoolean) row.getFieldValue(0); BooleanWritable boolean1 = (BooleanWritable) lazyBoolean1.materialize(); if (boolean1 == null) { assertNull(expected.boolean1); } else { assertEquals(expected.boolean1.booleanValue(), boolean1.get()); } ByteWritable byte1 = (ByteWritable) ((OrcLazyByte) row.getFieldValue(1)).materialize(); if (byte1 == null) { assertNull(expected.byte1); } else { assertEquals(expected.byte1.byteValue(), byte1.get()); } OrcLazyShort lazyShort1 = (OrcLazyShort) row.getFieldValue(2); ShortWritable short1 = (ShortWritable) lazyShort1.materialize(); if (short1 == null) { assertNull(expected.short1); } else { assertEquals(expected.short1.shortValue(), short1.get()); } OrcLazyInt lazyInt1 = (OrcLazyInt) row.getFieldValue(3); IntWritable int1 = (IntWritable) lazyInt1.materialize(); if (int1 == null) { assertNull(expected.int1); } else { assertEquals(expected.int1.intValue(), int1.get()); } OrcLazyLong lazyLong1 = (OrcLazyLong) row.getFieldValue(4); LongWritable long1 = (LongWritable) lazyLong1.materialize(); if (long1 == null) { assertNull(expected.long1); } else { assertEquals(expected.long1.longValue(), long1.get()); } OrcLazyShort lazyShort2 = (OrcLazyShort) row.getFieldValue(5); ShortWritable short2 = (ShortWritable) lazyShort2.materialize(); if (short2 == null) { assertNull(expected.short2); } else { assertEquals(expected.short2.shortValue(), short2.get()); } OrcLazyInt lazyInt2 = (OrcLazyInt) row.getFieldValue(6); IntWritable int2 = (IntWritable) lazyInt2.materialize(); if (int2 == null) { assertNull(expected.int2); } else { assertEquals(expected.int2.intValue(), int2.get()); } OrcLazyLong lazyLong2 = (OrcLazyLong) row.getFieldValue(7); LongWritable long2 = (LongWritable) lazyLong2.materialize(); if (long2 == null) { assertNull(expected.long2); } else { assertEquals(expected.long2.longValue(), long2.get()); } OrcLazyShort lazyShort3 = (OrcLazyShort) row.getFieldValue(8); ShortWritable short3 = (ShortWritable) lazyShort3.materialize(); if (short3 == null) { assertNull(expected.short3); } else { assertEquals(expected.short3.shortValue(), short3.get()); } OrcLazyInt lazyInt3 = (OrcLazyInt) row.getFieldValue(9); IntWritable int3 = (IntWritable) lazyInt3.materialize(); if (int3 == null) { assertNull(expected.int3); } else { assertEquals(expected.int3.intValue(), int3.get()); } OrcLazyLong lazyLong3 = (OrcLazyLong) row.getFieldValue(10); LongWritable long3 = (LongWritable) lazyLong3.materialize(); if (long3 == null) { assertNull(expected.long3); } else { assertEquals(expected.long3.longValue(), long3.get()); } OrcLazyFloat lazyFloat1 = (OrcLazyFloat) row.getFieldValue(11); FloatWritable float1 = (FloatWritable) lazyFloat1.materialize(); if (float1 == null) { assertNull(expected.float1); } else { assertEquals(expected.float1.floatValue(), float1.get(), 0.0001); } OrcLazyDouble lazyDouble1 = (OrcLazyDouble) row.getFieldValue(12); DoubleWritable double1 = (DoubleWritable) lazyDouble1.materialize(); if (double1 == null) { assertNull(expected.double1); } else { assertEquals(expected.double1.doubleValue(), double1.get(), 0.0001); } BytesWritable bytes1 = (BytesWritable) ((OrcLazyBinary) row.getFieldValue(13)).materialize(); if (bytes1 == null) { assertNull(expected.bytes1); } else { assertEquals(expected.bytes1, bytes1); } Text string1 = (Text) ((OrcLazyString) row.getFieldValue(14)).materialize(); if (string1 == null) { assertNull(expected.string1); } else { assertEquals(expected.string1, string1); } Text string2 = (Text) ((OrcLazyString) row.getFieldValue(15)).materialize(); if (string2 == null) { assertNull(expected.string2); } else { assertEquals(expected.string2, string2); } Text string3 = (Text) ((OrcLazyString) row.getFieldValue(16)).materialize(); if (string3 == null) { assertNull(expected.string3); } else { assertEquals(expected.string3, string3); } OrcStruct middle = (OrcStruct) ((OrcLazyStruct) row.getFieldValue(17)).materialize(); if (middle == null) { assertNull(expected.middle); } else { final List<InnerStruct> expectedList = expected.middle.list; final List<OrcStruct> actualList = (List) middle.getFieldValue(0); compareListOfStructs(expectedList, actualList); final List<String> actualFieldNames = middle.getFieldNames(); final List<String> expectedFieldNames = ImmutableList.of("list"); compareLists(expectedFieldNames, actualFieldNames); } List list = (List) ((OrcLazyList) row.getFieldValue(18)).materialize(); if (list == null) { assertNull(expected.list); } else { compareListOfStructs(expected.list, list); } Map map = (Map) ((OrcLazyMap) row.getFieldValue(19)).materialize(); if (map == null) { assertNull(expected.map); } else { compareMap(expected.map, map); } if (usingPrimitives) { compareRowsUsingPrimitives(expected, lazyBoolean1, lazyShort1, lazyInt1, lazyLong1, lazyShort2, lazyInt2, lazyLong2, lazyShort3, lazyInt3, lazyLong3, lazyFloat1, lazyDouble1); } }