KevinGG commented on a change in pull request #13277: URL: https://github.com/apache/beam/pull/13277#discussion_r519030688
########## File path: sdks/python/apache_beam/runners/interactive/derivation_tree.py ########## @@ -0,0 +1,136 @@ +# +# 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. +# + +"""Class that tracks derived/pipeline fragments from user pipelines. + +For internal use only; no backwards-compatibility guarantees. +In the InteractiveRunner the design is to keep the user pipeline unchanged, +create a copy of the user pipeline, and modify the copy. When the derived +pipeline runs, there should only be per-user pipeline state. This makes sure +that derived pipelines can link back to the parent user pipeline. +""" +# pytype: skip-file + + +class DerivationTree: + """Tracks which pipelines are derived from user pipelines. + + This data structure is similar to a disjoint set data structure. A derived + pipeline can only have one parent user pipeline. A user pipeline can have many + derived pipelines. + """ + class Node: + """Object to track the relationship between user to derived pipelines.""" + def __init__(self): + self.user_pipeline = None + self.derived_pipelines = set() + + def __init__(self): + self._tree = {} + self._pid_to_pipelines = {} + + def __iter__(self): + """Iterates through all the user pipelines.""" + for n in self._tree.values(): + yield n.user_pipeline + + def _key(self, pipeline): + return str(id(pipeline)) + + def clear(self): + """Clears the tree of all user and derived pipelines.""" + self._tree.clear() + + def get_pipeline(self, pid): + """Returns the pipeline corresponding to the given pipeline id.""" + if pid in self._pid_to_pipelines: + return self._pid_to_pipelines[pid] + return None + + def add_user_pipeline(self, p): + """Adds a user pipeline with an empty set of derived pipelines.""" + self._memoize_pipieline(p) Review comment: Nit: should it be `memorize`? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
