Skip to main content

mdbrtools

This package contains experimental tools for schema analysis and query workload generation used by MongoDB Research (MDBR).

Disclaimer

This tool is not officially supported or endorsed by MongoDB Inc. The code is released for use "AS IS" without any warranties of any kind, including, but not limited to its installation, use, or performance. Do not run this tool in critical production systems.

Installation

Installation with pip

This tool requires python 3.x and pip on your system. To install mdbrtools, run the following command:

pip install mdbrtools

Installation from source

Clone the respository from github. From the top-level directory, run:

pip install -e .

This installs an editable development version of mdbrtools in your current Python environment.

Usage

See the ./notebooks directory for more detailed examples for schema parsing and workload generation.

Schema Parsing

Schema parsing operates on a list of Python dictionaries.

from mdbrtools.schema import parse_schema
from pprint import pprint

docs = [
    {"_id": 1, "mixed_field": "world", "missing_field": False},
    {"_id": 2, "mixed_field": 123},
    {"_id": 3, "mixed_field": False, "missing_field": True},
]

schema = parse_schema(docs)
pprint(dict(schema))

Converting the schema object to a dictionary will output some general information about the schema:

{'_id': [{'counter': 3, 'type': 'int'}],
 'missing_field': [{'counter': 2, 'type': 'bool'}],
 'mixed_field': [{'counter': 1, 'type': 'str'},
                 {'counter': 1, 'type': 'int'},
                 {'counter': 1, 'type': 'bool'}]}

For access to types, values and uniqueness information, see the examples in ./notebooks/schema_parsing.ipynb.

Workload Generation

Workload generation takes either a list of Python dictionaries, or a MongoCollection object as input.

from mdbrtools.workload import Workload

docs = [
    {"_id": 1, "mixed_field": "world", "missing_field": False},
    {"_id": 2, "mixed_field": 123},
    {"_id": 3, "mixed_field": False, "missing_field": True},
]

workload = Workload()
workload.generate(docs, num_queries=5)

for query in workload:
    print(query.to_mql())

The generated MQL queries are:

{'missing_field': True}
{'missing_field': {'$exists': False}, '_id': {'$gte': 3}}
{'_id': {'$gt': 3}, 'mixed_field': False, 'missing_field': {'$exists': False}}
{'mixed_field': {'$gte': 'world'}, '_id': 3, 'missing_field': {'$ne': False}}
{'mixed_field': 'world'}

The workload generator supports a number of different constraints on the queries:

  • min. and max. number of predicates per query
  • allowing only certain fields
  • which query operators are allowed for which data types
  • control over the weights by which operators are randomly chosen
  • min. and max. query selectivity constraints

See the notebook under ./notebooks/workload_generation.ipynb for examples.

Tests

To execute the unit tests, run from the top-level directory:

python -m unittest discover ./tests

License

MIT, see LICENSE.

Metadata

Release files for mdbrtools 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdbrtools 0.1.1
File Size Uploaded Provenance
mdbrtools-0.1.1.tar.gz 23.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mdbrtools 0.1.1
File Interpreter ABI Platform
mdbrtools-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.0 kB

Release files / mdbrtools-0.1.1.tar.gz

Download URL mdbrtools-0.1.1.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e22eaa86b5b595cf6ce83321417561fca6412e4c7b40d17137d9066d87f2cdd8
BLAKE2b-256 checksum
How to use checksums
5b1cb871fa8894102b476a34e928ec1a83210d5b8a9d5fd175a1a5b35839709a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Release files / mdbrtools-0.1.1-py3-none-any.whl

Download URL mdbrtools-0.1.1-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7de812155e13f7f8a07516cc5d9a74af4d35fffbbb430e9e4f161a51a2160a0
BLAKE2b-256 checksum
How to use checksums
1172050551524d314fc3f9a6f5e632f5c5bd0448f816727e6edd09ad04a4ce2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Security for mdbrtools 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page