Java Code Examples for org.apache.flink.api.java.operators.CoGroupOperator#name()
The following examples show how to use
org.apache.flink.api.java.operators.CoGroupOperator#name() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScatterGatherIteration.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Method that builds the scatter function using a coGroup operator for a simple vertex (without * degrees). * It afterwards configures the function with a custom name and broadcast variables. * * @param iteration * @param messageTypeInfo * @param whereArg the argument for the where within the coGroup * @param equalToArg the argument for the equalTo within the coGroup * @return the scatter function */ private CoGroupOperator<?, ?, Tuple2<K, Message>> buildScatterFunction( DeltaIteration<Vertex<K, VV>, Vertex<K, VV>> iteration, TypeInformation<Tuple2<K, Message>> messageTypeInfo, int whereArg, int equalToArg, DataSet<LongValue> numberOfVertices) { // build the scatter function (co group) CoGroupOperator<?, ?, Tuple2<K, Message>> messages; ScatterUdfWithEdgeValues<K, VV, VV, Message, EV> messenger = new ScatterUdfWithEVsSimpleVV<>(scatterFunction, messageTypeInfo); messages = this.edgesWithValue.coGroup(iteration.getWorkset()).where(whereArg) .equalTo(equalToArg).with(messenger); // configure coGroup message function with name and broadcast variables messages = messages.name("Messaging"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getScatterBcastVars()) { messages = messages.withBroadcastSet(e.f1, e.f0); } if (this.configuration.isOptNumVertices()) { messages = messages.withBroadcastSet(numberOfVertices, "number of vertices"); } } return messages; }
Example 2
Source File: ScatterGatherIteration.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Method that builds the scatter function using a coGroup operator for a vertex * containing degree information. * It afterwards configures the function with a custom name and broadcast variables. * * @param iteration * @param messageTypeInfo * @param whereArg the argument for the where within the coGroup * @param equalToArg the argument for the equalTo within the coGroup * @return the scatter function */ private CoGroupOperator<?, ?, Tuple2<K, Message>> buildScatterFunctionVerticesWithDegrees( DeltaIteration<Vertex<K, Tuple3<VV, LongValue, LongValue>>, Vertex<K, Tuple3<VV, LongValue, LongValue>>> iteration, TypeInformation<Tuple2<K, Message>> messageTypeInfo, int whereArg, int equalToArg, DataSet<LongValue> numberOfVertices) { // build the scatter function (co group) CoGroupOperator<?, ?, Tuple2<K, Message>> messages; ScatterUdfWithEdgeValues<K, Tuple3<VV, LongValue, LongValue>, VV, Message, EV> messenger = new ScatterUdfWithEVsVVWithDegrees<>(scatterFunction, messageTypeInfo); messages = this.edgesWithValue.coGroup(iteration.getWorkset()).where(whereArg) .equalTo(equalToArg).with(messenger); // configure coGroup message function with name and broadcast variables messages = messages.name("Messaging"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getScatterBcastVars()) { messages = messages.withBroadcastSet(e.f1, e.f0); } if (this.configuration.isOptNumVertices()) { messages = messages.withBroadcastSet(numberOfVertices, "number of vertices"); } } return messages; }
Example 3
Source File: ScatterGatherIteration.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private <VVWithDegree> void configureUpdateFunction(CoGroupOperator<?, ?, Vertex<K, VVWithDegree>> updates) { // configure coGroup update function with name and broadcast variables updates = updates.name("Vertex State Updates"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getGatherBcastVars()) { updates = updates.withBroadcastSet(e.f1, e.f0); } } // let the operator know that we preserve the key field updates.withForwardedFieldsFirst("0").withForwardedFieldsSecond("0"); }
Example 4
Source File: ScatterGatherIteration.java From flink with Apache License 2.0 | 5 votes |
/** * Method that builds the scatter function using a coGroup operator for a simple vertex (without * degrees). * It afterwards configures the function with a custom name and broadcast variables. * * @param iteration * @param messageTypeInfo * @param whereArg the argument for the where within the coGroup * @param equalToArg the argument for the equalTo within the coGroup * @return the scatter function */ private CoGroupOperator<?, ?, Tuple2<K, Message>> buildScatterFunction( DeltaIteration<Vertex<K, VV>, Vertex<K, VV>> iteration, TypeInformation<Tuple2<K, Message>> messageTypeInfo, int whereArg, int equalToArg, DataSet<LongValue> numberOfVertices) { // build the scatter function (co group) CoGroupOperator<?, ?, Tuple2<K, Message>> messages; ScatterUdfWithEdgeValues<K, VV, VV, Message, EV> messenger = new ScatterUdfWithEVsSimpleVV<>(scatterFunction, messageTypeInfo); messages = this.edgesWithValue.coGroup(iteration.getWorkset()).where(whereArg) .equalTo(equalToArg).with(messenger); // configure coGroup message function with name and broadcast variables messages = messages.name("Messaging"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getScatterBcastVars()) { messages = messages.withBroadcastSet(e.f1, e.f0); } if (this.configuration.isOptNumVertices()) { messages = messages.withBroadcastSet(numberOfVertices, "number of vertices"); } } return messages; }
Example 5
Source File: ScatterGatherIteration.java From flink with Apache License 2.0 | 5 votes |
/** * Method that builds the scatter function using a coGroup operator for a vertex * containing degree information. * It afterwards configures the function with a custom name and broadcast variables. * * @param iteration * @param messageTypeInfo * @param whereArg the argument for the where within the coGroup * @param equalToArg the argument for the equalTo within the coGroup * @return the scatter function */ private CoGroupOperator<?, ?, Tuple2<K, Message>> buildScatterFunctionVerticesWithDegrees( DeltaIteration<Vertex<K, Tuple3<VV, LongValue, LongValue>>, Vertex<K, Tuple3<VV, LongValue, LongValue>>> iteration, TypeInformation<Tuple2<K, Message>> messageTypeInfo, int whereArg, int equalToArg, DataSet<LongValue> numberOfVertices) { // build the scatter function (co group) CoGroupOperator<?, ?, Tuple2<K, Message>> messages; ScatterUdfWithEdgeValues<K, Tuple3<VV, LongValue, LongValue>, VV, Message, EV> messenger = new ScatterUdfWithEVsVVWithDegrees<>(scatterFunction, messageTypeInfo); messages = this.edgesWithValue.coGroup(iteration.getWorkset()).where(whereArg) .equalTo(equalToArg).with(messenger); // configure coGroup message function with name and broadcast variables messages = messages.name("Messaging"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getScatterBcastVars()) { messages = messages.withBroadcastSet(e.f1, e.f0); } if (this.configuration.isOptNumVertices()) { messages = messages.withBroadcastSet(numberOfVertices, "number of vertices"); } } return messages; }
Example 6
Source File: ScatterGatherIteration.java From flink with Apache License 2.0 | 5 votes |
private <VVWithDegree> void configureUpdateFunction(CoGroupOperator<?, ?, Vertex<K, VVWithDegree>> updates) { // configure coGroup update function with name and broadcast variables updates = updates.name("Vertex State Updates"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getGatherBcastVars()) { updates = updates.withBroadcastSet(e.f1, e.f0); } } // let the operator know that we preserve the key field updates.withForwardedFieldsFirst("0").withForwardedFieldsSecond("0"); }
Example 7
Source File: ScatterGatherIteration.java From flink with Apache License 2.0 | 5 votes |
/** * Method that builds the scatter function using a coGroup operator for a simple vertex (without * degrees). * It afterwards configures the function with a custom name and broadcast variables. * * @param iteration * @param messageTypeInfo * @param whereArg the argument for the where within the coGroup * @param equalToArg the argument for the equalTo within the coGroup * @return the scatter function */ private CoGroupOperator<?, ?, Tuple2<K, Message>> buildScatterFunction( DeltaIteration<Vertex<K, VV>, Vertex<K, VV>> iteration, TypeInformation<Tuple2<K, Message>> messageTypeInfo, int whereArg, int equalToArg, DataSet<LongValue> numberOfVertices) { // build the scatter function (co group) CoGroupOperator<?, ?, Tuple2<K, Message>> messages; ScatterUdfWithEdgeValues<K, VV, VV, Message, EV> messenger = new ScatterUdfWithEVsSimpleVV<>(scatterFunction, messageTypeInfo); messages = this.edgesWithValue.coGroup(iteration.getWorkset()).where(whereArg) .equalTo(equalToArg).with(messenger); // configure coGroup message function with name and broadcast variables messages = messages.name("Messaging"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getScatterBcastVars()) { messages = messages.withBroadcastSet(e.f1, e.f0); } if (this.configuration.isOptNumVertices()) { messages = messages.withBroadcastSet(numberOfVertices, "number of vertices"); } } return messages; }
Example 8
Source File: ScatterGatherIteration.java From flink with Apache License 2.0 | 5 votes |
/** * Method that builds the scatter function using a coGroup operator for a vertex * containing degree information. * It afterwards configures the function with a custom name and broadcast variables. * * @param iteration * @param messageTypeInfo * @param whereArg the argument for the where within the coGroup * @param equalToArg the argument for the equalTo within the coGroup * @return the scatter function */ private CoGroupOperator<?, ?, Tuple2<K, Message>> buildScatterFunctionVerticesWithDegrees( DeltaIteration<Vertex<K, Tuple3<VV, LongValue, LongValue>>, Vertex<K, Tuple3<VV, LongValue, LongValue>>> iteration, TypeInformation<Tuple2<K, Message>> messageTypeInfo, int whereArg, int equalToArg, DataSet<LongValue> numberOfVertices) { // build the scatter function (co group) CoGroupOperator<?, ?, Tuple2<K, Message>> messages; ScatterUdfWithEdgeValues<K, Tuple3<VV, LongValue, LongValue>, VV, Message, EV> messenger = new ScatterUdfWithEVsVVWithDegrees<>(scatterFunction, messageTypeInfo); messages = this.edgesWithValue.coGroup(iteration.getWorkset()).where(whereArg) .equalTo(equalToArg).with(messenger); // configure coGroup message function with name and broadcast variables messages = messages.name("Messaging"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getScatterBcastVars()) { messages = messages.withBroadcastSet(e.f1, e.f0); } if (this.configuration.isOptNumVertices()) { messages = messages.withBroadcastSet(numberOfVertices, "number of vertices"); } } return messages; }
Example 9
Source File: ScatterGatherIteration.java From flink with Apache License 2.0 | 5 votes |
private <VVWithDegree> void configureUpdateFunction(CoGroupOperator<?, ?, Vertex<K, VVWithDegree>> updates) { // configure coGroup update function with name and broadcast variables updates = updates.name("Vertex State Updates"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getGatherBcastVars()) { updates = updates.withBroadcastSet(e.f1, e.f0); } } // let the operator know that we preserve the key field updates.withForwardedFieldsFirst("0").withForwardedFieldsSecond("0"); }
Example 10
Source File: VertexCentricIteration.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Creates the operator that represents this vertex-centric graph computation. * * <p>The Pregel iteration is mapped to delta iteration as follows. * The solution set consists of the set of active vertices and the workset contains the set of messages * send to vertices during the previous superstep. Initially, the workset contains a null message for each vertex. * In the beginning of a superstep, the solution set is joined with the workset to produce * a dataset containing tuples of vertex state and messages (vertex inbox). * The superstep compute UDF is realized with a coGroup between the vertices with inbox and the graph edges. * The output of the compute UDF contains both the new vertex values and the new messages produced. * These are directed to the solution set delta and new workset, respectively, with subsequent flatMaps. * * @return The operator that represents this vertex-centric graph computation. */ @Override public DataSet<Vertex<K, VV>> createResult() { if (this.initialVertices == null) { throw new IllegalStateException("The input data set has not been set."); } // prepare the type information TypeInformation<K> keyType = ((TupleTypeInfo<?>) initialVertices.getType()).getTypeAt(0); TypeInformation<Tuple2<K, Message>> messageTypeInfo = new TupleTypeInfo<>(keyType, messageType); TypeInformation<Vertex<K, VV>> vertexType = initialVertices.getType(); TypeInformation<Either<Vertex<K, VV>, Tuple2<K, Message>>> intermediateTypeInfo = new EitherTypeInfo<>(vertexType, messageTypeInfo); TypeInformation<Either<NullValue, Message>> nullableMsgTypeInfo = new EitherTypeInfo<>(TypeExtractor.getForClass(NullValue.class), messageType); TypeInformation<Tuple2<K, Either<NullValue, Message>>> workSetTypeInfo = new TupleTypeInfo<>(keyType, nullableMsgTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> initialWorkSet = initialVertices.map( new InitializeWorkSet<K, VV, Message>()).returns(workSetTypeInfo); final DeltaIteration<Vertex<K, VV>, Tuple2<K, Either<NullValue, Message>>> iteration = initialVertices.iterateDelta(initialWorkSet, this.maximumNumberOfIterations, 0); setUpIteration(iteration); // join with the current state to get vertex values DataSet<Tuple2<Vertex<K, VV>, Either<NullValue, Message>>> verticesWithMsgs = iteration.getSolutionSet().join(iteration.getWorkset()) .where(0).equalTo(0) .with(new AppendVertexState<>()) .returns(new TupleTypeInfo<>( vertexType, nullableMsgTypeInfo)); VertexComputeUdf<K, VV, EV, Message> vertexUdf = new VertexComputeUdf<>(computeFunction, intermediateTypeInfo); CoGroupOperator<?, ?, Either<Vertex<K, VV>, Tuple2<K, Message>>> superstepComputation = verticesWithMsgs.coGroup(edgesWithValue) .where("f0.f0").equalTo(0) .with(vertexUdf); // compute the solution set delta DataSet<Vertex<K, VV>> solutionSetDelta = superstepComputation.flatMap( new ProjectNewVertexValue<>()).returns(vertexType); // compute the inbox of each vertex for the next superstep (new workset) DataSet<Tuple2<K, Either<NullValue, Message>>> allMessages = superstepComputation.flatMap( new ProjectMessages<>()).returns(workSetTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> newWorkSet = allMessages; // check if a combiner has been provided if (combineFunction != null) { MessageCombinerUdf<K, Message> combinerUdf = new MessageCombinerUdf<>(combineFunction, workSetTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> combinedMessages = allMessages .groupBy(0).reduceGroup(combinerUdf) .setCombinable(true); newWorkSet = combinedMessages; } // configure the compute function superstepComputation = superstepComputation.name("Compute Function"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getBcastVars()) { superstepComputation = superstepComputation.withBroadcastSet(e.f1, e.f0); } } return iteration.closeWith(solutionSetDelta, newWorkSet); }
Example 11
Source File: VertexCentricIteration.java From flink with Apache License 2.0 | 4 votes |
/** * Creates the operator that represents this vertex-centric graph computation. * * <p>The Pregel iteration is mapped to delta iteration as follows. * The solution set consists of the set of active vertices and the workset contains the set of messages * send to vertices during the previous superstep. Initially, the workset contains a null message for each vertex. * In the beginning of a superstep, the solution set is joined with the workset to produce * a dataset containing tuples of vertex state and messages (vertex inbox). * The superstep compute UDF is realized with a coGroup between the vertices with inbox and the graph edges. * The output of the compute UDF contains both the new vertex values and the new messages produced. * These are directed to the solution set delta and new workset, respectively, with subsequent flatMaps. * * @return The operator that represents this vertex-centric graph computation. */ @Override public DataSet<Vertex<K, VV>> createResult() { if (this.initialVertices == null) { throw new IllegalStateException("The input data set has not been set."); } // prepare the type information TypeInformation<K> keyType = ((TupleTypeInfo<?>) initialVertices.getType()).getTypeAt(0); TypeInformation<Tuple2<K, Message>> messageTypeInfo = new TupleTypeInfo<>(keyType, messageType); TypeInformation<Vertex<K, VV>> vertexType = initialVertices.getType(); TypeInformation<Either<Vertex<K, VV>, Tuple2<K, Message>>> intermediateTypeInfo = new EitherTypeInfo<>(vertexType, messageTypeInfo); TypeInformation<Either<NullValue, Message>> nullableMsgTypeInfo = new EitherTypeInfo<>(TypeExtractor.getForClass(NullValue.class), messageType); TypeInformation<Tuple2<K, Either<NullValue, Message>>> workSetTypeInfo = new TupleTypeInfo<>(keyType, nullableMsgTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> initialWorkSet = initialVertices.map( new InitializeWorkSet<K, VV, Message>()).returns(workSetTypeInfo); final DeltaIteration<Vertex<K, VV>, Tuple2<K, Either<NullValue, Message>>> iteration = initialVertices.iterateDelta(initialWorkSet, this.maximumNumberOfIterations, 0); setUpIteration(iteration); // join with the current state to get vertex values DataSet<Tuple2<Vertex<K, VV>, Either<NullValue, Message>>> verticesWithMsgs = iteration.getSolutionSet().join(iteration.getWorkset()) .where(0).equalTo(0) .with(new AppendVertexState<>()) .returns(new TupleTypeInfo<>( vertexType, nullableMsgTypeInfo)); VertexComputeUdf<K, VV, EV, Message> vertexUdf = new VertexComputeUdf<>(computeFunction, intermediateTypeInfo); CoGroupOperator<?, ?, Either<Vertex<K, VV>, Tuple2<K, Message>>> superstepComputation = verticesWithMsgs.coGroup(edgesWithValue) .where("f0.f0").equalTo(0) .with(vertexUdf); // compute the solution set delta DataSet<Vertex<K, VV>> solutionSetDelta = superstepComputation.flatMap( new ProjectNewVertexValue<>()).returns(vertexType); // compute the inbox of each vertex for the next superstep (new workset) DataSet<Tuple2<K, Either<NullValue, Message>>> allMessages = superstepComputation.flatMap( new ProjectMessages<>()).returns(workSetTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> newWorkSet = allMessages; // check if a combiner has been provided if (combineFunction != null) { MessageCombinerUdf<K, Message> combinerUdf = new MessageCombinerUdf<>(combineFunction, workSetTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> combinedMessages = allMessages .groupBy(0).reduceGroup(combinerUdf) .setCombinable(true); newWorkSet = combinedMessages; } // configure the compute function superstepComputation = superstepComputation.name("Compute Function"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getBcastVars()) { superstepComputation = superstepComputation.withBroadcastSet(e.f1, e.f0); } } return iteration.closeWith(solutionSetDelta, newWorkSet); }
Example 12
Source File: VertexCentricIteration.java From flink with Apache License 2.0 | 4 votes |
/** * Creates the operator that represents this vertex-centric graph computation. * * <p>The Pregel iteration is mapped to delta iteration as follows. * The solution set consists of the set of active vertices and the workset contains the set of messages * send to vertices during the previous superstep. Initially, the workset contains a null message for each vertex. * In the beginning of a superstep, the solution set is joined with the workset to produce * a dataset containing tuples of vertex state and messages (vertex inbox). * The superstep compute UDF is realized with a coGroup between the vertices with inbox and the graph edges. * The output of the compute UDF contains both the new vertex values and the new messages produced. * These are directed to the solution set delta and new workset, respectively, with subsequent flatMaps. * * @return The operator that represents this vertex-centric graph computation. */ @Override public DataSet<Vertex<K, VV>> createResult() { if (this.initialVertices == null) { throw new IllegalStateException("The input data set has not been set."); } // prepare the type information TypeInformation<K> keyType = ((TupleTypeInfo<?>) initialVertices.getType()).getTypeAt(0); TypeInformation<Tuple2<K, Message>> messageTypeInfo = new TupleTypeInfo<>(keyType, messageType); TypeInformation<Vertex<K, VV>> vertexType = initialVertices.getType(); TypeInformation<Either<Vertex<K, VV>, Tuple2<K, Message>>> intermediateTypeInfo = new EitherTypeInfo<>(vertexType, messageTypeInfo); TypeInformation<Either<NullValue, Message>> nullableMsgTypeInfo = new EitherTypeInfo<>(TypeExtractor.getForClass(NullValue.class), messageType); TypeInformation<Tuple2<K, Either<NullValue, Message>>> workSetTypeInfo = new TupleTypeInfo<>(keyType, nullableMsgTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> initialWorkSet = initialVertices.map( new InitializeWorkSet<K, VV, Message>()).returns(workSetTypeInfo); final DeltaIteration<Vertex<K, VV>, Tuple2<K, Either<NullValue, Message>>> iteration = initialVertices.iterateDelta(initialWorkSet, this.maximumNumberOfIterations, 0); setUpIteration(iteration); // join with the current state to get vertex values DataSet<Tuple2<Vertex<K, VV>, Either<NullValue, Message>>> verticesWithMsgs = iteration.getSolutionSet().join(iteration.getWorkset()) .where(0).equalTo(0) .with(new AppendVertexState<>()) .returns(new TupleTypeInfo<>( vertexType, nullableMsgTypeInfo)); VertexComputeUdf<K, VV, EV, Message> vertexUdf = new VertexComputeUdf<>(computeFunction, intermediateTypeInfo); CoGroupOperator<?, ?, Either<Vertex<K, VV>, Tuple2<K, Message>>> superstepComputation = verticesWithMsgs.coGroup(edgesWithValue) .where("f0.f0").equalTo(0) .with(vertexUdf); // compute the solution set delta DataSet<Vertex<K, VV>> solutionSetDelta = superstepComputation.flatMap( new ProjectNewVertexValue<>()).returns(vertexType); // compute the inbox of each vertex for the next superstep (new workset) DataSet<Tuple2<K, Either<NullValue, Message>>> allMessages = superstepComputation.flatMap( new ProjectMessages<>()).returns(workSetTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> newWorkSet = allMessages; // check if a combiner has been provided if (combineFunction != null) { MessageCombinerUdf<K, Message> combinerUdf = new MessageCombinerUdf<>(combineFunction, workSetTypeInfo); DataSet<Tuple2<K, Either<NullValue, Message>>> combinedMessages = allMessages .groupBy(0).reduceGroup(combinerUdf) .setCombinable(true); newWorkSet = combinedMessages; } // configure the compute function superstepComputation = superstepComputation.name("Compute Function"); if (this.configuration != null) { for (Tuple2<String, DataSet<?>> e : this.configuration.getBcastVars()) { superstepComputation = superstepComputation.withBroadcastSet(e.f1, e.f0); } } return iteration.closeWith(solutionSetDelta, newWorkSet); }