Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
'is_query_plan_request': 'isQueryPlanRequest',
'supported_query_features': 'supportedQueryFeatures',
'query_version': 'queryVersion',
'priority_level': 'priorityLevel'
'priority': 'priorityLevel'
}

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

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

if cosmos_client_connection.master_key:
Expand Down
104 changes: 52 additions & 52 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_integers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import NoReturn, Tuple, Union


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

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

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

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

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

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

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

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

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

def __or__(self, other: Union[int, 'UInt64']) -> 'UInt64':
if isinstance(other, UInt64):
return UInt64(self.value | other.value)
def __or__(self, other: Union[int, '_UInt64']) -> '_UInt64':
if isinstance(other, _UInt64):
return _UInt64(self.value | other.value)
if isinstance(other, int):
return UInt64(self.value | other)
return _UInt64(self.value | other)
raise TypeError("Unsupported type for OR operation")

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

@staticmethod
def encode_double_as_uint64(value: float) -> int:
Expand All @@ -88,62 +88,62 @@ def __int__(self) -> int:
return self.value


class UInt128:
def __init__(self, low: Union[int, UInt64], high: Union[int, UInt64]) -> None:
if isinstance(low, UInt64):
class _UInt128:
def __init__(self, low: Union[int, _UInt64], high: Union[int, _UInt64]) -> None:
if isinstance(low, _UInt64):
self.low = low
else:
self.low = UInt64(low)
if isinstance(high, UInt64):
self.low = _UInt64(low)
if isinstance(high, _UInt64):
self.high = high
else:
self.high = UInt64(high)
self.high = _UInt64(high)

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

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

low = (self.low - other.low) & 0xFFFFFFFFFFFFFFFF
high = (self.high - other.high - borrow) & 0xFFFFFFFFFFFFFFFF
return UInt128(low, high)
return _UInt128(low, high)

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

def __xor__(self, other: 'UInt128') -> 'UInt128':
def __xor__(self, other: '_UInt128') -> '_UInt128':
low = self.low ^ other.low
high = self.high ^ other.high
return UInt128(low, high)
return _UInt128(low, high)

def __and__(self, other: 'UInt128') -> 'UInt128':
def __and__(self, other: '_UInt128') -> '_UInt128':
low = self.low & other.low
high = self.high & other.high
return UInt128(low, high)
return _UInt128(low, high)

def __or__(self, other: 'UInt128') -> 'UInt128':
def __or__(self, other: '_UInt128') -> '_UInt128':
low = self.low | other.low
high = self.high | other.high
return UInt128(low, high)
return _UInt128(low, high)

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

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

def get_low(self) -> UInt64:
def get_low(self) -> _UInt64:
return self.low

def get_high(self) -> UInt64:
def get_high(self) -> _UInt64:
return self.high

def as_tuple(self) -> Tuple[int, int]:
Expand Down
60 changes: 30 additions & 30 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_murmurhash3.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
# This is public domain code with no copyrights. From home page of
# <a href="https://github.com/aappleby/smhasher">SMHasher</a>:
# "All MurmurHash versions are public domain software, and the author disclaims all copyright to their code."
from ._cosmos_integers import UInt128, UInt64
from ._cosmos_integers import _UInt128, _UInt64


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


def mix(value: UInt64) -> UInt64:
def mix(value: _UInt64) -> _UInt64:
value ^= value >> 33
value *= 0xff51afd7ed558ccd
value = value & 0xFFFFFFFFFFFFFFFF
Expand All @@ -48,102 +48,102 @@ def mix(value: UInt64) -> UInt64:
return value


def murmurhash3_128(span: bytearray, seed: UInt128) -> UInt128: # pylint: disable=too-many-statements
def murmurhash3_128(span: bytearray, seed: _UInt128) -> _UInt128: # pylint: disable=too-many-statements
"""
Python implementation of 128 bit murmurhash3 from Dot Net SDK. To match with other SDKs, It is recommended to
do the following with number values, especially floats as other SDKs use Doubles
-> bytearray(struct.pack("d", #)) where # represents any number. The d will treat it as a double.

:param bytearray span:
bytearray of value to hash
:param UInt128 seed:
:param _UInt128 seed:
seed value for murmurhash3, takes in a UInt128 value from Cosmos Integers
:return:
The hash value as a UInt128
:rtype:
UInt128
"""
c1 = UInt64(0x87c37b91114253d5)
c2 = UInt64(0x4cf5ad432745937f)
c1 = _UInt64(0x87c37b91114253d5)
c2 = _UInt64(0x4cf5ad432745937f)
h1 = seed.get_low()
h2 = seed.get_high()

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

k1 *= c1
k1.value = rotate_left_64(k1.value, 31)
k1 *= c2
h1 ^= k1
h1.value = rotate_left_64(h1.value, 27)
h1 += h2
h1 = h1 * 5 + UInt64(0x52dce729)
h1 = h1 * 5 + _UInt64(0x52dce729)

k2 *= c2
k2.value = rotate_left_64(k2.value, 33)
k2 *= c1
h2 ^= k2
h2.value = rotate_left_64(h2.value, 31)
h2 += h1
h2 = h2 * 5 + UInt64(0x38495ab5)
h2 = h2 * 5 + _UInt64(0x38495ab5)

position += 16

k1 = UInt64(0)
k2 = UInt64(0)
k1 = _UInt64(0)
k2 = _UInt64(0)
n = len(span) & 15
if n >= 15:
k2 ^= UInt64(span[position + 14] << 48)
k2 ^= _UInt64(span[position + 14] << 48)
if n >= 14:
k2 ^= UInt64(span[position + 13] << 40)
k2 ^= _UInt64(span[position + 13] << 40)
if n >= 13:
k2 ^= UInt64(span[position + 12] << 32)
k2 ^= _UInt64(span[position + 12] << 32)
if n >= 12:
k2 ^= UInt64(span[position + 11] << 24)
k2 ^= _UInt64(span[position + 11] << 24)
if n >= 11:
k2 ^= UInt64(span[position + 10] << 16)
k2 ^= _UInt64(span[position + 10] << 16)
if n >= 10:
k2 ^= UInt64(span[position + 9] << 8)
k2 ^= _UInt64(span[position + 9] << 8)
if n >= 9:
k2 ^= UInt64(span[position + 8] << 0)
k2 ^= _UInt64(span[position + 8] << 0)

k2 *= c2
k2.value = rotate_left_64(k2.value, 33)
k2 *= c1
h2 ^= k2

if n >= 8:
k1 ^= UInt64(span[position + 7] << 56)
k1 ^= _UInt64(span[position + 7] << 56)
if n >= 7:
k1 ^= UInt64(span[position + 6] << 48)
k1 ^= _UInt64(span[position + 6] << 48)
if n >= 6:
k1 ^= UInt64(span[position + 5] << 40)
k1 ^= _UInt64(span[position + 5] << 40)
if n >= 5:
k1 ^= UInt64(span[position + 4] << 32)
k1 ^= _UInt64(span[position + 4] << 32)
if n >= 4:
k1 ^= UInt64(span[position + 3] << 24)
k1 ^= _UInt64(span[position + 3] << 24)
if n >= 3:
k1 ^= UInt64(span[position + 2] << 16)
k1 ^= _UInt64(span[position + 2] << 16)
if n >= 2:
k1 ^= UInt64(span[position + 1] << 8)
k1 ^= _UInt64(span[position + 1] << 8)
if n >= 1:
k1 ^= UInt64(span[position + 0] << 0)
k1 ^= _UInt64(span[position + 0] << 0)

k1 *= c1
k1.value = rotate_left_64(k1.value, 31)
k1 *= c2
h1 ^= k1

# Finalization
h1 ^= UInt64(len(span))
h2 ^= UInt64(len(span))
h1 ^= _UInt64(len(span))
h2 ^= _UInt64(len(span))
h1 += h2
h2 += h1
h1 = mix(h1)
h2 = mix(h2)
h1 += h2
h2 += h1

return UInt128(int(h1.value), int(h2.value))
return _UInt128(int(h1.value), int(h2.value))
Loading