12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
import abc
15
- import collections
16
15
import math
17
16
import os
18
17
from abc import ABC
21
20
import pandas as pd
22
21
import pyarrow
23
22
import pymongo
24
- from bson import BSON
23
+ from bson import BSON , Binary , Decimal128
25
24
from pymongoarrow .api import (
26
25
Schema ,
27
26
find_arrow_all ,
28
27
find_numpy_all ,
29
28
find_pandas_all ,
30
29
write ,
31
30
)
31
+ from pymongoarrow .types import BinaryType , Decimal128Type
32
32
33
33
N_DOCS = int (os .environ .get ("N_DOCS" ))
34
34
assert pymongo .has_c ()
@@ -163,7 +163,7 @@ class ProfileReadArray(Read):
163
163
def setup_cache (self ):
164
164
coll = db .benchmark
165
165
coll .drop ()
166
- base_dict = collections . OrderedDict (
166
+ base_dict = dict (
167
167
[("x" , 1 ), ("y" , math .pi ), ("emb" , [math .pi for _ in range (EMBEDDED_OBJECT_SIZE )])]
168
168
)
169
169
coll .insert_many ([base_dict .copy () for _ in range (N_DOCS )])
@@ -208,7 +208,7 @@ class ProfileReadDocument(Read):
208
208
def setup_cache (self ):
209
209
coll = db .benchmark
210
210
coll .drop ()
211
- base_dict = collections . OrderedDict (
211
+ base_dict = dict (
212
212
[
213
213
("x" , 1 ),
214
214
("y" , math .pi ),
@@ -250,7 +250,7 @@ class ProfileReadSmall(Read):
250
250
def setup_cache (self ):
251
251
coll = db .benchmark
252
252
coll .drop ()
253
- base_dict = collections . OrderedDict (
253
+ base_dict = dict (
254
254
[
255
255
("x" , 1 ),
256
256
("y" , math .pi ),
@@ -272,7 +272,44 @@ def setup_cache(self):
272
272
coll = db .benchmark
273
273
coll .drop ()
274
274
275
- base_dict = collections .OrderedDict ([(k , math .pi ) for k in self .large_doc_keys ])
275
+ base_dict = dict ([(k , math .pi ) for k in self .large_doc_keys ])
276
+ coll .insert_many ([base_dict .copy () for _ in range (N_DOCS )])
277
+ print (
278
+ "%d docs, %dk each with %d keys"
279
+ % (N_DOCS , len (BSON .encode (base_dict )) // 1024 , len (base_dict ))
280
+ )
281
+
282
+
283
+ class ProfileReadExtensionSmall (Read ):
284
+ schema = Schema ({"x" : Decimal128Type (), "y" : BinaryType (10 )})
285
+ dtypes = np .dtype (np .dtype ([("x" , np .object_ ), ("y" , np .object_ )]))
286
+
287
+ def setup_cache (self ):
288
+ coll = db .benchmark
289
+ coll .drop ()
290
+ base_dict = dict (
291
+ [
292
+ ("x" , Decimal128 ("1" )),
293
+ ("y" , Binary (b"1234" , 10 )),
294
+ ]
295
+ )
296
+ coll .insert_many ([base_dict .copy () for _ in range (N_DOCS )])
297
+ print (
298
+ "%d docs, %dk each with %d keys"
299
+ % (N_DOCS , len (BSON .encode (base_dict )) // 1024 , len (base_dict ))
300
+ )
301
+
302
+
303
+ class ProfileReadExtensionLarge (Read ):
304
+ large_doc_keys = [f"{ i } " for i in range (LARGE_DOC_SIZE )]
305
+ schema = Schema ({k : Decimal128Type () for k in large_doc_keys })
306
+ dtypes = np .dtype ([(k , np .object_ ) for k in large_doc_keys ])
307
+
308
+ def setup_cache (self ):
309
+ coll = db .benchmark
310
+ coll .drop ()
311
+
312
+ base_dict = dict ([(k , Decimal128 (k )) for k in self .large_doc_keys ])
276
313
coll .insert_many ([base_dict .copy () for _ in range (N_DOCS )])
277
314
print (
278
315
"%d docs, %dk each with %d keys"
@@ -291,7 +328,7 @@ class ProfileInsertSmall(Insert):
291
328
def setup_cache (self ):
292
329
coll = db .benchmark
293
330
coll .drop ()
294
- base_dict = collections . OrderedDict ([("x" , 1 ), ("y" , math .pi )])
331
+ base_dict = dict ([("x" , 1 ), ("y" , math .pi )])
295
332
coll .insert_many ([base_dict .copy () for _ in range (N_DOCS )])
296
333
print (
297
334
"%d docs, %dk each with %d keys"
@@ -310,7 +347,7 @@ class ProfileInsertLarge(Insert):
310
347
def setup_cache (self ):
311
348
coll = db .benchmark
312
349
coll .drop ()
313
- base_dict = collections . OrderedDict ([(k , math .pi ) for k in self .large_doc_keys ])
350
+ base_dict = dict ([(k , math .pi ) for k in self .large_doc_keys ])
314
351
coll .insert_many ([base_dict .copy () for _ in range (N_DOCS )])
315
352
print (
316
353
"%d docs, %dk each with %d keys"
0 commit comments