Skip to content

Commit

Permalink
Merge 6350c1f into 3eb76a7
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb committed May 11, 2017
2 parents 3eb76a7 + 6350c1f commit c247014
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 14 deletions.
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/coders/coder_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
This module may be optionally compiled with Cython, using the corresponding
coder_impl.pxd file for type hints.
For internal use only; no backwards-compatibility guarantees.
"""
from types import NoneType

Expand Down
16 changes: 15 additions & 1 deletion sdks/python/apache_beam/coders/coders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
# limitations under the License.
#

"""Collection of useful coders."""
"""Collection of useful coders.
Only those coders listed in __all__ are part of the public API of this module.
"""

import base64
import cPickle as pickle
Expand Down Expand Up @@ -45,6 +48,13 @@
import dill


__all__ = ['Coder',
'BytesCoder', 'DillCoder', 'FastPrimitivesCoder', 'FloatCoder',
'IterableCoder', 'PickleCoder', 'ProtoCoder', 'SingletonCoder',
'StrUtf8Coder', 'TimestampCoder', 'TupleCoder',
'TupleSequenceCoder', 'VarIntCoder', 'WindowedValueCoder']


def serialize_coder(coder):
from apache_beam.internal import pickler
return '%s$%s' % (coder.__class__.__name__, pickler.dumps(coder))
Expand Down Expand Up @@ -116,6 +126,10 @@ def _create_impl(self):
self.estimate_size)

def get_impl(self):
"""For internal use only; no backwards-compatibility guarantees.
Returns the CoderImpl backing this Coder.
"""
if not hasattr(self, '_impl'):
self._impl = self._create_impl()
assert isinstance(self._impl, coder_impl.CoderImpl)
Expand Down
11 changes: 6 additions & 5 deletions sdks/python/apache_beam/coders/coders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import logging
import unittest

from apache_beam import coders
from apache_beam.coders import coders
from apache_beam.coders import proto2_coder_test_messages_pb2 as test_message
from apache_beam.coders.typecoders import registry as coders_registry


class PickleCoderTest(unittest.TestCase):
Expand All @@ -46,13 +47,13 @@ def test_equality(self):
class CodersTest(unittest.TestCase):

def test_str_utf8_coder(self):
real_coder = coders.registry.get_coder(str)
real_coder = coders_registry.get_coder(str)
expected_coder = coders.BytesCoder()
self.assertEqual(
real_coder.encode('abc'), expected_coder.encode('abc'))
self.assertEqual('abc', real_coder.decode(real_coder.encode('abc')))

real_coder = coders.registry.get_coder(bytes)
real_coder = coders_registry.get_coder(bytes)
expected_coder = coders.BytesCoder()
self.assertEqual(
real_coder.encode('abc'), expected_coder.encode('abc'))
Expand Down Expand Up @@ -82,7 +83,7 @@ def test_proto_coder(self):
mb.field1 = True
ma.field1 = u'hello world'
expected_coder = coders.ProtoCoder(ma.__class__)
real_coder = coders.registry.get_coder(ma.__class__)
real_coder = coders_registry.get_coder(ma.__class__)
self.assertEqual(expected_coder, real_coder)
self.assertEqual(real_coder.encode(ma), expected_coder.encode(ma))
self.assertEqual(ma, real_coder.decode(real_coder.encode(ma)))
Expand All @@ -104,7 +105,7 @@ class FallbackCoderTest(unittest.TestCase):
def test_default_fallback_path(self):
"""Test fallback path picks a matching coder if no coder is registered."""

coder = coders.registry.get_coder(DummyClass)
coder = coders_registry.get_coder(DummyClass)
# No matching coder, so picks the last fallback coder which is a
# FastPrimitivesCoder.
self.assertEqual(coder, coders.FastPrimitivesCoder())
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/coders/coders_test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

import dill

import coders
import observable
from apache_beam.transforms import window
from apache_beam.utils import timestamp
from apache_beam.utils import windowed_value

from apache_beam.coders import coders
from apache_beam.coders import proto2_coder_test_messages_pb2 as test_message


Expand Down
5 changes: 4 additions & 1 deletion sdks/python/apache_beam/coders/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#


"""Observable base class for iterables."""
"""Observable base class for iterables.
For internal use only; no backwards-compatibility guarantees.
"""


class ObservableMixin(object):
Expand Down
5 changes: 4 additions & 1 deletion sdks/python/apache_beam/coders/slow_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
# limitations under the License.
#

"""A pure Python implementation of stream.pyx."""
"""A pure Python implementation of stream.pyx.
For internal use only; no backwards-compatibility guarantees.
"""

import struct

Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/coders/standard_coders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import yaml

from apache_beam import coders
from apache_beam.coders import coders
from apache_beam.coders import coder_impl
from apache_beam.utils import windowed_value
from apache_beam.utils.timestamp import Timestamp
Expand Down
5 changes: 5 additions & 0 deletions sdks/python/apache_beam/coders/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# limitations under the License.
#

"""Compiled version of the Stream objects used by CoderImpl.
For internal use only; no backwards-compatibility guarantees.
"""

cimport libc.stdlib
cimport libc.string

Expand Down
3 changes: 3 additions & 0 deletions sdks/python/apache_beam/coders/typecoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def MakeXyzs(v):
from apache_beam.typehints import typehints


__all__ = ['registry']


class CoderRegistry(object):
"""A coder registry for typehint/coder associations."""

Expand Down
3 changes: 2 additions & 1 deletion sdks/python/apache_beam/examples/snippets/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from apache_beam import coders
from apache_beam import pvalue
from apache_beam import typehints
from apache_beam.coders.coders import ToStringCoder
from apache_beam.transforms.util import assert_that
from apache_beam.transforms.util import equal_to
from apache_beam.options.pipeline_options import PipelineOptions
Expand Down Expand Up @@ -422,7 +423,7 @@ class WriteDoFn(beam.DoFn):
def __init__(self, file_to_write):
self.file_to_write = file_to_write
self.file_obj = None
self.coder = coders.ToStringCoder()
self.coder = ToStringCoder()

def start_bundle(self):
assert self.file_to_write
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/io/fileio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import mock

import apache_beam as beam
from apache_beam import coders
from apache_beam.coders import coders
from apache_beam.io import fileio
from apache_beam.testing.test_pipeline import TestPipeline
from apache_beam.transforms.display import DisplayData
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/io/textio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import absolute_import
import logging

from apache_beam import coders
from apache_beam.coders import coders
from apache_beam.io import filebasedsource
from apache_beam.io import fileio
from apache_beam.io import iobase
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/transforms/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

from google.protobuf import struct_pb2

from apache_beam import coders
from apache_beam.coders import coders
from apache_beam.runners.api import beam_runner_api_pb2
from apache_beam.transforms import timeutil
from apache_beam.utils import proto_utils
Expand Down

0 comments on commit c247014

Please sign in to comment.