BuildTuplesFromVertices.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.keyedgrouping.functions;

  17. import org.apache.flink.api.java.tuple.Tuple;
  18. import org.gradoop.common.model.api.entities.Element;
  19. import org.gradoop.flink.model.api.functions.AggregateFunction;
  20. import org.gradoop.flink.model.api.functions.KeyFunction;

  21. import java.util.List;

  22. /**
  23.  * Build a tuple-based representation of vertices for grouping.
  24.  * Tuples will contain the vertex ID, a reserved field for the super vertex ID, all grouping keys
  25.  * and all aggregate values.
  26.  *
  27.  * @param <E> The element type.
  28.  */
  29. public class BuildTuplesFromVertices<E extends Element> extends BuildTuplesFromElements<E> {

  30.   /**
  31.    * Initialize this function, setting the grouping keys abd aggregate functions.
  32.    *
  33.    * @param keys               The grouping keys.
  34.    * @param aggregateFunctions The aggregate functions used to determine the aggregate property
  35.    */
  36.   public BuildTuplesFromVertices(List<KeyFunction<E, ?>> keys, List<AggregateFunction> aggregateFunctions) {
  37.     super(GroupingConstants.VERTEX_TUPLE_RESERVED, keys, aggregateFunctions);
  38.   }

  39.   @Override
  40.   public Tuple map(E element) throws Exception {
  41.     final Tuple result = super.map(element);
  42.     result.setField(element.getId(), GroupingConstants.VERTEX_TUPLE_ID);
  43.     return result;
  44.   }
  45. }