github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/runners/direct/util.py (about) 1 # 2 # Licensed to the Apache Software Foundation (ASF) under one or more 3 # contributor license agreements. See the NOTICE file distributed with 4 # this work for additional information regarding copyright ownership. 5 # The ASF licenses this file to You under the Apache License, Version 2.0 6 # (the "License"); you may not use this file except in compliance with 7 # the License. You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 """Utility classes used by the DirectRunner. 19 20 For internal use only. No backwards compatibility guarantees. 21 """ 22 23 # pytype: skip-file 24 25 26 class TransformResult(object): 27 """Result of evaluating an AppliedPTransform with a TransformEvaluator.""" 28 def __init__( 29 self, 30 transform_evaluator, 31 uncommitted_output_bundles, 32 unprocessed_bundles, 33 counters, 34 keyed_watermark_holds, 35 undeclared_tag_values=None): 36 self.transform = transform_evaluator._applied_ptransform 37 self.uncommitted_output_bundles = uncommitted_output_bundles 38 self.unprocessed_bundles = unprocessed_bundles 39 self.counters = counters 40 # Mapping of key -> earliest hold timestamp or None. Keys should be 41 # strings or None. 42 # 43 # For each key, we receive as its corresponding value the earliest 44 # watermark hold for that key (the key can be None for global state), past 45 # which the output watermark for the currently-executing step will not 46 # advance. If the value is None or utils.timestamp.MAX_TIMESTAMP, the 47 # watermark hold will be removed. 48 self.keyed_watermark_holds = keyed_watermark_holds or {} 49 # Only used when caching (materializing) all values is requested. 50 self.undeclared_tag_values = undeclared_tag_values 51 # Populated by the TransformExecutor. 52 self.logical_metric_updates = None 53 54 step_context = transform_evaluator._execution_context.get_step_context() 55 self.partial_keyed_state = step_context.partial_keyed_state 56 57 58 class TimerFiring(object): 59 """A single instance of a fired timer.""" 60 def __init__( 61 self, 62 encoded_key, 63 window, 64 name, 65 time_domain, 66 timestamp, 67 dynamic_timer_tag=''): 68 self.encoded_key = encoded_key 69 self.window = window 70 self.name = name 71 self.time_domain = time_domain 72 self.timestamp = timestamp 73 self.dynamic_timer_tag = dynamic_timer_tag 74 75 def __repr__(self): 76 return 'TimerFiring({!r}, {!r}, {}, {}, {})'.format( 77 self.encoded_key, 78 self.name, 79 self.time_domain, 80 self.timestamp, 81 self.dynamic_timer_tag) 82 83 84 class KeyedWorkItem(object): 85 """A keyed item that can either be a timer firing or a list of elements.""" 86 def __init__(self, encoded_key, timer_firings=None, elements=None): 87 self.encoded_key = encoded_key 88 self.timer_firings = timer_firings or [] 89 self.elements = elements or [] 90 91 def __repr__(self): 92 return 'KeyedWorkItem({!r}, {}, {})'.format( 93 self.encoded_key, self.timer_firings, self.elements)