Skip to content

Commit

Permalink
Int32 serialization (Azure#13452)
Browse files Browse the repository at this point in the history
* changes from int64 to int32 serialization. client side will try to serialize to int32, then int64, and raise a TypeError if it cannot

* removed string casting, fixed linting error

* rerun recording

* removing additional tests to see if that is pipeline issue
  • Loading branch information
seankane-msft authored and rakshith91 committed Sep 4, 2020
1 parent 35b095d commit 2d68777
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ def _convert_to_entity(entry_element):

# Add type for Int32
if type(value) is int: # pylint:disable=C0123
mtype = EdmType.INT32
if value.bit_length() <= 32:
mtype = EdmType.INT32
else:
mtype = EdmType.INT64

# no type info, property should parse automatically
if not mtype:
Expand Down
5 changes: 4 additions & 1 deletion sdk/tables/azure-data-tables/azure/data/tables/_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def __init__(self,
elif isinstance(value, bool):
self.type = EdmType.BOOLEAN
elif isinstance(value, six.integer_types):
self.type = EdmType.INT64
if value.bit_length() <= 32:
self.type = EdmType.INT32
else:
self.type = EdmType.INT64
elif isinstance(value, datetime):
self.type = EdmType.DATETIME
elif isinstance(value, float):
Expand Down
11 changes: 10 additions & 1 deletion sdk/tables/azure-data-tables/azure/data/tables/_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ def _to_entity_int64(value):
return EdmType.INT64, str(value)


def _to_entity_int(value):
ivalue = int(value)
if ivalue.bit_length() <= 32:
return _to_entity_int32(value)
if ivalue.bit_length() <= 64:
return _to_entity_int64(value)
raise TypeError(_ERROR_VALUE_TOO_LARGE.format(str(value), EdmType.INT64))


def _to_entity_str(value):
return None, value

Expand All @@ -144,7 +153,7 @@ def _to_entity_none(value): # pylint:disable=W0613
# Conversion from Python type to a function which returns a tuple of the
# type string and content string.
_PYTHON_TO_ENTITY_CONVERSIONS = {
int: _to_entity_int64,
int: _to_entity_int,
bool: _to_entity_bool,
datetime: _to_entity_datetime,
float: _to_entity_float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ._serialize import serialize_iso
from ._deserialize import _return_headers_and_deserialized
from ._error import _process_table_error
from ._models import TableEntityPropertiesPaged, UpdateMode, TableItem
from ._models import TableEntityPropertiesPaged, UpdateMode


class TableClient(TableClientBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Thu, 20 Aug 2020 20:16:40 GMT
- Mon, 31 Aug 2020 22:27:33 GMT
User-Agent:
- azsdk-python-data-tables/2019-07-07 Python/3.8.4 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b1 Python/3.8.4 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Thu, 20 Aug 2020 20:16:40 GMT
- Mon, 31 Aug 2020 22:27:33 GMT
x-ms-version:
- '2019-07-07'
- '2019-02-02'
method: POST
uri: https://storagename.table.core.windows.net/Tables
response:
Expand All @@ -33,7 +33,7 @@ interactions:
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Thu, 20 Aug 2020 20:16:40 GMT
- Mon, 31 Aug 2020 22:27:30 GMT
location:
- https://storagename.table.core.windows.net/Tables('uttable8fac1b18')
server:
Expand All @@ -43,7 +43,7 @@ interactions:
x-content-type-options:
- nosniff
x-ms-version:
- '2019-07-07'
- '2019-02-02'
status:
code: 201
message: Created
Expand All @@ -59,13 +59,13 @@ interactions:
Content-Length:
- '0'
Date:
- Thu, 20 Aug 2020 20:16:40 GMT
- Mon, 31 Aug 2020 22:27:33 GMT
User-Agent:
- azsdk-python-data-tables/2019-07-07 Python/3.8.4 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b1 Python/3.8.4 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Thu, 20 Aug 2020 20:16:40 GMT
- Mon, 31 Aug 2020 22:27:33 GMT
x-ms-version:
- '2019-07-07'
- '2019-02-02'
method: DELETE
uri: https://storagename.table.core.windows.net/Tables('uttable8fac1b18')
response:
Expand All @@ -77,13 +77,13 @@ interactions:
content-length:
- '0'
date:
- Thu, 20 Aug 2020 20:16:40 GMT
- Mon, 31 Aug 2020 22:27:30 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-content-type-options:
- nosniff
x-ms-version:
- '2019-07-07'
- '2019-02-02'
status:
code: 204
message: No Content
Expand Down
6 changes: 3 additions & 3 deletions sdk/tables/azure-data-tables/tests/test_table_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_inferred_types(self):
entity.test5 = EntityProperty(u"stringystring")
entity.test6 = EntityProperty(3.14159)
entity.test7 = EntityProperty(100)
entity.test8 = EntityProperty(10, EdmType.INT32)
entity.test8 = EntityProperty(2 ** 33)

# Assert
self.assertEqual(entity.test.type, EdmType.BOOLEAN)
Expand All @@ -172,8 +172,8 @@ def test_inferred_types(self):
self.assertEqual(entity.test4.type, EdmType.DATETIME)
self.assertEqual(entity.test5.type, EdmType.STRING)
self.assertEqual(entity.test6.type, EdmType.DOUBLE)
self.assertEqual(entity.test7.type, EdmType.INT64)
self.assertEqual(entity.test8.type, EdmType.INT32)
self.assertEqual(entity.test7.type, EdmType.INT32)
self.assertEqual(entity.test8.type, EdmType.INT64)


@pytest.mark.skip("pending")
Expand Down
8 changes: 4 additions & 4 deletions sdk/tables/azure-data-tables/tests/test_table_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _assert_default_entity(self, entity, headers=None):
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
self.assertEqual(entity['binary'].value, b'binary')
self.assertIsInstance(entity['other'], EntityProperty)
self.assertEqual(entity['other'].type, EdmType.INT64)
self.assertEqual(entity['other'].type, EdmType.INT32)
self.assertEqual(entity['other'].value, 20)
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
# self.assertTrue('metadata' in entity.odata)
Expand Down Expand Up @@ -188,7 +188,7 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None):
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
self.assertEqual(entity['binary'].value, b'binary')
self.assertIsInstance(entity['other'], EntityProperty)
self.assertEqual(entity['other'].type, EdmType.INT64)
self.assertEqual(entity['other'].type, EdmType.INT32)
self.assertEqual(entity['other'].value, 20)
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
# self.assertTrue('metadata' in entity.odata)
Expand Down Expand Up @@ -222,7 +222,7 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None):
self.assertTrue(entity['birthday'].endswith('00Z'))
self.assertEqual(entity['binary'], b64encode(b'binary').decode('utf-8'))
self.assertIsInstance(entity['other'], EntityProperty)
self.assertEqual(entity['other'].type, EdmType.INT64)
self.assertEqual(entity['other'].type, EdmType.INT32)
self.assertEqual(entity['other'].value, 20)
self.assertEqual(entity['clsid'], 'c9da6455-213d-42c9-9a79-3e9149a57833')
# self.assertIsNone(entity.odata)
Expand Down Expand Up @@ -273,7 +273,7 @@ def _assert_merged_entity(self, entity):
self.assertEqual(entity.Birthday, datetime(1973, 10, 4, tzinfo=tzutc()))
self.assertEqual(entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()))
self.assertIsInstance(entity.other, EntityProperty)
self.assertEqual(entity.other.type, EdmType.INT64)
self.assertEqual(entity.other.type, EdmType.INT32)
self.assertEqual(entity.other.value, 20)
self.assertIsInstance(entity.clsid, uuid.UUID)
self.assertEqual(str(entity.clsid), 'c9da6455-213d-42c9-9a79-3e9149a57833')
Expand Down
8 changes: 4 additions & 4 deletions sdk/tables/azure-data-tables/tests/test_table_entity_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _assert_default_entity(self, entity, headers=None):
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
self.assertEqual(entity['binary'].value, b'binary') # TODO: added the ".value" portion, verify this is correct
self.assertIsInstance(entity['other'], EntityProperty)
self.assertEqual(entity['other'].type, EdmType.INT64)
self.assertEqual(entity['other'].type, EdmType.INT32)
self.assertEqual(entity['other'].value, 20)
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
# self.assertTrue('metadata' in entity.odata)
Expand Down Expand Up @@ -190,7 +190,7 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None):
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
self.assertEqual(entity['binary'].value, b'binary')
self.assertIsInstance(entity['other'], EntityProperty)
self.assertEqual(entity['other'].type, EdmType.INT64)
self.assertEqual(entity['other'].type, EdmType.INT32)
self.assertEqual(entity['other'].value, 20)
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
# self.assertTrue('metadata' in entity.odata)
Expand Down Expand Up @@ -225,7 +225,7 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None):
self.assertTrue(entity['birthday'].endswith('00Z'))
self.assertEqual(entity['binary'], b64encode(b'binary').decode('utf-8'))
self.assertIsInstance(entity['other'], EntityProperty)
self.assertEqual(entity['other'].type, EdmType.INT64)
self.assertEqual(entity['other'].type, EdmType.INT32)
self.assertEqual(entity['other'].value, 20)
self.assertEqual(entity['clsid'], 'c9da6455-213d-42c9-9a79-3e9149a57833')
# self.assertIsNone(entity.odata)
Expand Down Expand Up @@ -275,7 +275,7 @@ def _assert_merged_entity(self, entity):
self.assertEqual(entity.Birthday, datetime(1973, 10, 4, tzinfo=tzutc()))
self.assertEqual(entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()))
self.assertIsInstance(entity.other, EntityProperty)
self.assertEqual(entity.other.type, EdmType.INT64)
self.assertEqual(entity.other.type, EdmType.INT32)
self.assertEqual(entity.other.value, 20)
self.assertIsInstance(entity.clsid, uuid.UUID)
self.assertEqual(str(entity.clsid), 'c9da6455-213d-42c9-9a79-3e9149a57833')
Expand Down

0 comments on commit 2d68777

Please sign in to comment.