zlmdb 25.10.1__cp311-cp311-macosx_10_9_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of zlmdb might be problematic. Click here for more details.
- flatbuffers/__init__.py +19 -0
- flatbuffers/_version.py +17 -0
- flatbuffers/builder.py +776 -0
- flatbuffers/compat.py +86 -0
- flatbuffers/encode.py +42 -0
- flatbuffers/flexbuffers.py +1527 -0
- flatbuffers/number_types.py +181 -0
- flatbuffers/packer.py +42 -0
- flatbuffers/reflection/AdvancedFeatures.py +10 -0
- flatbuffers/reflection/BaseType.py +24 -0
- flatbuffers/reflection/Enum.py +169 -0
- flatbuffers/reflection/EnumVal.py +96 -0
- flatbuffers/reflection/Field.py +208 -0
- flatbuffers/reflection/KeyValue.py +56 -0
- flatbuffers/reflection/Object.py +175 -0
- flatbuffers/reflection/RPCCall.py +131 -0
- flatbuffers/reflection/Schema.py +206 -0
- flatbuffers/reflection/SchemaFile.py +77 -0
- flatbuffers/reflection/Service.py +145 -0
- flatbuffers/reflection/Type.py +98 -0
- flatbuffers/reflection/__init__.py +0 -0
- flatbuffers/table.py +129 -0
- flatbuffers/util.py +43 -0
- zlmdb/__init__.py +312 -0
- zlmdb/_database.py +990 -0
- zlmdb/_errors.py +31 -0
- zlmdb/_meta.py +27 -0
- zlmdb/_pmap.py +1667 -0
- zlmdb/_schema.py +137 -0
- zlmdb/_transaction.py +181 -0
- zlmdb/_types.py +1596 -0
- zlmdb/_version.py +27 -0
- zlmdb/cli.py +41 -0
- zlmdb/flatbuffers/__init__.py +5 -0
- zlmdb/flatbuffers/reflection/AdvancedFeatures.py +10 -0
- zlmdb/flatbuffers/reflection/BaseType.py +25 -0
- zlmdb/flatbuffers/reflection/Enum.py +252 -0
- zlmdb/flatbuffers/reflection/EnumVal.py +144 -0
- zlmdb/flatbuffers/reflection/Field.py +325 -0
- zlmdb/flatbuffers/reflection/KeyValue.py +84 -0
- zlmdb/flatbuffers/reflection/Object.py +260 -0
- zlmdb/flatbuffers/reflection/RPCCall.py +195 -0
- zlmdb/flatbuffers/reflection/Schema.py +301 -0
- zlmdb/flatbuffers/reflection/SchemaFile.py +112 -0
- zlmdb/flatbuffers/reflection/Service.py +213 -0
- zlmdb/flatbuffers/reflection/Type.py +148 -0
- zlmdb/flatbuffers/reflection/__init__.py +0 -0
- zlmdb/flatbuffers/reflection.fbs +152 -0
- zlmdb/lmdb/__init__.py +37 -0
- zlmdb/lmdb/__main__.py +25 -0
- zlmdb/lmdb/_config.py +10 -0
- zlmdb/lmdb/_lmdb_cffi.cpython-311-darwin.so +0 -0
- zlmdb/lmdb/cffi.py +2606 -0
- zlmdb/lmdb/tool.py +670 -0
- zlmdb/tests/lmdb/__init__.py +0 -0
- zlmdb/tests/lmdb/address_book.py +287 -0
- zlmdb/tests/lmdb/crash_test.py +339 -0
- zlmdb/tests/lmdb/cursor_test.py +333 -0
- zlmdb/tests/lmdb/env_test.py +919 -0
- zlmdb/tests/lmdb/getmulti_test.py +92 -0
- zlmdb/tests/lmdb/iteration_test.py +258 -0
- zlmdb/tests/lmdb/package_test.py +70 -0
- zlmdb/tests/lmdb/test_lmdb.py +188 -0
- zlmdb/tests/lmdb/testlib.py +185 -0
- zlmdb/tests/lmdb/tool_test.py +60 -0
- zlmdb/tests/lmdb/txn_test.py +575 -0
- zlmdb/tests/orm/MNodeLog.py +853 -0
- zlmdb/tests/orm/__init__.py +0 -0
- zlmdb/tests/orm/_schema_fbs.py +215 -0
- zlmdb/tests/orm/_schema_mnode_log.py +1201 -0
- zlmdb/tests/orm/_schema_py2.py +250 -0
- zlmdb/tests/orm/_schema_py3.py +307 -0
- zlmdb/tests/orm/_test_flatbuffers.py +144 -0
- zlmdb/tests/orm/_test_serialization.py +144 -0
- zlmdb/tests/orm/test_basic.py +217 -0
- zlmdb/tests/orm/test_etcd.py +275 -0
- zlmdb/tests/orm/test_pmap_indexes.py +466 -0
- zlmdb/tests/orm/test_pmap_types.py +90 -0
- zlmdb/tests/orm/test_pmaps.py +295 -0
- zlmdb/tests/orm/test_select.py +619 -0
- zlmdb-25.10.1.dist-info/METADATA +264 -0
- zlmdb-25.10.1.dist-info/RECORD +87 -0
- zlmdb-25.10.1.dist-info/WHEEL +5 -0
- zlmdb-25.10.1.dist-info/entry_points.txt +2 -0
- zlmdb-25.10.1.dist-info/licenses/LICENSE +137 -0
- zlmdb-25.10.1.dist-info/licenses/NOTICE +41 -0
- zlmdb-25.10.1.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# The MIT License (MIT)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) typedef int GmbH
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
###############################################################################
|
|
26
|
+
|
|
27
|
+
import random
|
|
28
|
+
import uuid
|
|
29
|
+
import datetime
|
|
30
|
+
import zlmdb
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class User(object):
|
|
34
|
+
def __init__(self):
|
|
35
|
+
self.oid = None
|
|
36
|
+
self.name = None
|
|
37
|
+
self.authid = None
|
|
38
|
+
self.uuid = None
|
|
39
|
+
self.email = None
|
|
40
|
+
self.birthday = None
|
|
41
|
+
self.is_friendly = None
|
|
42
|
+
self.tags = None
|
|
43
|
+
self.ratings = {}
|
|
44
|
+
self.friends = []
|
|
45
|
+
self.referred_by = None
|
|
46
|
+
self.realm_oid = None
|
|
47
|
+
self.icecream = None
|
|
48
|
+
self.mrealm = None
|
|
49
|
+
self.mrealm_notnull = None
|
|
50
|
+
|
|
51
|
+
def __eq__(self, other):
|
|
52
|
+
if not isinstance(other, self.__class__):
|
|
53
|
+
return False
|
|
54
|
+
if other.oid != self.oid:
|
|
55
|
+
return False
|
|
56
|
+
if other.name != self.name:
|
|
57
|
+
return False
|
|
58
|
+
if other.authid != self.authid:
|
|
59
|
+
return False
|
|
60
|
+
if other.uuid != self.uuid:
|
|
61
|
+
return False
|
|
62
|
+
if other.email != self.email:
|
|
63
|
+
return False
|
|
64
|
+
if other.birthday != self.birthday:
|
|
65
|
+
return False
|
|
66
|
+
if other.is_friendly != self.is_friendly:
|
|
67
|
+
return False
|
|
68
|
+
if (self.tags and not other.tags) or (not self.tags and other.tags):
|
|
69
|
+
return False
|
|
70
|
+
if other.realm_oid != self.realm_oid:
|
|
71
|
+
return False
|
|
72
|
+
if other.icecream != self.icecream:
|
|
73
|
+
return False
|
|
74
|
+
if other.mrealm != self.mrealm:
|
|
75
|
+
return False
|
|
76
|
+
if other.mrealm_notnull != self.mrealm_notnull:
|
|
77
|
+
return False
|
|
78
|
+
return True
|
|
79
|
+
|
|
80
|
+
def __ne__(self, other):
|
|
81
|
+
return not self.__eq__(other)
|
|
82
|
+
|
|
83
|
+
def marshal(self):
|
|
84
|
+
obj = {
|
|
85
|
+
"oid": self.oid,
|
|
86
|
+
"name": self.name,
|
|
87
|
+
"authid": self.authid,
|
|
88
|
+
"uuid": self.uuid.hex if self.uuid else None,
|
|
89
|
+
"email": self.email,
|
|
90
|
+
"birthday": {
|
|
91
|
+
"year": self.birthday.year if self.birthday else None,
|
|
92
|
+
"month": self.birthday.month if self.birthday else None,
|
|
93
|
+
"day": self.birthday.day if self.birthday else None,
|
|
94
|
+
},
|
|
95
|
+
"is_friendly": self.is_friendly,
|
|
96
|
+
"tags": self.tags,
|
|
97
|
+
"ratings": self.ratings,
|
|
98
|
+
"friends": self.friends,
|
|
99
|
+
"referred_by": self.referred_by,
|
|
100
|
+
"realm_oid": self.realm_oid,
|
|
101
|
+
"icecream": self.icecream,
|
|
102
|
+
"mrealm": self.mrealm.hex if self.mrealm else None,
|
|
103
|
+
"mrealm_notnull": self.mrealm_notnull.hex if self.mrealm_notnull else None,
|
|
104
|
+
}
|
|
105
|
+
return obj
|
|
106
|
+
|
|
107
|
+
@staticmethod
|
|
108
|
+
def parse(obj):
|
|
109
|
+
user = User()
|
|
110
|
+
user.oid = obj.get("oid", None)
|
|
111
|
+
user.name = obj.get("name", None)
|
|
112
|
+
user.authid = obj.get("authid", None)
|
|
113
|
+
if "uuid" in obj:
|
|
114
|
+
user.uuid = uuid.UUID(hex=obj["uuid"])
|
|
115
|
+
user.email = obj.get("email", None)
|
|
116
|
+
if "birthday" in obj:
|
|
117
|
+
b = obj["birthday"]
|
|
118
|
+
user.birthday = datetime.date(b.year, b.month, b.day)
|
|
119
|
+
user.is_friendly = obj.get("is_friendly", None)
|
|
120
|
+
user.tags = obj.get("tags", None)
|
|
121
|
+
user.ratings = obj.get("ratings", {})
|
|
122
|
+
user.friends = obj.get("friends", [])
|
|
123
|
+
user.referred_by = obj.get("referred_by", None)
|
|
124
|
+
user.realm_oid = obj.get("realm_oid", None)
|
|
125
|
+
user.icecream = obj.get("icecream", None)
|
|
126
|
+
if "mrealm" in obj and obj["mrealm"]:
|
|
127
|
+
user.mrealm = uuid.UUID(hex=obj["mrealm"])
|
|
128
|
+
if "mrealm_notnull" in obj and obj["mrealm_notnull"]:
|
|
129
|
+
user.mrealm_notnull = uuid.UUID(hex=obj["mrealm_notnull"])
|
|
130
|
+
return user
|
|
131
|
+
|
|
132
|
+
@staticmethod
|
|
133
|
+
def create_test_user(oid=None, realm_oid=None):
|
|
134
|
+
user = User()
|
|
135
|
+
if oid is not None:
|
|
136
|
+
user.oid = oid
|
|
137
|
+
else:
|
|
138
|
+
user.oid = random.randint(0, 9007199254740992)
|
|
139
|
+
user.name = "Test {}".format(user.oid)
|
|
140
|
+
user.authid = "test-{}".format(user.oid)
|
|
141
|
+
user.uuid = uuid.uuid4()
|
|
142
|
+
user.email = "{}@example.com".format(user.authid)
|
|
143
|
+
user.birthday = datetime.date(1950, 12, 24)
|
|
144
|
+
user.is_friendly = True
|
|
145
|
+
user.tags = ["geek", "sudoko", "yellow"]
|
|
146
|
+
for j in range(10):
|
|
147
|
+
user.ratings["test-rating-{}".format(j)] = random.random()
|
|
148
|
+
user.friends = [random.randint(0, 9007199254740992) for _ in range(10)]
|
|
149
|
+
user.referred_by = random.randint(0, 9007199254740992)
|
|
150
|
+
if realm_oid is not None:
|
|
151
|
+
user.realm_oid = realm_oid
|
|
152
|
+
else:
|
|
153
|
+
user.realm_oid = random.randint(0, 9007199254740992)
|
|
154
|
+
user.icecream = random.choice(["vanilla", "lemon", "strawberry"])
|
|
155
|
+
user.mrealm = uuid.uuid4()
|
|
156
|
+
user.mrealm_notnull = uuid.uuid4()
|
|
157
|
+
return user
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class Schema1(zlmdb.Schema):
|
|
161
|
+
def __init__(self):
|
|
162
|
+
super(Schema1, self).__init__()
|
|
163
|
+
|
|
164
|
+
self.tab_uuid_str = zlmdb.MapUuidString(slot=1)
|
|
165
|
+
self.tab_uuid_oid = zlmdb.MapUuidOid(slot=2)
|
|
166
|
+
self.tab_uuid_uuid = zlmdb.MapUuidUuid(slot=3)
|
|
167
|
+
self.tab_str_str = zlmdb.MapStringString(slot=4)
|
|
168
|
+
self.tab_str_oid = zlmdb.MapStringOid(slot=5)
|
|
169
|
+
self.tab_str_uuid = zlmdb.MapStringUuid(slot=6)
|
|
170
|
+
self.tab_oid_str = zlmdb.MapOidString(slot=7)
|
|
171
|
+
self.tab_oid_oid = zlmdb.MapOidOid(slot=8)
|
|
172
|
+
self.tab_oid_uuid = zlmdb.MapOidUuid(slot=9)
|
|
173
|
+
self.tab_uuid_json = zlmdb.MapUuidJson(
|
|
174
|
+
slot=10, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
175
|
+
)
|
|
176
|
+
self.tab_uuid_cbor = zlmdb.MapUuidCbor(
|
|
177
|
+
slot=11, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
178
|
+
)
|
|
179
|
+
self.tab_uuid_pickle = zlmdb.MapUuidPickle(slot=12)
|
|
180
|
+
self.tab_str_json = zlmdb.MapStringJson(
|
|
181
|
+
slot=20, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
182
|
+
)
|
|
183
|
+
self.tab_str_cbor = zlmdb.MapStringCbor(
|
|
184
|
+
slot=21, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
185
|
+
)
|
|
186
|
+
self.tab_str_pickle = zlmdb.MapStringPickle(slot=22)
|
|
187
|
+
self.tab_oid_json = zlmdb.MapOidJson(
|
|
188
|
+
slot=30, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
189
|
+
)
|
|
190
|
+
self.tab_oid_cbor = zlmdb.MapOidCbor(
|
|
191
|
+
slot=31, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
192
|
+
)
|
|
193
|
+
self.tab_oid_pickle = zlmdb.MapOidPickle(slot=32)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class Schema2(zlmdb.Schema):
|
|
197
|
+
def __init__(self):
|
|
198
|
+
super(Schema2, self).__init__()
|
|
199
|
+
self.users = zlmdb.MapOidPickle(1)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class Schema3(zlmdb.Schema):
|
|
203
|
+
def __init__(self):
|
|
204
|
+
super(Schema3, self).__init__()
|
|
205
|
+
self.users = zlmdb.MapStringPickle(1)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class Schema4(zlmdb.Schema):
|
|
209
|
+
def __init__(self):
|
|
210
|
+
super(Schema4, self).__init__()
|
|
211
|
+
self.users = zlmdb.MapOidPickle(1)
|
|
212
|
+
|
|
213
|
+
self.idx_users_by_authid = zlmdb.MapStringOid(2)
|
|
214
|
+
self.users.attach_index(
|
|
215
|
+
"idx1", self.idx_users_by_authid, lambda user: user.authid, nullable=False
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
self.idx_users_by_email = zlmdb.MapStringOid(3)
|
|
219
|
+
self.users.attach_index(
|
|
220
|
+
"idx2", self.idx_users_by_email, lambda user: user.email, nullable=True
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
self.idx_users_by_realm = zlmdb.MapOidOidOid(4)
|
|
224
|
+
self.users.attach_index(
|
|
225
|
+
"idx3", self.idx_users_by_realm, lambda user: (user.realm_oid, user.oid)
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
self.idx_users_by_icecream = zlmdb.MapStringOidOid(5)
|
|
229
|
+
self.users.attach_index(
|
|
230
|
+
"idx4",
|
|
231
|
+
self.idx_users_by_icecream,
|
|
232
|
+
lambda user: (user.icecream, user.oid),
|
|
233
|
+
nullable=False,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
self.idx_users_by_mrealm_authid = zlmdb.MapUuidStringOid(6)
|
|
237
|
+
self.users.attach_index(
|
|
238
|
+
"idx5",
|
|
239
|
+
self.idx_users_by_mrealm_authid,
|
|
240
|
+
lambda user: (user.mrealm, user.authid),
|
|
241
|
+
nullable=True,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
self.idx_users_by_mrealm_notnull_authid = zlmdb.MapUuidStringOid(7)
|
|
245
|
+
self.users.attach_index(
|
|
246
|
+
"idx6",
|
|
247
|
+
self.idx_users_by_mrealm_notnull_authid,
|
|
248
|
+
lambda user: (user.mrealm_notnull, user.authid),
|
|
249
|
+
nullable=False,
|
|
250
|
+
)
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# The MIT License (MIT)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) typedef int GmbH
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
###############################################################################
|
|
26
|
+
|
|
27
|
+
import random
|
|
28
|
+
import uuid
|
|
29
|
+
import datetime
|
|
30
|
+
from typing import Optional, List, Dict
|
|
31
|
+
|
|
32
|
+
import zlmdb
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class User(object):
|
|
36
|
+
oid: int
|
|
37
|
+
name: str
|
|
38
|
+
authid: str
|
|
39
|
+
uuid: uuid.UUID
|
|
40
|
+
email: str
|
|
41
|
+
birthday: datetime.date
|
|
42
|
+
is_friendly: bool
|
|
43
|
+
tags: Optional[List[str]]
|
|
44
|
+
ratings: Dict[str, float]
|
|
45
|
+
friends: List[int]
|
|
46
|
+
referred_by: int
|
|
47
|
+
realm_oid: int
|
|
48
|
+
icecream: str
|
|
49
|
+
mrealm: uuid.UUID # type:ignore
|
|
50
|
+
mrealm_notnull: uuid.UUID # type:ignore
|
|
51
|
+
|
|
52
|
+
def __init__(self):
|
|
53
|
+
self.oid = None
|
|
54
|
+
self.name = None
|
|
55
|
+
self.authid = None
|
|
56
|
+
self.uuid = None
|
|
57
|
+
self.email = None
|
|
58
|
+
self.birthday = None
|
|
59
|
+
self.is_friendly = None
|
|
60
|
+
self.tags = None
|
|
61
|
+
self.ratings = {}
|
|
62
|
+
self.friends = []
|
|
63
|
+
self.referred_by = None
|
|
64
|
+
self.realm_oid = None
|
|
65
|
+
self.icecream = None
|
|
66
|
+
self.mrealm = None
|
|
67
|
+
self.mrealm_notnull = None
|
|
68
|
+
|
|
69
|
+
def __eq__(self, other):
|
|
70
|
+
if not isinstance(other, self.__class__):
|
|
71
|
+
return False
|
|
72
|
+
if other.oid != self.oid:
|
|
73
|
+
return False
|
|
74
|
+
if other.name != self.name:
|
|
75
|
+
return False
|
|
76
|
+
if other.authid != self.authid:
|
|
77
|
+
return False
|
|
78
|
+
if other.uuid != self.uuid:
|
|
79
|
+
return False
|
|
80
|
+
if other.email != self.email:
|
|
81
|
+
return False
|
|
82
|
+
if other.birthday != self.birthday:
|
|
83
|
+
return False
|
|
84
|
+
if other.is_friendly != self.is_friendly:
|
|
85
|
+
return False
|
|
86
|
+
if (self.tags and not other.tags) or (not self.tags and other.tags):
|
|
87
|
+
return False
|
|
88
|
+
if other.realm_oid != self.realm_oid:
|
|
89
|
+
return False
|
|
90
|
+
if other.icecream != self.icecream:
|
|
91
|
+
return False
|
|
92
|
+
if other.mrealm != self.mrealm:
|
|
93
|
+
return False
|
|
94
|
+
if other.mrealm_notnull != self.mrealm_notnull:
|
|
95
|
+
return False
|
|
96
|
+
return True
|
|
97
|
+
|
|
98
|
+
def __ne__(self, other):
|
|
99
|
+
return not self.__eq__(other)
|
|
100
|
+
|
|
101
|
+
def marshal(self):
|
|
102
|
+
obj = {
|
|
103
|
+
"oid": self.oid,
|
|
104
|
+
"name": self.name,
|
|
105
|
+
"authid": self.authid,
|
|
106
|
+
"uuid": self.uuid.hex if self.uuid else None,
|
|
107
|
+
"email": self.email,
|
|
108
|
+
"birthday": {
|
|
109
|
+
"year": self.birthday.year if self.birthday else None,
|
|
110
|
+
"month": self.birthday.month if self.birthday else None,
|
|
111
|
+
"day": self.birthday.day if self.birthday else None,
|
|
112
|
+
},
|
|
113
|
+
"is_friendly": self.is_friendly,
|
|
114
|
+
"tags": self.tags,
|
|
115
|
+
"ratings": self.ratings,
|
|
116
|
+
"friends": self.friends,
|
|
117
|
+
"referred_by": self.referred_by,
|
|
118
|
+
"realm_oid": self.realm_oid,
|
|
119
|
+
"icecream": self.icecream,
|
|
120
|
+
"mrealm": self.mrealm.hex if self.mrealm else None,
|
|
121
|
+
"mrealm_notnull": self.mrealm_notnull.hex if self.mrealm_notnull else None,
|
|
122
|
+
}
|
|
123
|
+
return obj
|
|
124
|
+
|
|
125
|
+
@staticmethod
|
|
126
|
+
def parse(obj):
|
|
127
|
+
user = User()
|
|
128
|
+
user.oid = obj.get("oid", None)
|
|
129
|
+
user.name = obj.get("name", None)
|
|
130
|
+
user.authid = obj.get("authid", None)
|
|
131
|
+
if "uuid" in obj:
|
|
132
|
+
user.uuid = uuid.UUID(hex=obj["uuid"])
|
|
133
|
+
user.email = obj.get("email", None)
|
|
134
|
+
if "birthday" in obj:
|
|
135
|
+
b = obj["birthday"]
|
|
136
|
+
user.birthday = datetime.date(b.year, b.month, b.day)
|
|
137
|
+
user.is_friendly = obj.get("is_friendly", None)
|
|
138
|
+
user.tags = obj.get("tags", None)
|
|
139
|
+
user.ratings = obj.get("ratings", {})
|
|
140
|
+
user.friends = obj.get("friends", [])
|
|
141
|
+
user.referred_by = obj.get("referred_by", None)
|
|
142
|
+
user.realm_oid = obj.get("realm_oid", None)
|
|
143
|
+
user.icecream = obj.get("icecream", None)
|
|
144
|
+
if "mrealm" in obj and obj["mrealm"]:
|
|
145
|
+
user.mrealm = uuid.UUID(hex=obj["mrealm"])
|
|
146
|
+
if "mrealm_notnull" in obj and obj["mrealm_notnull"]:
|
|
147
|
+
user.mrealm_notnull = uuid.UUID(hex=obj["mrealm_notnull"])
|
|
148
|
+
return user
|
|
149
|
+
|
|
150
|
+
@staticmethod
|
|
151
|
+
def create_test_user(oid=None, realm_oid=None):
|
|
152
|
+
user = User()
|
|
153
|
+
if oid is not None:
|
|
154
|
+
user.oid = oid
|
|
155
|
+
else:
|
|
156
|
+
user.oid = random.randint(0, 9007199254740992)
|
|
157
|
+
user.name = "Test {}".format(user.oid)
|
|
158
|
+
user.authid = "test-{}".format(user.oid)
|
|
159
|
+
user.uuid = uuid.uuid4()
|
|
160
|
+
user.email = "{}@example.com".format(user.authid)
|
|
161
|
+
user.birthday = datetime.date(1950, 12, 24)
|
|
162
|
+
user.is_friendly = True
|
|
163
|
+
user.tags = ["geek", "sudoko", "yellow"]
|
|
164
|
+
for j in range(10):
|
|
165
|
+
user.ratings["test-rating-{}".format(j)] = 1 / (
|
|
166
|
+
j + 1
|
|
167
|
+
) # round(random.random(), 3)
|
|
168
|
+
user.friends = [random.randint(0, 9007199254740992) for _ in range(10)]
|
|
169
|
+
user.referred_by = random.randint(0, 9007199254740992)
|
|
170
|
+
if realm_oid is not None:
|
|
171
|
+
user.realm_oid = realm_oid
|
|
172
|
+
else:
|
|
173
|
+
user.realm_oid = random.randint(0, 9007199254740992)
|
|
174
|
+
user.icecream = random.choice(["vanilla", "lemon", "strawberry"])
|
|
175
|
+
user.mrealm = uuid.uuid4()
|
|
176
|
+
user.mrealm_notnull = uuid.uuid4()
|
|
177
|
+
return user
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class Schema1(zlmdb.Schema):
|
|
181
|
+
tab_uuid_str: zlmdb.MapUuidString
|
|
182
|
+
tab_uuid_oid: zlmdb.MapUuidOid
|
|
183
|
+
tab_uuid_uuid: zlmdb.MapUuidUuid
|
|
184
|
+
tab_str_str: zlmdb.MapStringString
|
|
185
|
+
tab_str_oid: zlmdb.MapStringOid
|
|
186
|
+
tab_str_uuid: zlmdb.MapStringUuid
|
|
187
|
+
tab_oid_str: zlmdb.MapOidString
|
|
188
|
+
tab_oid_oid: zlmdb.MapOidOid
|
|
189
|
+
tab_oid_uuid: zlmdb.MapOidUuid
|
|
190
|
+
tab_uuid_json: zlmdb.MapUuidJson
|
|
191
|
+
tab_uuid_cbor: zlmdb.MapUuidCbor
|
|
192
|
+
tab_uuid_pickle: zlmdb.MapUuidPickle
|
|
193
|
+
tab_str_json: zlmdb.MapStringJson
|
|
194
|
+
tab_str_cbor: zlmdb.MapStringCbor
|
|
195
|
+
tab_str_pickle: zlmdb.MapStringPickle
|
|
196
|
+
tab_oid_json: zlmdb.MapOidJson
|
|
197
|
+
tab_oid_cbor: zlmdb.MapOidCbor
|
|
198
|
+
tab_oid_pickle: zlmdb.MapOidPickle
|
|
199
|
+
|
|
200
|
+
def __init__(self):
|
|
201
|
+
self.tab_uuid_str = zlmdb.MapUuidString(slot=1)
|
|
202
|
+
self.tab_uuid_oid = zlmdb.MapUuidOid(slot=2)
|
|
203
|
+
self.tab_uuid_uuid = zlmdb.MapUuidUuid(slot=3)
|
|
204
|
+
self.tab_str_str = zlmdb.MapStringString(slot=4)
|
|
205
|
+
self.tab_str_oid = zlmdb.MapStringOid(slot=5)
|
|
206
|
+
self.tab_str_uuid = zlmdb.MapStringUuid(slot=6)
|
|
207
|
+
self.tab_oid_str = zlmdb.MapOidString(slot=7)
|
|
208
|
+
self.tab_oid_oid = zlmdb.MapOidOid(slot=8)
|
|
209
|
+
self.tab_oid_uuid = zlmdb.MapOidUuid(slot=9)
|
|
210
|
+
self.tab_uuid_json = zlmdb.MapUuidJson(
|
|
211
|
+
slot=10, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
212
|
+
)
|
|
213
|
+
self.tab_uuid_cbor = zlmdb.MapUuidCbor(
|
|
214
|
+
slot=11, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
215
|
+
)
|
|
216
|
+
self.tab_uuid_pickle = zlmdb.MapUuidPickle(slot=12)
|
|
217
|
+
self.tab_str_json = zlmdb.MapStringJson(
|
|
218
|
+
slot=20, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
219
|
+
)
|
|
220
|
+
self.tab_str_cbor = zlmdb.MapStringCbor(
|
|
221
|
+
slot=21, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
222
|
+
)
|
|
223
|
+
self.tab_str_pickle = zlmdb.MapStringPickle(slot=22)
|
|
224
|
+
self.tab_oid_json = zlmdb.MapOidJson(
|
|
225
|
+
slot=30, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
226
|
+
)
|
|
227
|
+
self.tab_oid_cbor = zlmdb.MapOidCbor(
|
|
228
|
+
slot=31, marshal=(lambda o: o.marshal()), unmarshal=User.parse
|
|
229
|
+
)
|
|
230
|
+
self.tab_oid_pickle = zlmdb.MapOidPickle(slot=32)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class Schema2(zlmdb.Schema):
|
|
234
|
+
users: zlmdb.MapOidPickle
|
|
235
|
+
|
|
236
|
+
def __init__(self):
|
|
237
|
+
self.users = zlmdb.MapOidPickle(1)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class Schema3(zlmdb.Schema):
|
|
241
|
+
users: zlmdb.MapStringPickle
|
|
242
|
+
|
|
243
|
+
def __init__(self):
|
|
244
|
+
self.users = zlmdb.MapStringPickle(1)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class Schema4(zlmdb.Schema):
|
|
248
|
+
users: zlmdb.MapOidPickle
|
|
249
|
+
|
|
250
|
+
idx_users_by_authid: zlmdb.MapStringOid
|
|
251
|
+
|
|
252
|
+
idx_users_by_email: zlmdb.MapStringOid
|
|
253
|
+
|
|
254
|
+
idx_users_by_realm: zlmdb.MapOidOidOid
|
|
255
|
+
|
|
256
|
+
idx_users_by_icecream: zlmdb.MapStringOidOid
|
|
257
|
+
|
|
258
|
+
idx_users_by_mrealm_authid: zlmdb.MapUuidStringOid
|
|
259
|
+
|
|
260
|
+
idx_users_by_mrealm_authid_notnull: zlmdb.MapUuidStringOid
|
|
261
|
+
|
|
262
|
+
def __init__(self):
|
|
263
|
+
super(Schema4, self).__init__()
|
|
264
|
+
|
|
265
|
+
self.users = zlmdb.MapOidPickle(1)
|
|
266
|
+
|
|
267
|
+
self.idx_users_by_authid = zlmdb.MapStringOid(2)
|
|
268
|
+
self.users.attach_index(
|
|
269
|
+
"idx1", self.idx_users_by_authid, lambda user: user.authid, nullable=False
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
self.idx_users_by_email = zlmdb.MapStringOid(3)
|
|
273
|
+
self.users.attach_index(
|
|
274
|
+
"idx2", self.idx_users_by_email, lambda user: user.email, nullable=True
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
self.idx_users_by_realm = zlmdb.MapOidOidOid(4)
|
|
278
|
+
self.users.attach_index(
|
|
279
|
+
"idx3",
|
|
280
|
+
self.idx_users_by_realm,
|
|
281
|
+
lambda user: (user.realm_oid, user.oid),
|
|
282
|
+
nullable=False,
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
self.idx_users_by_icecream = zlmdb.MapStringOidOid(5)
|
|
286
|
+
self.users.attach_index(
|
|
287
|
+
"idx4",
|
|
288
|
+
self.idx_users_by_icecream,
|
|
289
|
+
lambda user: (user.icecream, user.oid),
|
|
290
|
+
nullable=False,
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
self.idx_users_by_mrealm_authid = zlmdb.MapUuidStringOid(6)
|
|
294
|
+
self.users.attach_index(
|
|
295
|
+
"idx5",
|
|
296
|
+
self.idx_users_by_mrealm_authid,
|
|
297
|
+
lambda user: (user.mrealm, user.authid),
|
|
298
|
+
nullable=True,
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
self.idx_users_by_mrealm_notnull_authid = zlmdb.MapUuidStringOid(7)
|
|
302
|
+
self.users.attach_index(
|
|
303
|
+
"idx6",
|
|
304
|
+
self.idx_users_by_mrealm_notnull_authid,
|
|
305
|
+
lambda user: (user.mrealm_notnull, user.authid),
|
|
306
|
+
nullable=False,
|
|
307
|
+
)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# The MIT License (MIT)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) typedef int GmbH
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
###############################################################################
|
|
26
|
+
|
|
27
|
+
import os
|
|
28
|
+
import sys
|
|
29
|
+
import random
|
|
30
|
+
import logging
|
|
31
|
+
|
|
32
|
+
import txaio
|
|
33
|
+
|
|
34
|
+
txaio.use_twisted()
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
from tempfile import TemporaryDirectory
|
|
38
|
+
except ImportError:
|
|
39
|
+
from backports.tempfile import TemporaryDirectory # type:ignore
|
|
40
|
+
|
|
41
|
+
import zlmdb # noqa
|
|
42
|
+
|
|
43
|
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
44
|
+
|
|
45
|
+
from _schema_fbs import User # noqa
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class UsersSchema(zlmdb.Schema):
|
|
49
|
+
def __init__(self):
|
|
50
|
+
self.tab_oid_fbs = zlmdb.MapOidFlatBuffers(1, build=User.build, cast=User.cast)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_pmap_flatbuffers_values():
|
|
54
|
+
with TemporaryDirectory() as dbpath:
|
|
55
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
56
|
+
|
|
57
|
+
schema = UsersSchema()
|
|
58
|
+
|
|
59
|
+
with zlmdb.Database(dbpath) as db:
|
|
60
|
+
N = 100
|
|
61
|
+
stats = zlmdb.TransactionStats()
|
|
62
|
+
|
|
63
|
+
with db.begin(write=True, stats=stats) as txn:
|
|
64
|
+
for i in range(N):
|
|
65
|
+
user = User.create_test_user()
|
|
66
|
+
schema.tab_oid_fbs[txn, user.oid] = user
|
|
67
|
+
|
|
68
|
+
assert stats.puts == N
|
|
69
|
+
assert stats.dels == 0
|
|
70
|
+
stats.reset()
|
|
71
|
+
|
|
72
|
+
with db.begin() as txn:
|
|
73
|
+
cnt = schema.tab_oid_fbs.count(txn)
|
|
74
|
+
|
|
75
|
+
assert cnt == N
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_pmap_flatbuffers_count():
|
|
79
|
+
with TemporaryDirectory() as dbpath:
|
|
80
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
81
|
+
|
|
82
|
+
schema = UsersSchema()
|
|
83
|
+
|
|
84
|
+
# max DB size is 100 MB
|
|
85
|
+
with zlmdb.Database(dbpath, maxsize=100 * (2**20)) as db:
|
|
86
|
+
oids = set()
|
|
87
|
+
oid_to_referred_by = {}
|
|
88
|
+
|
|
89
|
+
stats = zlmdb.TransactionStats()
|
|
90
|
+
|
|
91
|
+
# number of transactions
|
|
92
|
+
M = 5
|
|
93
|
+
|
|
94
|
+
# number of insert rows per transaction
|
|
95
|
+
N = 10000
|
|
96
|
+
for j in range(M):
|
|
97
|
+
with db.begin(write=True, stats=stats) as txn:
|
|
98
|
+
for i in range(N):
|
|
99
|
+
user = User.create_test_user()
|
|
100
|
+
schema.tab_oid_fbs[txn, user.oid] = user
|
|
101
|
+
oids.add(user.oid)
|
|
102
|
+
oid_to_referred_by[user.oid] = user.referred_by
|
|
103
|
+
|
|
104
|
+
assert stats.puts == N
|
|
105
|
+
assert stats.dels == 0
|
|
106
|
+
duration_ns = stats.duration
|
|
107
|
+
duration_ms = int(duration_ns / 1000000.0)
|
|
108
|
+
rows_per_sec = int(
|
|
109
|
+
round(float(stats.puts + stats.dels) * 1000.0 / float(duration_ms))
|
|
110
|
+
)
|
|
111
|
+
logging.info(
|
|
112
|
+
"Transaction ended: puts={} / dels={} rows in {} ms, {} rows/sec".format(
|
|
113
|
+
stats.puts, stats.dels, duration_ms, rows_per_sec
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
stats.reset()
|
|
118
|
+
|
|
119
|
+
# count all rows
|
|
120
|
+
with db.begin() as txn:
|
|
121
|
+
cnt = schema.tab_oid_fbs.count(txn)
|
|
122
|
+
|
|
123
|
+
assert cnt == N * M
|
|
124
|
+
|
|
125
|
+
# retrieve
|
|
126
|
+
with db.begin() as txn:
|
|
127
|
+
for j in range(5):
|
|
128
|
+
started = zlmdb.walltime()
|
|
129
|
+
M = 100
|
|
130
|
+
for i in range(M):
|
|
131
|
+
for oid in random.sample(oids, N):
|
|
132
|
+
user = schema.tab_oid_fbs[txn, oid]
|
|
133
|
+
assert user
|
|
134
|
+
assert user.referred_by == oid_to_referred_by.get(oid, None)
|
|
135
|
+
duration_ns = zlmdb.walltime() - started
|
|
136
|
+
duration_ms = int(duration_ns / 1000000.0)
|
|
137
|
+
rows_per_sec = int(
|
|
138
|
+
round(float(M * N) * 1000.0 / float(duration_ms))
|
|
139
|
+
)
|
|
140
|
+
logging.info(
|
|
141
|
+
"Transaction ended: {} rows read in {} ms, {} rows/sec".format(
|
|
142
|
+
M * N, duration_ms, rows_per_sec
|
|
143
|
+
)
|
|
144
|
+
)
|