ExtractKeyedCandidateEdges.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.model.impl.operators.matching.single.cypher.operators.expand.functions;

  17. import org.apache.flink.api.common.functions.RichMapFunction;
  18. import org.apache.flink.configuration.Configuration;
  19. import org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding;
  20. import org.gradoop.flink.model.impl.operators.matching.single.cypher.operators.expand.tuples.EdgeWithTiePoint;

  21. /**
  22.  * Extract the join key from an edge embedding and stores both in an {@link EdgeWithTiePoint}
  23.  */
  24. public class ExtractKeyedCandidateEdges
  25.   extends RichMapFunction<Embedding, EdgeWithTiePoint> {

  26.   /**
  27.    * Reuse Tuple
  28.    */
  29.   private EdgeWithTiePoint reuseEdgeWitTiePoint;

  30.   @Override
  31.   public void open(Configuration parameters) throws Exception {
  32.     this.reuseEdgeWitTiePoint = new EdgeWithTiePoint();
  33.   }

  34.   @Override
  35.   public EdgeWithTiePoint map(Embedding edge) throws Exception {
  36.     reuseEdgeWitTiePoint.setSource(edge.getId(0));
  37.     reuseEdgeWitTiePoint.setId(edge.getId(1));
  38.     if (edge.size() == 3) {
  39.       // normal edge
  40.       reuseEdgeWitTiePoint.setTarget(edge.getId(2));
  41.     } else {
  42.       // loop edge
  43.       reuseEdgeWitTiePoint.setTarget(edge.getId(0));
  44.     }

  45.     return reuseEdgeWitTiePoint;
  46.   }
  47. }