Skip to content

Commit 6e8656d

Browse files
Int32 serialization (#13452)
* 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
1 parent f18cce0 commit 6e8656d

8 files changed

+42
-27
lines changed

sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ def _convert_to_entity(entry_element):
160160

161161
# Add type for Int32
162162
if type(value) is int: # pylint:disable=C0123
163-
mtype = EdmType.INT32
163+
if value.bit_length() <= 32:
164+
mtype = EdmType.INT32
165+
else:
166+
mtype = EdmType.INT64
164167

165168
# no type info, property should parse automatically
166169
if not mtype:

sdk/tables/azure-data-tables/azure/data/tables/_entity.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ def __init__(self,
101101
elif isinstance(value, bool):
102102
self.type = EdmType.BOOLEAN
103103
elif isinstance(value, six.integer_types):
104-
self.type = EdmType.INT64
104+
if value.bit_length() <= 32:
105+
self.type = EdmType.INT32
106+
else:
107+
self.type = EdmType.INT64
105108
elif isinstance(value, datetime):
106109
self.type = EdmType.DATETIME
107110
elif isinstance(value, float):

sdk/tables/azure-data-tables/azure/data/tables/_serialize.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def _to_entity_int64(value):
133133
return EdmType.INT64, str(value)
134134

135135

136+
def _to_entity_int(value):
137+
ivalue = int(value)
138+
if ivalue.bit_length() <= 32:
139+
return _to_entity_int32(value)
140+
if ivalue.bit_length() <= 64:
141+
return _to_entity_int64(value)
142+
raise TypeError(_ERROR_VALUE_TOO_LARGE.format(str(value), EdmType.INT64))
143+
144+
136145
def _to_entity_str(value):
137146
return None, value
138147

@@ -144,7 +153,7 @@ def _to_entity_none(value): # pylint:disable=W0613
144153
# Conversion from Python type to a function which returns a tuple of the
145154
# type string and content string.
146155
_PYTHON_TO_ENTITY_CONVERSIONS = {
147-
int: _to_entity_int64,
156+
int: _to_entity_int,
148157
bool: _to_entity_bool,
149158
datetime: _to_entity_datetime,
150159
float: _to_entity_float,

sdk/tables/azure-data-tables/azure/data/tables/_table_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from ._serialize import serialize_iso
3333
from ._deserialize import _return_headers_and_deserialized
3434
from ._error import _process_table_error
35-
from ._models import TableEntityPropertiesPaged, UpdateMode, TableItem
35+
from ._models import TableEntityPropertiesPaged, UpdateMode
3636

3737

3838
class TableClient(TableClientBase):

sdk/tables/azure-data-tables/tests/recordings/test_table_entity.test_insert_entity_with_large_int32_value_throws.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ interactions:
1515
DataServiceVersion:
1616
- '3.0'
1717
Date:
18-
- Thu, 20 Aug 2020 20:16:40 GMT
18+
- Mon, 31 Aug 2020 22:27:33 GMT
1919
User-Agent:
20-
- azsdk-python-data-tables/2019-07-07 Python/3.8.4 (Windows-10-10.0.19041-SP0)
20+
- azsdk-python-data-tables/12.0.0b1 Python/3.8.4 (Windows-10-10.0.19041-SP0)
2121
x-ms-date:
22-
- Thu, 20 Aug 2020 20:16:40 GMT
22+
- Mon, 31 Aug 2020 22:27:33 GMT
2323
x-ms-version:
24-
- '2019-07-07'
24+
- '2019-02-02'
2525
method: POST
2626
uri: https://storagename.table.core.windows.net/Tables
2727
response:
@@ -33,7 +33,7 @@ interactions:
3333
content-type:
3434
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
3535
date:
36-
- Thu, 20 Aug 2020 20:16:40 GMT
36+
- Mon, 31 Aug 2020 22:27:30 GMT
3737
location:
3838
- https://storagename.table.core.windows.net/Tables('uttable8fac1b18')
3939
server:
@@ -43,7 +43,7 @@ interactions:
4343
x-content-type-options:
4444
- nosniff
4545
x-ms-version:
46-
- '2019-07-07'
46+
- '2019-02-02'
4747
status:
4848
code: 201
4949
message: Created
@@ -59,13 +59,13 @@ interactions:
5959
Content-Length:
6060
- '0'
6161
Date:
62-
- Thu, 20 Aug 2020 20:16:40 GMT
62+
- Mon, 31 Aug 2020 22:27:33 GMT
6363
User-Agent:
64-
- azsdk-python-data-tables/2019-07-07 Python/3.8.4 (Windows-10-10.0.19041-SP0)
64+
- azsdk-python-data-tables/12.0.0b1 Python/3.8.4 (Windows-10-10.0.19041-SP0)
6565
x-ms-date:
66-
- Thu, 20 Aug 2020 20:16:40 GMT
66+
- Mon, 31 Aug 2020 22:27:33 GMT
6767
x-ms-version:
68-
- '2019-07-07'
68+
- '2019-02-02'
6969
method: DELETE
7070
uri: https://storagename.table.core.windows.net/Tables('uttable8fac1b18')
7171
response:
@@ -77,13 +77,13 @@ interactions:
7777
content-length:
7878
- '0'
7979
date:
80-
- Thu, 20 Aug 2020 20:16:40 GMT
80+
- Mon, 31 Aug 2020 22:27:30 GMT
8181
server:
8282
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
8383
x-content-type-options:
8484
- nosniff
8585
x-ms-version:
86-
- '2019-07-07'
86+
- '2019-02-02'
8787
status:
8888
code: 204
8989
message: No Content

sdk/tables/azure-data-tables/tests/test_table_batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_inferred_types(self):
163163
entity.test5 = EntityProperty(u"stringystring")
164164
entity.test6 = EntityProperty(3.14159)
165165
entity.test7 = EntityProperty(100)
166-
entity.test8 = EntityProperty(10, EdmType.INT32)
166+
entity.test8 = EntityProperty(2 ** 33)
167167

168168
# Assert
169169
self.assertEqual(entity.test.type, EdmType.BOOLEAN)
@@ -172,8 +172,8 @@ def test_inferred_types(self):
172172
self.assertEqual(entity.test4.type, EdmType.DATETIME)
173173
self.assertEqual(entity.test5.type, EdmType.STRING)
174174
self.assertEqual(entity.test6.type, EdmType.DOUBLE)
175-
self.assertEqual(entity.test7.type, EdmType.INT64)
176-
self.assertEqual(entity.test8.type, EdmType.INT32)
175+
self.assertEqual(entity.test7.type, EdmType.INT32)
176+
self.assertEqual(entity.test8.type, EdmType.INT64)
177177

178178

179179
@pytest.mark.skip("pending")

sdk/tables/azure-data-tables/tests/test_table_entity.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _assert_default_entity(self, entity, headers=None):
160160
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
161161
self.assertEqual(entity['binary'].value, b'binary')
162162
self.assertIsInstance(entity['other'], EntityProperty)
163-
self.assertEqual(entity['other'].type, EdmType.INT64)
163+
self.assertEqual(entity['other'].type, EdmType.INT32)
164164
self.assertEqual(entity['other'].value, 20)
165165
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
166166
# self.assertTrue('metadata' in entity.odata)
@@ -188,7 +188,7 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None):
188188
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
189189
self.assertEqual(entity['binary'].value, b'binary')
190190
self.assertIsInstance(entity['other'], EntityProperty)
191-
self.assertEqual(entity['other'].type, EdmType.INT64)
191+
self.assertEqual(entity['other'].type, EdmType.INT32)
192192
self.assertEqual(entity['other'].value, 20)
193193
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
194194
# self.assertTrue('metadata' in entity.odata)
@@ -222,7 +222,7 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None):
222222
self.assertTrue(entity['birthday'].endswith('00Z'))
223223
self.assertEqual(entity['binary'], b64encode(b'binary').decode('utf-8'))
224224
self.assertIsInstance(entity['other'], EntityProperty)
225-
self.assertEqual(entity['other'].type, EdmType.INT64)
225+
self.assertEqual(entity['other'].type, EdmType.INT32)
226226
self.assertEqual(entity['other'].value, 20)
227227
self.assertEqual(entity['clsid'], 'c9da6455-213d-42c9-9a79-3e9149a57833')
228228
# self.assertIsNone(entity.odata)
@@ -273,7 +273,7 @@ def _assert_merged_entity(self, entity):
273273
self.assertEqual(entity.Birthday, datetime(1973, 10, 4, tzinfo=tzutc()))
274274
self.assertEqual(entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()))
275275
self.assertIsInstance(entity.other, EntityProperty)
276-
self.assertEqual(entity.other.type, EdmType.INT64)
276+
self.assertEqual(entity.other.type, EdmType.INT32)
277277
self.assertEqual(entity.other.value, 20)
278278
self.assertIsInstance(entity.clsid, uuid.UUID)
279279
self.assertEqual(str(entity.clsid), 'c9da6455-213d-42c9-9a79-3e9149a57833')

sdk/tables/azure-data-tables/tests/test_table_entity_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _assert_default_entity(self, entity, headers=None):
161161
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
162162
self.assertEqual(entity['binary'].value, b'binary') # TODO: added the ".value" portion, verify this is correct
163163
self.assertIsInstance(entity['other'], EntityProperty)
164-
self.assertEqual(entity['other'].type, EdmType.INT64)
164+
self.assertEqual(entity['other'].type, EdmType.INT32)
165165
self.assertEqual(entity['other'].value, 20)
166166
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
167167
# self.assertTrue('metadata' in entity.odata)
@@ -190,7 +190,7 @@ def _assert_default_entity_json_full_metadata(self, entity, headers=None):
190190
self.assertEqual(entity['birthday'], datetime(1970, 10, 4, tzinfo=tzutc()))
191191
self.assertEqual(entity['binary'].value, b'binary')
192192
self.assertIsInstance(entity['other'], EntityProperty)
193-
self.assertEqual(entity['other'].type, EdmType.INT64)
193+
self.assertEqual(entity['other'].type, EdmType.INT32)
194194
self.assertEqual(entity['other'].value, 20)
195195
self.assertEqual(entity['clsid'], uuid.UUID('c9da6455-213d-42c9-9a79-3e9149a57833'))
196196
# self.assertTrue('metadata' in entity.odata)
@@ -225,7 +225,7 @@ def _assert_default_entity_json_no_metadata(self, entity, headers=None):
225225
self.assertTrue(entity['birthday'].endswith('00Z'))
226226
self.assertEqual(entity['binary'], b64encode(b'binary').decode('utf-8'))
227227
self.assertIsInstance(entity['other'], EntityProperty)
228-
self.assertEqual(entity['other'].type, EdmType.INT64)
228+
self.assertEqual(entity['other'].type, EdmType.INT32)
229229
self.assertEqual(entity['other'].value, 20)
230230
self.assertEqual(entity['clsid'], 'c9da6455-213d-42c9-9a79-3e9149a57833')
231231
# self.assertIsNone(entity.odata)
@@ -275,7 +275,7 @@ def _assert_merged_entity(self, entity):
275275
self.assertEqual(entity.Birthday, datetime(1973, 10, 4, tzinfo=tzutc()))
276276
self.assertEqual(entity.birthday, datetime(1991, 10, 4, tzinfo=tzutc()))
277277
self.assertIsInstance(entity.other, EntityProperty)
278-
self.assertEqual(entity.other.type, EdmType.INT64)
278+
self.assertEqual(entity.other.type, EdmType.INT32)
279279
self.assertEqual(entity.other.value, 20)
280280
self.assertIsInstance(entity.clsid, uuid.UUID)
281281
self.assertEqual(str(entity.clsid), 'c9da6455-213d-42c9-9a79-3e9149a57833')

0 commit comments

Comments
 (0)