Skip to content

Commit

Permalink
move pytest-runner to test-deps; add new pmap type (#40)
Browse files Browse the repository at this point in the history
move pytest-runner to test-deps; add new pmap type
  • Loading branch information
oberstet committed Jan 28, 2022
1 parent b786d68 commit 7cacc39
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@
'numpy>=1.20.1',
]

setup_requirements = ['pytest-runner', ]

test_requirements = ['pytest', ]
# setup_requirements = ['pytest-runner']
test_requirements = ['pytest', 'pytest-runner']

packages = [
'flatbuffers',
Expand Down Expand Up @@ -97,7 +96,7 @@
keywords='zlmdb',
name='zlmdb',
packages=packages,
setup_requires=setup_requirements,
# setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/crossbario/zlmdb',
Expand Down
2 changes: 2 additions & 0 deletions zlmdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MapOidTimestampOid, \
MapOidTimestampFlatBuffers, \
MapOidTimestampStringOid, \
MapUint16UuidTimestampFlatBuffers, \
MapBytes32Uuid, \
MapBytes32Timestamp, \
MapBytes32Bytes32, \
Expand Down Expand Up @@ -152,6 +153,7 @@
'MapUuidBytes20Uint8FlatBuffers',
'MapUuidBytes20Uint8UuidFlatBuffers',
'MapUuidBytes20Bytes20Uint8UuidFlatBuffers',
'MapUint16UuidTimestampFlatBuffers',

# UUID (uint128) based pmap types for indexes
'MapUuidUuid',
Expand Down
10 changes: 10 additions & 0 deletions zlmdb/_pmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,16 @@ def __init__(self, slot=None, compress=None, build=None, cast=None):
_types._FlatBuffersValuesMixin.__init__(self, build=build, cast=cast)


class MapUint16UuidTimestampFlatBuffers(_types._Uint16UuidTimestampKeysMixin, _types._FlatBuffersValuesMixin,
PersistentMap):
"""
Persistent map with (uint16, UUID, Timestamp) keys and FlatBuffers values.
"""
def __init__(self, slot=None, compress=None, build=None, cast=None):
PersistentMap.__init__(self, slot=slot, compress=compress)
_types._FlatBuffersValuesMixin.__init__(self, build=build, cast=cast)


class MapUuidBytes20Uint8FlatBuffers(_types._UuidBytes20Uint8KeysMixin, _types._FlatBuffersValuesMixin, PersistentMap):
"""
Persistent map with (UUID, bytes[20], uint8) keys and FlatBuffers values.
Expand Down
29 changes: 29 additions & 0 deletions zlmdb/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,35 @@ def _deserialize_key(self, data):
return uuid.UUID(bytes=data1), uuid.UUID(bytes=data2)


class _Uint16UuidTimestampKeysMixin(object):
@staticmethod
def new_key():
return random.randint(0, 2**16), uuid.uuid4(), np.datetime64(time_ns(), 'ns')

def _serialize_key(self, key1_key2_key3):
assert type(key1_key2_key3) == tuple and len(key1_key2_key3) == 3
key1, key2, key3 = key1_key2_key3

if key1 is None:
key1 = 0
if key2 is None:
key2 = uuid.UUID(bytes=b'\x00' * 16)
if key3 is None:
key3 = np.datetime64(0, 'ns')

assert type(key1) == int and key1 >= 0 and key1 < 2**16
assert isinstance(key2, uuid.UUID)
assert isinstance(key3, np.datetime64)

return struct.pack('H', key1) + key2.bytes + dt_to_bytes(key3)

def _deserialize_key(self, data):
assert type(data) == bytes and len(data) == (2 + 16 + 8)

data1, data2, data3 = data[0:2], data[2:18], data[18:26],
return struct.unpack('H', data1), uuid.UUID(bytes=data2), bytes_to_dt(data3)


class _UuidBytes20Uint8KeysMixin(object):
@staticmethod
def new_key():
Expand Down
2 changes: 1 addition & 1 deletion zlmdb/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
#
###############################################################################

__version__ = u'22.1.1'
__version__ = u'22.1.2'

0 comments on commit 7cacc39

Please sign in to comment.