Package org.apache.flink.types

Examples of org.apache.flink.types.Record


    @Override
    public void coGroup(Iterator<Record> candidates, Iterator<Record> current, Collector<Record> out) throws Exception {
      if (!current.hasNext()) {
        throw new Exception("Error: Id not encountered before.");
      }
      Record old = current.next();
      long oldId = old.getField(1, LongValue.class).getValue();
     
      long minimumComponentID = Long.MAX_VALUE;

      while (candidates.hasNext()) {
        Record candidate = candidates.next();
        long candidateComponentID = candidate.getField(1, LongValue.class).getValue();
        if (candidateComponentID < minimumComponentID) {
          minimumComponentID = candidateComponentID;
        }
      }
     
View Full Code Here


    /**
     * Compute the new position (coordinate vector) of a cluster center.
     */
    @Override
    public void reduce(Iterator<Record> points, Collector<Record> out) {
      Record sum = sumPointsAndCount(points);
      sum.setField(1, sum.getField(1, Point.class).div(sum.getField(2, IntValue.class).getValue()));
      out.collect(sum);
    }
View Full Code Here

    public void combine(Iterator<Record> points, Collector<Record> out) {
      out.collect(sumPointsAndCount(points));
    }
   
    private final Record sumPointsAndCount(Iterator<Record> dataPoints) {
      Record next = null;
      p.clear();
      int count = 0;
     
      // compute coordinate vector sum and count
      while (dataPoints.hasNext()) {
        next = dataPoints.next();
        p.add(next.getField(1, Point.class));
        count += next.getField(2, IntValue.class).getValue();
      }
     
      next.setField(1, p);
      next.setField(2, new IntValue(count));
      return next;
    }
View Full Code Here

      int len = 0;
      int key = -1;
     
      // collect all values
      while (records.hasNext()) {
        final Record rec = records.next();
        final int id = rec.getField(1, IntValue.class).getValue();
        if (key == -1) {
          key = rec.getField(0, IntValue.class).getValue();
        }
       
        if (len >= vals.length) {
          vals = new int[vals.length * 2];
          System.arraycopy(this.vals, 0, vals, 0, this.vals.length);
View Full Code Here

    public void reduce(Iterator<Record> records, Collector<Record> out) {
      // Compute the sum
      int sum = 0;
     
      while (records.hasNext()) {
        Record r = records.next();
        Integer value = Integer.parseInt(r.getField(0, StringValue.class).getValue());
        sum += value;
        testCounter.add(value);
      }
      out.collect(new Record(new StringValue(Integer.toString(sum))));
    }
View Full Code Here

     
      while (it.hasNext()) {
        sum += Integer.parseInt(it.next().getField(0, StringValue.class).getValue()) + 1;
      }
     
      out.collect(new Record(new StringValue(Integer.toString(sum))));
    }
View Full Code Here

    private final IntValue count1 = new IntValue();
    private final IntValue count2 = new IntValue();

    @Override
    public void reduce(Iterator<Record> records, Collector<Record> out) throws Exception {
      Record rec = null;
      int c1 = 0, c2 = 0;
      int numValues = 0;
     
      while (records.hasNext()) {
        rec = records.next();
        final int f1 = rec.getField(2, IntValue.class).getValue();
        final int f2 = rec.getField(3, IntValue.class).getValue();
        c1 += f1;
        c2 += f2;
        numValues++;
      }
     
      if (numValues != 2 || c1 == 0 || c2 == 0) {
        throw new RuntimeException("JoinCountsAndUniquify Problem: key1=" +
          rec.getField(0, IntValue.class).getValue() + ", key2=" +
          rec.getField(1, IntValue.class).getValue() +
          "values=" + numValues + ", c1=" + c1 + ", c2=" + c2);
      }
     
      count1.setValue(c1);
      count2.setValue(c2);
      rec.setField(2, count1);
      rec.setField(3, count2);
      out.collect(rec);
    }
View Full Code Here

    private StringValue valueString = new StringValue();
   
    @Override
    public void coGroup(Iterator<Record> records1, Iterator<Record> records2, Collector<Record> out) {
     
      Record record = null;
      int sum = 0;
     
      while (records1.hasNext()) {
        record = records1.next();
        keyString = record.getField(0, keyString);
        valueString = record.getField(1, valueString);
        sum += Integer.parseInt(valueString.getValue());
      }
     
     
      while (records2.hasNext()) {
        record = records2.next();
        keyString = record.getField(0, keyString);
        valueString = record.getField(1, valueString);
        sum -= Integer.parseInt(valueString.getValue());
      }
      record.setField(1, new IntValue(sum));
     
      out.collect(record);
    }
View Full Code Here

  /**
   * Compute the new position (coordinate vector) of a cluster center.
   */
  @Override
  public void reduce(Iterator<Record> dataPoints, Collector<Record> out) {
    Record next = null;
     
    // initialize coordinate vector sum and count
    CoordVector coordinates = new CoordVector();
    double[] coordinateSum = null;
    int count = 0

    // compute coordinate vector sum and count
    while (dataPoints.hasNext()) {
      next = dataPoints.next();
     
      // get the coordinates and the count from the record
      double[] thisCoords = next.getField(1, CoordVector.class).getCoordinates();
      int thisCount = next.getField(2, IntValue.class).getValue();
     
      if (coordinateSum == null) {
        if (coordinates.getCoordinates() != null) {
          coordinateSum = coordinates.getCoordinates();
        }
        else {
          coordinateSum = new double[thisCoords.length];
        }
      }

      addToCoordVector(coordinateSum, thisCoords);
      count += thisCount;
    }

    // compute new coordinate vector (position) of cluster center
    for (int i = 0; i < coordinateSum.length; i++) {
      coordinateSum[i] /= count;
    }
   
    coordinates.setCoordinates(coordinateSum);
    next.setField(1, coordinates);
    next.setNull(2);

    // emit new position of cluster center
    out.collect(next);
  }
View Full Code Here

   * Computes a pre-aggregated average value of a coordinate vector.
   */
  @Override
  public void combine(Iterator<Record> dataPoints, Collector<Record> out) {
   
    Record next = null;
   
    // initialize coordinate vector sum and count
    CoordVector coordinates = new CoordVector();
    double[] coordinateSum = null;
    int count = 0

    // compute coordinate vector sum and count
    while (dataPoints.hasNext()) {
      next = dataPoints.next();
     
      // get the coordinates and the count from the record
      double[] thisCoords = next.getField(1, CoordVector.class).getCoordinates();
      int thisCount = next.getField(2, IntValue.class).getValue();
     
      if (coordinateSum == null) {
        if (coordinates.getCoordinates() != null) {
          coordinateSum = coordinates.getCoordinates();
        }
        else {
          coordinateSum = new double[thisCoords.length];
        }
      }

      addToCoordVector(coordinateSum, thisCoords);
      count += thisCount;
    }
   
    coordinates.setCoordinates(coordinateSum);
    this.count.setValue(count);
    next.setField(1, coordinates);
    next.setField(2, this.count);
   
    // emit partial sum and partial count for average computation
    out.collect(next);
  }
View Full Code Here

TOP

Related Classes of org.apache.flink.types.Record

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.