5454
5555 private final Map <String , JobNode > nodes = new HashMap <>();
5656 private final Map <String , StreamEdge > edges = new HashMap <>();
57- private final Set <StreamEdge > sources = new HashSet <>();
58- private final Set <StreamEdge > sinks = new HashSet <>();
57+ private final Set <StreamEdge > inputStreams = new HashSet <>();
58+ private final Set <StreamEdge > outputStreams = new HashSet <>();
5959 private final Set <StreamEdge > intermediateStreams = new HashSet <>();
6060 private final Set <TableSpec > tables = new HashSet <>();
6161 private final Config config ;
@@ -115,26 +115,26 @@ public OperatorSpecGraph getSpecGraph() {
115115
116116 /**
117117 * Add a source stream to a {@link JobNode}
118- * @param input source stream
119- * @param node the job node that consumes from the source
118+ * @param streamSpec input stream
119+ * @param node the job node that consumes from the streamSpec
120120 */
121- void addSource (StreamSpec input , JobNode node ) {
122- StreamEdge edge = getOrCreateStreamEdge (input );
121+ void addInputStream (StreamSpec streamSpec , JobNode node ) {
122+ StreamEdge edge = getOrCreateStreamEdge (streamSpec );
123123 edge .addTargetNode (node );
124124 node .addInEdge (edge );
125- sources .add (edge );
125+ inputStreams .add (edge );
126126 }
127127
128128 /**
129- * Add a sink stream to a {@link JobNode}
130- * @param output sink stream
131- * @param node the job node that outputs to the sink
129+ * Add an output stream to a {@link JobNode}
130+ * @param streamSpec output stream
131+ * @param node the job node that outputs to the output stream
132132 */
133- void addSink (StreamSpec output , JobNode node ) {
134- StreamEdge edge = getOrCreateStreamEdge (output );
133+ void addOutputStream (StreamSpec streamSpec , JobNode node ) {
134+ StreamEdge edge = getOrCreateStreamEdge (streamSpec );
135135 edge .addSourceNode (node );
136136 node .addOutEdge (edge );
137- sinks .add (edge );
137+ outputStreams .add (edge );
138138 }
139139
140140 /**
@@ -204,19 +204,19 @@ List<JobNode> getJobNodes() {
204204 }
205205
206206 /**
207- * Returns the source streams in the graph
207+ * Returns the input streams in the graph
208208 * @return unmodifiable set of {@link StreamEdge}
209209 */
210- Set <StreamEdge > getSources () {
211- return Collections .unmodifiableSet (sources );
210+ Set <StreamEdge > getInputStreams () {
211+ return Collections .unmodifiableSet (inputStreams );
212212 }
213213
214214 /**
215- * Return the sink streams in the graph
215+ * Return the output streams in the graph
216216 * @return unmodifiable set of {@link StreamEdge}
217217 */
218- Set <StreamEdge > getSinks () {
219- return Collections .unmodifiableSet (sinks );
218+ Set <StreamEdge > getOutputStreams () {
219+ return Collections .unmodifiableSet (outputStreams );
220220 }
221221
222222 /**
@@ -236,22 +236,22 @@ Set<StreamEdge> getIntermediateStreamEdges() {
236236 }
237237
238238 /**
239- * Validate the graph has the correct topology, meaning the sources are coming from external streams,
240- * sinks are going to external streams, and the nodes are connected with intermediate streams.
241- * Also validate all the nodes are reachable from the sources .
239+ * Validate the graph has the correct topology, meaning the input streams are coming from external streams,
240+ * output streams are going to external streams, and the nodes are connected with intermediate streams.
241+ * Also validate all the nodes are reachable from the input streams .
242242 */
243243 void validate () {
244- validateSources ();
245- validateSinks ();
244+ validateInputStreams ();
245+ validateOutputStreams ();
246246 validateInternalStreams ();
247247 validateReachability ();
248248 }
249249
250250 /**
251- * Validate the sources should have indegree being 0 and outdegree greater than 0
251+ * Validate the input streams should have indegree being 0 and outdegree greater than 0
252252 */
253- private void validateSources () {
254- sources .forEach (edge -> {
253+ private void validateInputStreams () {
254+ inputStreams .forEach (edge -> {
255255 if (!edge .getSourceNodes ().isEmpty ()) {
256256 throw new IllegalArgumentException (
257257 String .format ("Source stream %s should not have producers." , edge .getName ()));
@@ -264,10 +264,10 @@ private void validateSources() {
264264 }
265265
266266 /**
267- * Validate the sinks should have outdegree being 0 and indegree greater than 0
267+ * Validate the output streams should have outdegree being 0 and indegree greater than 0
268268 */
269- private void validateSinks () {
270- sinks .forEach (edge -> {
269+ private void validateOutputStreams () {
270+ outputStreams .forEach (edge -> {
271271 if (!edge .getTargetNodes ().isEmpty ()) {
272272 throw new IllegalArgumentException (
273273 String .format ("Sink stream %s should not have consumers" , edge .getName ()));
@@ -284,8 +284,8 @@ private void validateSinks() {
284284 */
285285 private void validateInternalStreams () {
286286 Set <StreamEdge > internalEdges = new HashSet <>(edges .values ());
287- internalEdges .removeAll (sources );
288- internalEdges .removeAll (sinks );
287+ internalEdges .removeAll (inputStreams );
288+ internalEdges .removeAll (outputStreams );
289289
290290 internalEdges .forEach (edge -> {
291291 if (edge .getSourceNodes ().isEmpty () || edge .getTargetNodes ().isEmpty ()) {
@@ -296,10 +296,10 @@ private void validateInternalStreams() {
296296 }
297297
298298 /**
299- * Validate all nodes are reachable by sources .
299+ * Validate all nodes are reachable by input streams .
300300 */
301301 private void validateReachability () {
302- // validate all nodes are reachable from the sources
302+ // validate all nodes are reachable from the input streams
303303 final Set <JobNode > reachable = findReachable ();
304304 if (reachable .size () != nodes .size ()) {
305305 Set <JobNode > unreachable = new HashSet <>(nodes .values ());
@@ -317,8 +317,8 @@ Set<JobNode> findReachable() {
317317 Queue <JobNode > queue = new ArrayDeque <>();
318318 Set <JobNode > visited = new HashSet <>();
319319
320- sources .forEach (source -> {
321- List <JobNode > next = source .getTargetNodes ();
320+ inputStreams .forEach (input -> {
321+ List <JobNode > next = input .getTargetNodes ();
322322 queue .addAll (next );
323323 visited .addAll (next );
324324 });
@@ -353,11 +353,11 @@ List<JobNode> topologicalSort() {
353353 pnodes .forEach (node -> {
354354 String nid = node .getId ();
355355 //only count the degrees of intermediate streams
356- long degree = node .getInEdges ().stream ().filter (e -> !sources .contains (e )).count ();
356+ long degree = node .getInEdges ().stream ().filter (e -> !inputStreams .contains (e )).count ();
357357 indegree .put (nid , degree );
358358
359359 if (degree == 0L ) {
360- // start from the nodes that has no intermediate input streams, so it only consumes from sources
360+ // start from the nodes that has no intermediate input streams, so it only consumes from input streams
361361 q .add (node );
362362 visited .add (node );
363363 }
@@ -410,9 +410,9 @@ List<JobNode> topologicalSort() {
410410 q .add (minNode );
411411 visited .add (minNode );
412412 } else {
413- // all the remaining nodes should be reachable from sources
414- // start from sources again to find the next node that hasn't been visited
415- JobNode nextNode = sources .stream ().flatMap (source -> source .getTargetNodes ().stream ())
413+ // all the remaining nodes should be reachable from input streams
414+ // start from input streams again to find the next node that hasn't been visited
415+ JobNode nextNode = inputStreams .stream ().flatMap (input -> input .getTargetNodes ().stream ())
416416 .filter (node -> !visited .contains (node ))
417417 .findAny ().get ();
418418 q .add (nextNode );
0 commit comments