KarmaGYZ commented on code in PR #23626:
URL: https://github.com/apache/flink/pull/23626#discussion_r1377416733


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/lineage/DefaultLineageGraph.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.streaming.api.lineage;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/** Default implementation for {@link LineageGraph}. */
+public class DefaultLineageGraph implements LineageGraph {
+    private final List<LineageEdge> lineageEdges;
+    private final List<SourceLineageVertex> sources;
+    private final List<LineageVertex> sinks;
+
+    private DefaultLineageGraph(List<LineageEdge> lineageEdges) {
+        this.lineageEdges = lineageEdges;
+
+        Set<SourceLineageVertex> srcs = new HashSet<>();
+        Set<LineageVertex> targets = new HashSet<>();
+        for (LineageEdge lineageEdge : lineageEdges) {
+            srcs.add(lineageEdge.source());
+            targets.add(lineageEdge.sink());
+        }
+        this.sources = new ArrayList<>(srcs);
+        this.sinks = new ArrayList<>(targets);
+    }
+
+    @Override
+    public List<SourceLineageVertex> sources() {
+        return sources;
+    }
+
+    @Override
+    public List<LineageVertex> sinks() {
+        return sinks;
+    }
+
+    @Override
+    public List<LineageEdge> relations() {
+        return lineageEdges;
+    }

Review Comment:
   If these should not be changed outside, we may use 
`Collections.unmodifiableList` to guard them.



##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/api/lineage/LineageGraphTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.streaming.api.lineage;
+
+import org.apache.flink.api.connector.source.Boundedness;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Testing for lineage graph. */
+class LineageGraphTest {

Review Comment:
   ```suggestion
   class DefaultLineageGraphTest {
   ```



##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/api/lineage/LineageGraphTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.streaming.api.lineage;
+
+import org.apache.flink.api.connector.source.Boundedness;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Testing for lineage graph. */
+class LineageGraphTest {
+    @Test
+    void testLineageGraph() {
+        SourceLineageVertex source1 = new 
TestingSourceLineageVertex("source1");
+        SourceLineageVertex source2 = new 
TestingSourceLineageVertex("source2");
+        SourceLineageVertex source3 = new 
TestingSourceLineageVertex("source3");
+        LineageVertex sink1 = new TestingLineageVertex("sink1");
+        LineageVertex sink2 = new TestingLineageVertex("sink2");
+        LineageGraph lineageGraph =
+                DefaultLineageGraph.builder()
+                        .addLineageEdge(new TestingLineageEdge(source1, sink1))
+                        .addLineageEdges(
+                                new TestingLineageEdge(source2, sink2),
+                                new TestingLineageEdge(source3, sink1),
+                                new TestingLineageEdge(source1, sink2))
+                        .build();
+        assertThat(lineageGraph.sources()).isEqualTo(Arrays.asList(source1, 
source2, source3));
+        assertThat(lineageGraph.sinks()).isEqualTo(Arrays.asList(sink1, 
sink2));

Review Comment:
   ```suggestion
           assertThat(lineageGraph.sinks()).containsExactlyInAnyOrder(sink1, 
sink2);
   ```



##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/api/lineage/LineageGraphTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.streaming.api.lineage;
+
+import org.apache.flink.api.connector.source.Boundedness;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Testing for lineage graph. */
+class LineageGraphTest {
+    @Test
+    void testLineageGraph() {
+        SourceLineageVertex source1 = new 
TestingSourceLineageVertex("source1");
+        SourceLineageVertex source2 = new 
TestingSourceLineageVertex("source2");
+        SourceLineageVertex source3 = new 
TestingSourceLineageVertex("source3");
+        LineageVertex sink1 = new TestingLineageVertex("sink1");
+        LineageVertex sink2 = new TestingLineageVertex("sink2");
+        LineageGraph lineageGraph =
+                DefaultLineageGraph.builder()
+                        .addLineageEdge(new TestingLineageEdge(source1, sink1))
+                        .addLineageEdges(
+                                new TestingLineageEdge(source2, sink2),
+                                new TestingLineageEdge(source3, sink1),
+                                new TestingLineageEdge(source1, sink2))
+                        .build();
+        assertThat(lineageGraph.sources()).isEqualTo(Arrays.asList(source1, 
source2, source3));

Review Comment:
   ```suggestion
           
assertThat(lineageGraph.sources()).containsExactlyInAnyOrder(source1, source2, 
source3);
   ```



-- 
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-unsubscr...@flink.apache.org

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

Reply via email to