You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/01/31 19:01:57 UTC

[GitHub] [flink-statefun-playground] tillrohrmann opened a new pull request #19: [FLINK-25899] Add connected components example

tillrohrmann opened a new pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19


   This PR adds an example for calculating the connected components using Stateful Functions.
   
   This PR needs to be ported to `dev` and `release-3.2`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-statefun-playground] tillrohrmann commented on a change in pull request #19: [FLINK-25899] Add connected components example

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19#discussion_r797656588



##########
File path: java/connected-components/src/main/java/org/apache/flink/statefun/playground/java/connectedcomponents/ConnectedComponentsFn.java
##########
@@ -0,0 +1,133 @@
+package org.apache.flink.statefun.playground.java.connectedcomponents;
+
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.Types;
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.Vertex;
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.generated.VertexComponentChange;
+import org.apache.flink.statefun.sdk.java.Context;
+import org.apache.flink.statefun.sdk.java.StatefulFunction;
+import org.apache.flink.statefun.sdk.java.StatefulFunctionSpec;
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.ValueSpec;
+import org.apache.flink.statefun.sdk.java.io.KafkaEgressMessage;
+import org.apache.flink.statefun.sdk.java.message.Message;
+import org.apache.flink.statefun.sdk.java.message.MessageBuilder;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * A stateful function that computes the connected component for a stream of vertices.

Review comment:
       I think this is a good idea. Will dig some link up.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-statefun-playground] tillrohrmann commented on pull request #19: [FLINK-25899] Add connected components example

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19#issuecomment-1028237525


   Thanks for the review @igalshilman. I've addressed your comments and pushed an update. Merging this PR now into `release-3.1`, `release-3.2` and `dev`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-statefun-playground] tillrohrmann merged pull request #19: [FLINK-25899] Add connected components example

Posted by GitBox <gi...@apache.org>.
tillrohrmann merged pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-statefun-playground] igalshilman commented on a change in pull request #19: [FLINK-25899] Add connected components example

Posted by GitBox <gi...@apache.org>.
igalshilman commented on a change in pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19#discussion_r796789576



##########
File path: java/connected-components/src/main/java/org/apache/flink/statefun/playground/java/connectedcomponents/types/JavaType.java
##########
@@ -0,0 +1,70 @@
+package org.apache.flink.statefun.playground.java.connectedcomponents.types;
+
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.slice.Slice;
+import org.apache.flink.statefun.sdk.java.slice.Slices;
+import org.apache.flink.statefun.sdk.java.types.Type;
+import org.apache.flink.statefun.sdk.java.types.TypeCharacteristics;
+import org.apache.flink.statefun.sdk.java.types.TypeSerializer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+
+/**
+ * Simple type that uses Java serialization to serialize values.
+ *
+ * @param <T> type to hold
+ */
+final class JavaType<T> implements Type<T> {
+    private static final JavaSerializer INSTANCE = new JavaSerializer();
+    private final TypeName typeName;
+
+    JavaType(TypeName typeName) {
+        this.typeName = typeName;
+    }
+
+    @Override
+    public TypeName typeName() {
+        return typeName;
+    }
+
+    @Override
+    public TypeSerializer<T> typeSerializer() {
+        return INSTANCE;
+    }
+
+    @Override
+    public Set<TypeCharacteristics> typeCharacteristics() {
+        return Collections.unmodifiableSet(EnumSet.of(TypeCharacteristics.IMMUTABLE_VALUES));
+    }
+
+    private static final class JavaSerializer<T> implements TypeSerializer<T> {
+        @Override
+        public Slice serialize(T value) {
+            final ByteArrayOutputStream baos = new ByteArrayOutputStream();

Review comment:
       @tillrohrmann, I'm a bit reluctant of having Java serialization here as an example, because we've learned that whatever we put in the examples folks tend to copy as-is. 
   I've seen that you are using `Jackson` at `Types` do you mind using this instead?
   
   I think that you can use the `ObjectMapper` to serialize and deserialize the set directly.
   
   

##########
File path: java/connected-components/src/main/java/org/apache/flink/statefun/playground/java/connectedcomponents/types/Types.java
##########
@@ -0,0 +1,38 @@
+package org.apache.flink.statefun.playground.java.connectedcomponents.types;
+
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.generated.VertexComponentChange;
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.types.SimpleType;
+import org.apache.flink.statefun.sdk.java.types.Type;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Set;
+
+public final class Types {
+
+  private Types() {}
+
+  private static final ObjectMapper JSON_OBJ_MAPPER = new ObjectMapper();
+  private static final String TYPES_NAMESPACE = "connected-components.types";
+
+  /**
+   * Type denoting a new vertex coming from the input source.
+   */
+  public static final Type<Vertex> VERTEX_INIT_TYPE =
+      SimpleType.simpleImmutableTypeFrom(
+          TypeName.typeNameOf(TYPES_NAMESPACE, Vertex.class.getName()),

Review comment:
       I think that we shouldn't encourage using `class.getName()` as this can be bit fragile if the Vertex class moves to a different package.
   How about using a logical name like `vertex`?

##########
File path: java/connected-components/src/main/protobuf/messages.proto
##########
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+package org.apache.flink.statefun.playground.java.connectedcomponents.types;
+
+option java_package = "org.apache.flink.statefun.playground.java.connectedcomponents.types.generated";
+option java_multiple_files = true;
+
+message VertexComponentChange {

Review comment:
       I think that we can get away without Protobuf here, it seems like you are already using JSON, what do you think about simplifying this a bit (and removing the protobuf dependency altogether) ?

##########
File path: java/connected-components/src/main/java/org/apache/flink/statefun/playground/java/connectedcomponents/ConnectedComponentsFn.java
##########
@@ -0,0 +1,133 @@
+package org.apache.flink.statefun.playground.java.connectedcomponents;
+
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.Types;
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.Vertex;
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.generated.VertexComponentChange;
+import org.apache.flink.statefun.sdk.java.Context;
+import org.apache.flink.statefun.sdk.java.StatefulFunction;
+import org.apache.flink.statefun.sdk.java.StatefulFunctionSpec;
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.ValueSpec;
+import org.apache.flink.statefun.sdk.java.io.KafkaEgressMessage;
+import org.apache.flink.statefun.sdk.java.message.Message;
+import org.apache.flink.statefun.sdk.java.message.MessageBuilder;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * A stateful function that computes the connected component for a stream of vertices.

Review comment:
       👍 really nice that you have added the algorithm description!
   Do you think that folks might find it useful if you will add a link to the algorithm, or cite it's name?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-statefun-playground] tillrohrmann commented on a change in pull request #19: [FLINK-25899] Add connected components example

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19#discussion_r797654985



##########
File path: java/connected-components/src/main/java/org/apache/flink/statefun/playground/java/connectedcomponents/types/JavaType.java
##########
@@ -0,0 +1,70 @@
+package org.apache.flink.statefun.playground.java.connectedcomponents.types;
+
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.slice.Slice;
+import org.apache.flink.statefun.sdk.java.slice.Slices;
+import org.apache.flink.statefun.sdk.java.types.Type;
+import org.apache.flink.statefun.sdk.java.types.TypeCharacteristics;
+import org.apache.flink.statefun.sdk.java.types.TypeSerializer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+
+/**
+ * Simple type that uses Java serialization to serialize values.
+ *
+ * @param <T> type to hold
+ */
+final class JavaType<T> implements Type<T> {
+    private static final JavaSerializer INSTANCE = new JavaSerializer();
+    private final TypeName typeName;
+
+    JavaType(TypeName typeName) {
+        this.typeName = typeName;
+    }
+
+    @Override
+    public TypeName typeName() {
+        return typeName;
+    }
+
+    @Override
+    public TypeSerializer<T> typeSerializer() {
+        return INSTANCE;
+    }
+
+    @Override
+    public Set<TypeCharacteristics> typeCharacteristics() {
+        return Collections.unmodifiableSet(EnumSet.of(TypeCharacteristics.IMMUTABLE_VALUES));
+    }
+
+    private static final class JavaSerializer<T> implements TypeSerializer<T> {
+        @Override
+        public Slice serialize(T value) {
+            final ByteArrayOutputStream baos = new ByteArrayOutputStream();

Review comment:
       Sounds good. Let's not give a wrong example. I'll remove the Java serialization.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-statefun-playground] tillrohrmann commented on a change in pull request #19: [FLINK-25899] Add connected components example

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19#discussion_r797655473



##########
File path: java/connected-components/src/main/protobuf/messages.proto
##########
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+package org.apache.flink.statefun.playground.java.connectedcomponents.types;
+
+option java_package = "org.apache.flink.statefun.playground.java.connectedcomponents.types.generated";
+option java_multiple_files = true;
+
+message VertexComponentChange {

Review comment:
       I think this makes a lot of sense. I will remove the protobuf dependency.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-statefun-playground] tillrohrmann commented on a change in pull request #19: [FLINK-25899] Add connected components example

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #19:
URL: https://github.com/apache/flink-statefun-playground/pull/19#discussion_r797656048



##########
File path: java/connected-components/src/main/java/org/apache/flink/statefun/playground/java/connectedcomponents/types/Types.java
##########
@@ -0,0 +1,38 @@
+package org.apache.flink.statefun.playground.java.connectedcomponents.types;
+
+import org.apache.flink.statefun.playground.java.connectedcomponents.types.generated.VertexComponentChange;
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.types.SimpleType;
+import org.apache.flink.statefun.sdk.java.types.Type;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Set;
+
+public final class Types {
+
+  private Types() {}
+
+  private static final ObjectMapper JSON_OBJ_MAPPER = new ObjectMapper();
+  private static final String TYPES_NAMESPACE = "connected-components.types";
+
+  /**
+   * Type denoting a new vertex coming from the input source.
+   */
+  public static final Type<Vertex> VERTEX_INIT_TYPE =
+      SimpleType.simpleImmutableTypeFrom(
+          TypeName.typeNameOf(TYPES_NAMESPACE, Vertex.class.getName()),

Review comment:
       True. Yes, will use a string constant.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org