Package org.apache.flink.types

Examples of org.apache.flink.types.Record


    }

    @Override
    public void reduce(Iterator<Record> records, Collector<Record> out) throws Exception {
      // read the first edge
      final Record rec = records.next();
      // read the matching vertex
      rec.getFieldInto(0, this.matchVertex);
      // read the non-matching vertex and add it to the list
      rec.getFieldInto(1, this.otherVertices.get(0));
     
      // set the matching vertex in the output record
      this.result.setField(0, this.matchVertex);
     
      int numEdges = 1;
      // while there are more edges
      while (records.hasNext()) {

        // read the next edge
        final Record next = records.next();
       
        final StringValue myVertex;
        // obtain an object to store the non-matching vertex
        if (numEdges >= this.otherVertices.size()) {
          // we need an additional vertex object
          // create the object
          myVertex = new StringValue();
          // and put it in the list
          this.otherVertices.add(myVertex);
        } else {
          // we reuse a previously created object from the list
          myVertex = this.otherVertices.get(numEdges);
        }
        // read the non-matching vertex into the obtained object
        next.getFieldInto(1, myVertex);
       
        // combine the current edge with all vertices in the non-matching vertex list
        for (int i = 0; i < numEdges; i++) {
          // get the other non-matching vertex
          final StringValue otherVertex = this.otherVertices.get(i);
          // add my and other vertex to the output record depending on their ordering
          if (otherVertex.compareTo(myVertex) < 0) {
            this.result.setField(1, otherVertex);
            this.result.setField(2, myVertex);
            out.collect(this.result);
          } else {
            next.setField(2, otherVertex);
            out.collect(next);
          }
        }
       
        numEdges++;
View Full Code Here


      String line = record.getField(0, StringValue.class).getValue();
      String [] element = line.split(" ");
      String word = element[0];
      int count = Integer.parseInt(element[1]);
      if (stringList.contains(word)) {
        collector.collect(new Record(new StringValue(word), new IntValue(count)));
      }
    }
View Full Code Here

   
    @Override
    public void coGroup(Iterator<Record> inputRecords, Iterator<Record> concatRecords, Collector<Record> out) {

      // init minimum length and minimum path
      Record pathRec = null;
      StringValue path = null;
      if(inputRecords.hasNext()) {
        // path is in input paths
        pathRec = inputRecords.next();
      } else {
        // path must be in concat paths
        pathRec = concatRecords.next();
      }
      // get from node (common for all paths)
      StringValue fromNode = pathRec.getField(0, StringValue.class);
      // get to node (common for all paths)
      StringValue toNode = pathRec.getField(1, StringValue.class);
      // get length of path
      minLength.setValue(pathRec.getField(2, IntValue.class).getValue());
      // store path and hop count
      path = new StringValue(pathRec.getField(4, StringValue.class));
      shortestPaths.add(path);
      hopCnts.put(path, new IntValue(pathRec.getField(3, IntValue.class).getValue()));
           
      // find shortest path of all input paths
      while (inputRecords.hasNext()) {
        pathRec = inputRecords.next();
        IntValue length = pathRec.getField(2, IntValue.class);
       
        if (length.getValue() == minLength.getValue()) {
          // path has also minimum length add to list
          path = new StringValue(pathRec.getField(4, StringValue.class));
          if(shortestPaths.add(path)) {
            hopCnts.put(path, new IntValue(pathRec.getField(3, IntValue.class).getValue()));
          }
        } else if (length.getValue() < minLength.getValue()) {
          // path has minimum length
          minLength.setValue(length.getValue());
          // clear lists
          hopCnts.clear();
          shortestPaths.clear();
          // get path and add path and hop count
          path = new StringValue(pathRec.getField(4, StringValue.class));
          shortestPaths.add(path);
          hopCnts.put(path, new IntValue(pathRec.getField(3, IntValue.class).getValue()));
        }
      }

      // find shortest path of all input and concatenated paths
      while (concatRecords.hasNext()) {
        pathRec = concatRecords.next();
        IntValue length = pathRec.getField(2, IntValue.class);
       
        if (length.getValue() == minLength.getValue()) {
          // path has also minimum length add to list
          path = new StringValue(pathRec.getField(4, StringValue.class));
          if(shortestPaths.add(path)) {
            hopCnts.put(path, new IntValue(pathRec.getField(3, IntValue.class).getValue()));
          }
        } else if (length.getValue() < minLength.getValue()) {
          // path has minimum length
          minLength.setValue(length.getValue());
          // clear lists
          hopCnts.clear();
          shortestPaths.clear();
          // get path and add path and hop count
          path = new StringValue(pathRec.getField(4, StringValue.class));
          shortestPaths.add(path);
          hopCnts.put(path, new IntValue(pathRec.getField(3, IntValue.class).getValue()));
        }
      }
     
      outputRecord.setField(0, fromNode);
      outputRecord.setField(1, toNode);
View Full Code Here

    private static final long serialVersionUID = 1L;

    @Override
    public void join(Record value1, Record value2, Collector<Record> out) throws Exception {
      out.collect(new Record(value1.getField(1, StringValue.class), value2.getField(1, IntValue.class)));
    }
View Full Code Here

    private final LongValue minComponentId = new LongValue();
   
    @Override
    public void reduce(Iterator<Record> records, Collector<Record> out) {

      final Record first = records.next();
      final long vertexID = first.getField(0, LongValue.class).getValue();
     
      long minimumComponentID = first.getField(1, LongValue.class).getValue();

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

    LineItemFilter out = new LineItemFilter();
   
    String shipDate = "1996-03-13";
    Tuple input = createInputTuple(shipDate);
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
    rec.setField(1, input);
   
    Collector<Record> collector = new RecordOutputCollector(writerList);
   
    StringValue returnFlag = new StringValue(RETURN_FLAG);
   
View Full Code Here

    @Override
    public void reduce(Iterator<Record> records, Collector<Record> out) {
     
      double rankSum = 0.0;
      double rank;
      Record rec = null;

      while (records.hasNext()) {
        rec = records.next();
        rank = rec.getField(1, DoubleValue.class).getValue();
        rankSum += rank;
      }
     
      // ignore small deltas
      if (Math.abs(rankSum) > 0.00001) {
        newRank.setValue(rankSum);
        rec.setField(1, newRank);
        out.collect(rec);
      }
    }
View Full Code Here

   
    String shipDate = "1999-03-13";
   
    Tuple input = createInputTuple(shipDate);
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
    rec.setField(1, input);
   
    Collector<Record> collector = new RecordOutputCollector(writerList);
   
    out.map(rec, collector);
    verifyNoMoreInteractions(recordWriterMock);
View Full Code Here

  {
    LineItemFilter out = new LineItemFilter();
   
    Tuple input = null;
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
    rec.setField(1, input);
   
   
    Collector<Record> collector = new RecordOutputCollector(writerList);
   
    out.map(rec, collector);
View Full Code Here

   
    String shipDate = "foobarDate";
   
    Tuple input = createInputTuple(shipDate);
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
    rec.setField(1, input);
   
    Collector<Record> collector = new RecordOutputCollector(writerList);
   
    out.map(rec, collector);
    verifyNoMoreInteractions(recordWriterMock);
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.