Repository: beam Updated Branches: refs/heads/master 097aec7a3 -> afe8b0ea1
Add a log message to ValueError in AsSingleton Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/521b2d71 Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/521b2d71 Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/521b2d71 Branch: refs/heads/master Commit: 521b2d711b373e64bff7f603ba45cd2a617f6e5e Parents: 097aec7 Author: Ahmet Altay <[email protected]> Authored: Mon Aug 28 15:34:26 2017 -0700 Committer: Ahmet Altay <[email protected]> Committed: Wed Aug 30 16:49:07 2017 -0700 ---------------------------------------------------------------------- sdks/python/apache_beam/pvalue.py | 5 +++-- sdks/python/apache_beam/pvalue_test.py | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/521b2d71/sdks/python/apache_beam/pvalue.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/pvalue.py b/sdks/python/apache_beam/pvalue.py index 34a483e..35686f7 100644 --- a/sdks/python/apache_beam/pvalue.py +++ b/sdks/python/apache_beam/pvalue.py @@ -329,8 +329,9 @@ class AsSingleton(AsSideInput): elif len(head) == 1: return head[0] raise ValueError( - 'PCollection with more than one element accessed as ' - 'a singleton view.') + 'PCollection of size %d with more than one element accessed as a ' + 'singleton view. First two elements encountered are "%s", "%s".' % ( + len(head), str(head[0]), str(head[1]))) @property def element_type(self): http://git-wip-us.apache.org/repos/asf/beam/blob/521b2d71/sdks/python/apache_beam/pvalue_test.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/pvalue_test.py b/sdks/python/apache_beam/pvalue_test.py index 4acbc52..48203df 100644 --- a/sdks/python/apache_beam/pvalue_test.py +++ b/sdks/python/apache_beam/pvalue_test.py @@ -19,6 +19,7 @@ import unittest +from apache_beam.pvalue import AsSingleton from apache_beam.pvalue import PValue from apache_beam.testing.test_pipeline import TestPipeline @@ -30,6 +31,13 @@ class PValueTest(unittest.TestCase): value = PValue(pipeline) self.assertEqual(pipeline, value.pipeline) + def test_assingleton_multi_element(self): + with self.assertRaisesRegexp( + ValueError, + 'PCollection of size 2 with more than one element accessed as a ' + 'singleton view. First two elements encountered are \"1\", \"2\".'): + AsSingleton._from_runtime_iterable([1, 2], {}) + if __name__ == '__main__': unittest.main()
