|
135 | 135 | # Serialized schema_pb2.Schema w/o id to id. |
136 | 136 | _SCHEMA_ID_CACHE = {} |
137 | 137 |
|
138 | | -# Schema id to Schema |
139 | | -_SCHEMA_CACHE = {} |
140 | 138 |
|
141 | 139 | def named_fields_to_schema( |
142 | 140 | names_and_types: Union[Dict[str, type], Sequence[Tuple[str, type]]], |
@@ -171,7 +169,6 @@ def named_fields_to_schema( |
171 | 169 | if key not in _SCHEMA_ID_CACHE: |
172 | 170 | _SCHEMA_ID_CACHE[key] = schema_registry.generate_new_id() |
173 | 171 | schema_id = _SCHEMA_ID_CACHE[key] |
174 | | - _SCHEMA_CACHE[schema_id] = schema |
175 | 172 |
|
176 | 173 | schema.id = schema_id |
177 | 174 | return schema |
@@ -581,8 +578,6 @@ def named_tuple_from_schema(self, schema: schema_pb2.Schema) -> type: |
581 | 578 | _named_tuple_reduce_method(schema.SerializeToString())) |
582 | 579 | setattr(user_type, "_field_descriptions", descriptions) |
583 | 580 | setattr(user_type, row_type._BEAM_SCHEMA_ID, schema.id) |
584 | | - if schema.id not in _SCHEMA_CACHE: |
585 | | - _SCHEMA_CACHE[schema.id] = schema |
586 | 581 |
|
587 | 582 | self.schema_registry.add(user_type, schema) |
588 | 583 | coders.registry.register_coder(user_type, coders.RowCoder) |
@@ -622,11 +617,12 @@ def schema_from_element_type(element_type: type) -> schema_pb2.Schema: |
622 | 617 | return named_fields_to_schema(element_type._fields) |
623 | 618 | elif match_is_named_tuple(element_type): |
624 | 619 | if hasattr(element_type, row_type._BEAM_SCHEMA_ID): |
625 | | - # if the named tuple's schema is in cache, we just use it instead of |
| 620 | + # if the named tuple's schema is in registry, we just use it instead of |
626 | 621 | # regenerating one. |
627 | 622 | schema_id = getattr(element_type, row_type._BEAM_SCHEMA_ID) |
628 | | - if schema_id in _SCHEMA_CACHE: |
629 | | - return _SCHEMA_CACHE[schema_id] |
| 623 | + schema = SCHEMA_REGISTRY.get_schema_by_id(schema_id) |
| 624 | + if schema is not None: |
| 625 | + return schema |
630 | 626 | return named_tuple_to_schema(element_type) |
631 | 627 | else: |
632 | 628 | raise TypeError( |
|
0 commit comments