Skip to content

Commit 4acdaa3

Browse files
committed
Comments.
1 parent 9d118db commit 4acdaa3

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

sdks/python/apache_beam/coders/coder_impl.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ cdef class FastPrimitivesCoderImpl(StreamCoderImpl):
8282
cdef object requires_deterministic_step_label
8383
cdef bint warn_deterministic_fallback
8484
cdef bint force_use_dill
85-
cdef bint skip_use_relative_filepaths
85+
cdef bint use_relative_filepaths
8686

8787
@cython.locals(dict_value=dict, int_value=libc.stdint.int64_t,
8888
unicode_value=unicode)

sdks/python/apache_beam/coders/coder_impl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,13 @@ def __init__(
379379
fallback_coder_impl,
380380
requires_deterministic_step_label=None,
381381
force_use_dill=False,
382-
skip_use_relative_filepaths=False):
382+
use_relative_filepaths=True):
383383
self.fallback_coder_impl = fallback_coder_impl
384384
self.iterable_coder_impl = IterableCoderImpl(self)
385385
self.requires_deterministic_step_label = requires_deterministic_step_label
386386
self.warn_deterministic_fallback = True
387387
self.force_use_dill = force_use_dill
388-
self.skip_use_relative_filepaths = skip_use_relative_filepaths
388+
self.use_relative_filepaths = use_relative_filepaths
389389

390390
@staticmethod
391391
def register_iterable_like_type(t):
@@ -567,7 +567,7 @@ def encode_type(self, t, stream):
567567
id_generator=None,
568568
skip_reset_dynamic_type_state=True,
569569
filepath_interceptor=cloudpickle.get_relative_path)
570-
if self.skip_use_relative_filepaths:
570+
if not self.use_relative_filepaths:
571571
config.filepath_interceptor = None
572572
_pickled_types[t] = cloudpickle_pickler.dumps(t, config=config)
573573
stream.write(_pickled_types[t], True)

sdks/python/apache_beam/coders/coders.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,21 +930,21 @@ class DeterministicFastPrimitivesCoderV2(FastCoder):
930930
def __init__(self, coder, step_label, update_compatibility_version=None):
931931
self._underlying_coder = coder
932932
self._step_label = step_label
933-
self._skip_use_relative_filepaths = False
933+
self._use_relative_filepaths = True
934934
self._version_tag = "v2_69"
935935
from apache_beam.transforms.util import is_v1_prior_to_v2
936936
# Versions prior to 2.69.0 did not use relative filepaths.
937937
if update_compatibility_version and is_v1_prior_to_v2(
938938
v1=update_compatibility_version, v2="2.69.0"):
939939
self._version_tag = ""
940-
self._skip_use_relative_filepaths = True
940+
self._use_relative_filepaths = False
941941

942942
def _create_impl(self):
943943
return coder_impl.FastPrimitivesCoderImpl(
944944
self._underlying_coder.get_impl(),
945945
requires_deterministic_step_label=self._step_label,
946946
force_use_dill=False,
947-
skip_use_relative_filepaths=self._skip_use_relative_filepaths)
947+
use_relative_filepaths=self._use_relative_filepaths)
948948

949949
def is_deterministic(self):
950950
# type: () -> bool
@@ -1024,6 +1024,16 @@ def _should_force_use_dill(update_compat_version):
10241024

10251025

10261026
def _update_compatible_deterministic_fast_primitives_coder(coder, step_label):
1027+
""" Returns the update compatible version of DeterministicFastPrimitivesCoder
1028+
The differences are in how "special types" e.g. NamedTuples, Dataclasses are
1029+
deterministically encoded.
1030+
1031+
- In SDK version <= 2.67.0 dill is used to encode "special types"
1032+
- In SDK version 2.68.0 cloudpickle is used to encode "special types" with
1033+
absolute filepaths in code objects and dynamic functions.
1034+
- In SDK version 2.69.0 cloudpickle is used to encode "special types" with
1035+
relative filepaths in code objects and dynamic functions.
1036+
"""
10271037
from apache_beam.coders import typecoders
10281038
update_compat_version = typecoders.registry.update_compatibility_version
10291039
if _should_force_use_dill(update_compat_version):

sdks/python/apache_beam/coders/coders_test_common.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ def test_memoizing_pickle_coder(self):
252252
param(compat_version="2.68.0"),
253253
])
254254
def test_deterministic_coder(self, compat_version):
255+
""" Test in process determinism for all special deterministic types
256+
257+
- In SDK version <= 2.67.0 dill is used to encode "special types"
258+
- In SDK version 2.68.0 cloudpickle is used to encode "special types" with
259+
absolute filepaths in code objects and dynamic functions.
260+
- In SDK version 2.69.0 cloudpickle is used to encode "special types" with
261+
relative filepaths in code objects and dynamic functions.
262+
"""
255263

256264
typecoders.registry.update_compatibility_version = compat_version
257265
coder = coders.FastPrimitivesCoder()
@@ -329,6 +337,15 @@ def test_deterministic_coder(self, compat_version):
329337
param(compat_version="2.68.0"),
330338
])
331339
def test_deterministic_map_coder_is_update_compatible(self, compat_version):
340+
""" Test in process determinism for map coder including when a component
341+
coder uses DeterministicFastPrimitivesCoder for "special types".
342+
343+
- In SDK version <= 2.67.0 dill is used to encode "special types"
344+
- In SDK version 2.68.0 cloudpickle is used to encode "special types" with
345+
absolute filepaths in code objects and dynamic functions.
346+
- In SDK version 2.69.0 cloudpickle is used to encode "special types" with
347+
relative file
348+
"""
332349
typecoders.registry.update_compatibility_version = compat_version
333350
values = [{
334351
MyTypedNamedTuple(i, 'a'): MyTypedNamedTuple('a', i)
@@ -688,7 +705,14 @@ def test_param_windowed_value_coder(self):
688705
])
689706
def test_cross_process_encoding_of_special_types_is_deterministic(
690707
self, compat_version):
691-
"""Test cross-process determinism for all special deterministic types"""
708+
"""Test cross-process determinism for all special deterministic types
709+
710+
- In SDK version <= 2.67.0 dill is used to encode "special types"
711+
- In SDK version 2.68.0 cloudpickle is used to encode "special types" with
712+
absolute filepaths in code objects and dynamic functions.
713+
- In SDK version 2.69.0 cloudpickle is used to encode "special types" with
714+
relative filepaths in code objects and dynamic functions.
715+
"""
692716
is_using_dill = compat_version == "2.67.0"
693717
if is_using_dill:
694718
pytest.importorskip("dill")
@@ -806,6 +830,8 @@ def run_subprocess():
806830
continue
807831

808832
if test_name == "named_tuple_simple" and not is_using_dill:
833+
# The absense of a compat_version means we are using the most recent
834+
# implementation of the coder, which uses relative paths.
809835
should_have_relative_path = not compat_version
810836
named_tuple_type = type(decoded1)
811837
self.assertEqual(

0 commit comments

Comments
 (0)