Skip to content

Commit fa4b95f

Browse files
authored
Updates with Api review Fixes (#34428)
* Updates with Api review asks This update changes key word priority_level to priority and adds it as an option to delete and batch execution. This also allows bad request exception to go through if user puts a value other than high or low for priority. This also makes additional classes related to partition key and prefix partitions as private. Additionally a test that accommodates the bad request exception from invalid priority value has been added. * update murmurhash3 tests tests were failing because it was referencing Uint128 when it was changed to _UInt128
1 parent 4521720 commit fa4b95f

File tree

9 files changed

+234
-204
lines changed

9 files changed

+234
-204
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
'is_query_plan_request': 'isQueryPlanRequest',
6161
'supported_query_features': 'supportedQueryFeatures',
6262
'query_version': 'queryVersion',
63-
'priority_level': 'priorityLevel'
63+
'priority': 'priorityLevel'
6464
}
6565

6666
# Cosmos resource ID validation regex breakdown:
@@ -245,7 +245,7 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
245245
headers[http_constants.HttpHeaders.ResponseContinuationTokenLimitInKb] = options[
246246
"responseContinuationTokenLimitInKb"]
247247

248-
if options.get("priorityLevel") and options["priorityLevel"].lower() in {"low", "high"}:
248+
if options.get("priorityLevel"):
249249
headers[http_constants.HttpHeaders.PriorityLevel] = options["priorityLevel"]
250250

251251
if cosmos_client_connection.master_key:

sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_integers.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from typing import NoReturn, Tuple, Union
2323

2424

25-
class UInt64:
25+
class _UInt64:
2626
def __init__(self, value: int) -> None:
2727
self._value: int = value & 0xFFFFFFFFFFFFFFFF
2828

@@ -34,43 +34,43 @@ def value(self) -> int:
3434
def value(self, new_value: int) -> None:
3535
self._value = new_value & 0xFFFFFFFFFFFFFFFF
3636

37-
def __add__(self, other: Union[int, 'UInt64']) -> 'UInt64':
38-
result = self.value + (other.value if isinstance(other, UInt64) else other)
39-
return UInt64(result & 0xFFFFFFFFFFFFFFFF)
37+
def __add__(self, other: Union[int, '_UInt64']) -> '_UInt64':
38+
result = self.value + (other.value if isinstance(other, _UInt64) else other)
39+
return _UInt64(result & 0xFFFFFFFFFFFFFFFF)
4040

41-
def __sub__(self, other: Union[int, 'UInt64']) -> 'UInt64':
42-
result = self.value - (other.value if isinstance(other, UInt64) else other)
43-
return UInt64(result & 0xFFFFFFFFFFFFFFFF)
41+
def __sub__(self, other: Union[int, '_UInt64']) -> '_UInt64':
42+
result = self.value - (other.value if isinstance(other, _UInt64) else other)
43+
return _UInt64(result & 0xFFFFFFFFFFFFFFFF)
4444

45-
def __mul__(self, other: Union[int, 'UInt64']) -> 'UInt64':
46-
result = self.value * (other.value if isinstance(other, UInt64) else other)
47-
return UInt64(result & 0xFFFFFFFFFFFFFFFF)
45+
def __mul__(self, other: Union[int, '_UInt64']) -> '_UInt64':
46+
result = self.value * (other.value if isinstance(other, _UInt64) else other)
47+
return _UInt64(result & 0xFFFFFFFFFFFFFFFF)
4848

49-
def __xor__(self, other: Union[int, 'UInt64']) -> 'UInt64':
50-
result = self.value ^ (other.value if isinstance(other, UInt64) else other)
51-
return UInt64(result & 0xFFFFFFFFFFFFFFFF)
49+
def __xor__(self, other: Union[int, '_UInt64']) -> '_UInt64':
50+
result = self.value ^ (other.value if isinstance(other, _UInt64) else other)
51+
return _UInt64(result & 0xFFFFFFFFFFFFFFFF)
5252

53-
def __lshift__(self, other: Union[int, 'UInt64']) -> 'UInt64':
54-
result = self.value << (other.value if isinstance(other, UInt64) else other)
55-
return UInt64(result & 0xFFFFFFFFFFFFFFFF)
53+
def __lshift__(self, other: Union[int, '_UInt64']) -> '_UInt64':
54+
result = self.value << (other.value if isinstance(other, _UInt64) else other)
55+
return _UInt64(result & 0xFFFFFFFFFFFFFFFF)
5656

57-
def __rshift__(self, other: Union[int, 'UInt64']) -> 'UInt64':
58-
result = self.value >> (other.value if isinstance(other, UInt64) else other)
59-
return UInt64(result & 0xFFFFFFFFFFFFFFFF)
57+
def __rshift__(self, other: Union[int, '_UInt64']) -> '_UInt64':
58+
result = self.value >> (other.value if isinstance(other, _UInt64) else other)
59+
return _UInt64(result & 0xFFFFFFFFFFFFFFFF)
6060

61-
def __and__(self, other: Union[int, 'UInt64']) -> 'UInt64':
62-
result = self.value & (other.value if isinstance(other, UInt64) else other)
63-
return UInt64(result & 0xFFFFFFFFFFFFFFFF)
61+
def __and__(self, other: Union[int, '_UInt64']) -> '_UInt64':
62+
result = self.value & (other.value if isinstance(other, _UInt64) else other)
63+
return _UInt64(result & 0xFFFFFFFFFFFFFFFF)
6464

65-
def __or__(self, other: Union[int, 'UInt64']) -> 'UInt64':
66-
if isinstance(other, UInt64):
67-
return UInt64(self.value | other.value)
65+
def __or__(self, other: Union[int, '_UInt64']) -> '_UInt64':
66+
if isinstance(other, _UInt64):
67+
return _UInt64(self.value | other.value)
6868
if isinstance(other, int):
69-
return UInt64(self.value | other)
69+
return _UInt64(self.value | other)
7070
raise TypeError("Unsupported type for OR operation")
7171

72-
def __invert__(self) -> 'UInt64':
73-
return UInt64(~self.value & 0xFFFFFFFFFFFFFFFF)
72+
def __invert__(self) -> '_UInt64':
73+
return _UInt64(~self.value & 0xFFFFFFFFFFFFFFFF)
7474

7575
@staticmethod
7676
def encode_double_as_uint64(value: float) -> int:
@@ -88,62 +88,62 @@ def __int__(self) -> int:
8888
return self.value
8989

9090

91-
class UInt128:
92-
def __init__(self, low: Union[int, UInt64], high: Union[int, UInt64]) -> None:
93-
if isinstance(low, UInt64):
91+
class _UInt128:
92+
def __init__(self, low: Union[int, _UInt64], high: Union[int, _UInt64]) -> None:
93+
if isinstance(low, _UInt64):
9494
self.low = low
9595
else:
96-
self.low = UInt64(low)
97-
if isinstance(high, UInt64):
96+
self.low = _UInt64(low)
97+
if isinstance(high, _UInt64):
9898
self.high = high
9999
else:
100-
self.high = UInt64(high)
100+
self.high = _UInt64(high)
101101

102-
def __add__(self, other: 'UInt128') -> 'UInt128':
102+
def __add__(self, other: '_UInt128') -> '_UInt128':
103103
low = self.low + other.low
104-
high = self.high + other.high + UInt64(int(low.value > 0xFFFFFFFFFFFFFFFF))
105-
return UInt128(low & 0xFFFFFFFFFFFFFFFF, high & 0xFFFFFFFFFFFFFFFF)
104+
high = self.high + other.high + _UInt64(int(low.value > 0xFFFFFFFFFFFFFFFF))
105+
return _UInt128(low & 0xFFFFFFFFFFFFFFFF, high & 0xFFFFFFFFFFFFFFFF)
106106

107-
def __sub__(self, other: 'UInt128') -> 'UInt128':
108-
borrow = UInt64(0)
107+
def __sub__(self, other: '_UInt128') -> '_UInt128':
108+
borrow = _UInt64(0)
109109
if self.low.value < other.low.value:
110-
borrow = UInt64(1)
110+
borrow = _UInt64(1)
111111

112112
low = (self.low - other.low) & 0xFFFFFFFFFFFFFFFF
113113
high = (self.high - other.high - borrow) & 0xFFFFFFFFFFFFFFFF
114-
return UInt128(low, high)
114+
return _UInt128(low, high)
115115

116-
def __mul__(self, other: 'UInt128') -> NoReturn:
116+
def __mul__(self, other: '_UInt128') -> NoReturn:
117117
# Multiplication logic here for 128 bits
118118
raise NotImplementedError()
119119

120-
def __xor__(self, other: 'UInt128') -> 'UInt128':
120+
def __xor__(self, other: '_UInt128') -> '_UInt128':
121121
low = self.low ^ other.low
122122
high = self.high ^ other.high
123-
return UInt128(low, high)
123+
return _UInt128(low, high)
124124

125-
def __and__(self, other: 'UInt128') -> 'UInt128':
125+
def __and__(self, other: '_UInt128') -> '_UInt128':
126126
low = self.low & other.low
127127
high = self.high & other.high
128-
return UInt128(low, high)
128+
return _UInt128(low, high)
129129

130-
def __or__(self, other: 'UInt128') -> 'UInt128':
130+
def __or__(self, other: '_UInt128') -> '_UInt128':
131131
low = self.low | other.low
132132
high = self.high | other.high
133-
return UInt128(low, high)
133+
return _UInt128(low, high)
134134

135-
def __lshift__(self, shift: 'UInt128') -> NoReturn:
135+
def __lshift__(self, shift: '_UInt128') -> NoReturn:
136136
# Left shift logic for 128 bits
137137
raise NotImplementedError()
138138

139-
def __rshift__(self, shift: 'UInt128') -> NoReturn:
139+
def __rshift__(self, shift: '_UInt128') -> NoReturn:
140140
# Right shift logic for 128 bits
141141
raise NotImplementedError()
142142

143-
def get_low(self) -> UInt64:
143+
def get_low(self) -> _UInt64:
144144
return self.low
145145

146-
def get_high(self) -> UInt64:
146+
def get_high(self) -> _UInt64:
147147
return self.high
148148

149149
def as_tuple(self) -> Tuple[int, int]:

sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_murmurhash3.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
# This is public domain code with no copyrights. From home page of
3131
# <a href="https://github.com/aappleby/smhasher">SMHasher</a>:
3232
# "All MurmurHash versions are public domain software, and the author disclaims all copyright to their code."
33-
from ._cosmos_integers import UInt128, UInt64
33+
from ._cosmos_integers import _UInt128, _UInt64
3434

3535

3636
def rotate_left_64(val: int, shift: int) -> int:
3737
return (val << shift) | (val >> (64 - shift))
3838

3939

40-
def mix(value: UInt64) -> UInt64:
40+
def mix(value: _UInt64) -> _UInt64:
4141
value ^= value >> 33
4242
value *= 0xff51afd7ed558ccd
4343
value = value & 0xFFFFFFFFFFFFFFFF
@@ -48,102 +48,102 @@ def mix(value: UInt64) -> UInt64:
4848
return value
4949

5050

51-
def murmurhash3_128(span: bytearray, seed: UInt128) -> UInt128: # pylint: disable=too-many-statements
51+
def murmurhash3_128(span: bytearray, seed: _UInt128) -> _UInt128: # pylint: disable=too-many-statements
5252
"""
5353
Python implementation of 128 bit murmurhash3 from Dot Net SDK. To match with other SDKs, It is recommended to
5454
do the following with number values, especially floats as other SDKs use Doubles
5555
-> bytearray(struct.pack("d", #)) where # represents any number. The d will treat it as a double.
5656
5757
:param bytearray span:
5858
bytearray of value to hash
59-
:param UInt128 seed:
59+
:param _UInt128 seed:
6060
seed value for murmurhash3, takes in a UInt128 value from Cosmos Integers
6161
:return:
6262
The hash value as a UInt128
6363
:rtype:
6464
UInt128
6565
"""
66-
c1 = UInt64(0x87c37b91114253d5)
67-
c2 = UInt64(0x4cf5ad432745937f)
66+
c1 = _UInt64(0x87c37b91114253d5)
67+
c2 = _UInt64(0x4cf5ad432745937f)
6868
h1 = seed.get_low()
6969
h2 = seed.get_high()
7070

7171
position = 0
7272
while position < len(span) - 15:
73-
k1 = UInt64(int.from_bytes(span[position: position + 8], 'little'))
74-
k2 = UInt64(int.from_bytes(span[position + 8: position + 16], 'little'))
73+
k1 = _UInt64(int.from_bytes(span[position: position + 8], 'little'))
74+
k2 = _UInt64(int.from_bytes(span[position + 8: position + 16], 'little'))
7575

7676
k1 *= c1
7777
k1.value = rotate_left_64(k1.value, 31)
7878
k1 *= c2
7979
h1 ^= k1
8080
h1.value = rotate_left_64(h1.value, 27)
8181
h1 += h2
82-
h1 = h1 * 5 + UInt64(0x52dce729)
82+
h1 = h1 * 5 + _UInt64(0x52dce729)
8383

8484
k2 *= c2
8585
k2.value = rotate_left_64(k2.value, 33)
8686
k2 *= c1
8787
h2 ^= k2
8888
h2.value = rotate_left_64(h2.value, 31)
8989
h2 += h1
90-
h2 = h2 * 5 + UInt64(0x38495ab5)
90+
h2 = h2 * 5 + _UInt64(0x38495ab5)
9191

9292
position += 16
9393

94-
k1 = UInt64(0)
95-
k2 = UInt64(0)
94+
k1 = _UInt64(0)
95+
k2 = _UInt64(0)
9696
n = len(span) & 15
9797
if n >= 15:
98-
k2 ^= UInt64(span[position + 14] << 48)
98+
k2 ^= _UInt64(span[position + 14] << 48)
9999
if n >= 14:
100-
k2 ^= UInt64(span[position + 13] << 40)
100+
k2 ^= _UInt64(span[position + 13] << 40)
101101
if n >= 13:
102-
k2 ^= UInt64(span[position + 12] << 32)
102+
k2 ^= _UInt64(span[position + 12] << 32)
103103
if n >= 12:
104-
k2 ^= UInt64(span[position + 11] << 24)
104+
k2 ^= _UInt64(span[position + 11] << 24)
105105
if n >= 11:
106-
k2 ^= UInt64(span[position + 10] << 16)
106+
k2 ^= _UInt64(span[position + 10] << 16)
107107
if n >= 10:
108-
k2 ^= UInt64(span[position + 9] << 8)
108+
k2 ^= _UInt64(span[position + 9] << 8)
109109
if n >= 9:
110-
k2 ^= UInt64(span[position + 8] << 0)
110+
k2 ^= _UInt64(span[position + 8] << 0)
111111

112112
k2 *= c2
113113
k2.value = rotate_left_64(k2.value, 33)
114114
k2 *= c1
115115
h2 ^= k2
116116

117117
if n >= 8:
118-
k1 ^= UInt64(span[position + 7] << 56)
118+
k1 ^= _UInt64(span[position + 7] << 56)
119119
if n >= 7:
120-
k1 ^= UInt64(span[position + 6] << 48)
120+
k1 ^= _UInt64(span[position + 6] << 48)
121121
if n >= 6:
122-
k1 ^= UInt64(span[position + 5] << 40)
122+
k1 ^= _UInt64(span[position + 5] << 40)
123123
if n >= 5:
124-
k1 ^= UInt64(span[position + 4] << 32)
124+
k1 ^= _UInt64(span[position + 4] << 32)
125125
if n >= 4:
126-
k1 ^= UInt64(span[position + 3] << 24)
126+
k1 ^= _UInt64(span[position + 3] << 24)
127127
if n >= 3:
128-
k1 ^= UInt64(span[position + 2] << 16)
128+
k1 ^= _UInt64(span[position + 2] << 16)
129129
if n >= 2:
130-
k1 ^= UInt64(span[position + 1] << 8)
130+
k1 ^= _UInt64(span[position + 1] << 8)
131131
if n >= 1:
132-
k1 ^= UInt64(span[position + 0] << 0)
132+
k1 ^= _UInt64(span[position + 0] << 0)
133133

134134
k1 *= c1
135135
k1.value = rotate_left_64(k1.value, 31)
136136
k1 *= c2
137137
h1 ^= k1
138138

139139
# Finalization
140-
h1 ^= UInt64(len(span))
141-
h2 ^= UInt64(len(span))
140+
h1 ^= _UInt64(len(span))
141+
h2 ^= _UInt64(len(span))
142142
h1 += h2
143143
h2 += h1
144144
h1 = mix(h1)
145145
h2 = mix(h2)
146146
h1 += h2
147147
h2 += h1
148148

149-
return UInt128(int(h1.value), int(h2.value))
149+
return _UInt128(int(h1.value), int(h2.value))

0 commit comments

Comments
 (0)