You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by ro...@apache.org on 2016/11/03 21:36:13 UTC

[1/3] incubator-beam git commit: Checking for integer types in json conversion

Repository: incubator-beam
Updated Branches:
  refs/heads/python-sdk 96c228675 -> a6e104d6d


Checking for integer types in json conversion


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/3321064e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/3321064e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/3321064e

Branch: refs/heads/python-sdk
Commit: 3321064e805fb0359881c543926d18005099cc36
Parents: 96c2286
Author: Pablo <pa...@google.com>
Authored: Thu Nov 3 11:41:53 2016 -0700
Committer: Robert Bradshaw <ro...@google.com>
Committed: Thu Nov 3 14:30:47 2016 -0700

----------------------------------------------------------------------
 sdks/python/apache_beam/internal/json_value.py | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/3321064e/sdks/python/apache_beam/internal/json_value.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/internal/json_value.py b/sdks/python/apache_beam/internal/json_value.py
index 5a3a286..23b5d5b 100644
--- a/sdks/python/apache_beam/internal/json_value.py
+++ b/sdks/python/apache_beam/internal/json_value.py
@@ -20,6 +20,10 @@
 from apitools.base.py import extra_types
 
 
+_MAXINT64 = (1 << 63) - 1
+_MININT64 = - (1 << 63)
+
+
 def get_typed_value_descriptor(obj):
   """Converts a basic type into a @type/value dictionary.
 
@@ -87,6 +91,11 @@ def to_json_value(obj, with_type=False):
     return extra_types.JsonValue(boolean_value=obj)
   elif isinstance(obj, int):
     return extra_types.JsonValue(integer_value=obj)
+  elif isinstance(obj, long):
+    if _MININT64 <= obj <= _MAXINT64:
+      return extra_types.JsonValue(integer_value=obj)
+    else:
+      raise TypeError('Can not encode {} as a 64-bit integer'.format(obj))
   elif isinstance(obj, float):
     return extra_types.JsonValue(double_value=obj)
   else:


[3/3] incubator-beam git commit: Closes #1273

Posted by ro...@apache.org.
Closes #1273


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/a6e104d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/a6e104d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/a6e104d6

Branch: refs/heads/python-sdk
Commit: a6e104d6d8090f70cc0e881e9a13bff53ff50949
Parents: 96c2286 b30208b
Author: Robert Bradshaw <ro...@google.com>
Authored: Thu Nov 3 14:35:40 2016 -0700
Committer: Robert Bradshaw <ro...@google.com>
Committed: Thu Nov 3 14:35:40 2016 -0700

----------------------------------------------------------------------
 sdks/python/apache_beam/internal/json_value.py    |  9 +++++++++
 .../apache_beam/internal/json_value_test.py       | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------



[2/3] incubator-beam git commit: Adding unit tests

Posted by ro...@apache.org.
Adding unit tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/b30208be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/b30208be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/b30208be

Branch: refs/heads/python-sdk
Commit: b30208bea7506d585a59b3c4c7dd346afd714287
Parents: 3321064
Author: Pablo <pa...@google.com>
Authored: Thu Nov 3 11:57:27 2016 -0700
Committer: Robert Bradshaw <ro...@google.com>
Committed: Thu Nov 3 14:30:50 2016 -0700

----------------------------------------------------------------------
 .../apache_beam/internal/json_value_test.py       | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/b30208be/sdks/python/apache_beam/internal/json_value_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/internal/json_value_test.py b/sdks/python/apache_beam/internal/json_value_test.py
index b3d9e83..cfab293 100644
--- a/sdks/python/apache_beam/internal/json_value_test.py
+++ b/sdks/python/apache_beam/internal/json_value_test.py
@@ -67,6 +67,24 @@ class JsonValueTest(unittest.TestCase):
   def test_none_from(self):
     self.assertIsNone(from_json_value(to_json_value(None)))
 
+  def test_large_integer(self):
+    num = 1 << 35
+    self.assertEquals(num, from_json_value(to_json_value(num)))
+    self.assertEquals(long(num), from_json_value(to_json_value(long(num))))
+
+  def test_long_value(self):
+    self.assertEquals(long(27), from_json_value(to_json_value(long(27))))
+
+  def test_too_long_value(self):
+    try:
+      to_json_value(long(1 << 64))
+    except TypeError as e:
+      pass
+    except Exception as e:
+      self.fail('Unexpected exception raised: {}'.format(e))
+    else:
+      self.fail('TypeError not raised.')
+
 
 if __name__ == '__main__':
   unittest.main()