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 <pabl...@google.com>
Authored: Thu Nov 3 11:41:53 2016 -0700
Committer: Robert Bradshaw <rober...@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:

Reply via email to