LongIdTupleToGellyEdgeWithLongValueJoin.java

  1. /*
  2.  * Copyright © 2014 - 2021 Leipzig University (Database Research Group)
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.gradoop.flink.algorithms.gelly.randomjump.functions;

  17. import org.apache.flink.api.common.functions.JoinFunction;
  18. import org.apache.flink.api.java.functions.FunctionAnnotation;
  19. import org.apache.flink.api.java.tuple.Tuple2;
  20. import org.apache.flink.api.java.tuple.Tuple3;
  21. import org.apache.flink.graph.Edge;
  22. import org.gradoop.common.model.impl.id.GradoopId;

  23. /**
  24.  * Creates a Gelly edge with its long index as its value.
  25.  */
  26. @FunctionAnnotation.ForwardedFieldsFirst("f0;f1")
  27. @FunctionAnnotation.ForwardedFieldsSecond("f0->f2")
  28. public class LongIdTupleToGellyEdgeWithLongValueJoin implements
  29.   JoinFunction<Tuple3<Long, Long, GradoopId>, Tuple2<Long, GradoopId>, Edge<Long, Long>> {

  30.   /**
  31.    * Reduce object instantiation.
  32.    */
  33.   private final Edge<Long, Long> reuseEdge;

  34.   /**
  35.    * Creates an instance of LongIdTupleToGellyEdgeWithLongValueJoin.
  36.    */
  37.   public LongIdTupleToGellyEdgeWithLongValueJoin() {
  38.     this.reuseEdge = new Edge<>();
  39.   }

  40.   @Override
  41.   public Edge<Long, Long> join(Tuple3<Long, Long, GradoopId> edgeTuple,
  42.     Tuple2<Long, GradoopId> indexToEdgeId) throws Exception {
  43.     reuseEdge.setSource(edgeTuple.f0);
  44.     reuseEdge.setTarget(edgeTuple.f1);
  45.     reuseEdge.setValue(indexToEdgeId.f0);
  46.     return reuseEdge;
  47.   }
  48. }