queryparser
Tool for parsing and processing MySQL and ADQL SELECT queries
Designed to be used in conjunction with django-daiquri as a query processing backend but it can be easily used as a stand-alone tool or integrated into another project.
Installation
The easiest way to install the package is by using the pip tool:
pip install queryparser-python3
or if you are using an older version (2.7) of python
pip install queryparser-python2
Alternatively, you can clone the repository and install it from there. However, this step also requires generating the parser which is a slighly more elaborate process (see below).
Generating the parser from the git repository
To generate the parsers you need python (either 2 or 3), java above version 7, and antlr4 (antlr-4.*-complete.jar has to be installed inside the /usr/local/lib/ or /usr/local/bin/ directories).
After cloning the project run
make
and a lib directory will be created with the complete source for python2 and python3. After that run
python setup.py install
to install the generated parser in your virtual environment.
Parsing MySQL
Parsing and processing of MySQL queries can be done by creating an instance of the MySQLQueryProcessor class
from queryparser.mysql import MySQLQueryProcessor
qp = MySQLQueryProcessor()
feeding it a MySQL query
sql = "SELECT a FROM db.tab;"
qp.set_query(sql)
and running it with
qp.process_query()
After the processing, the processor object qp will include tables, columns, functions, and keywords used in the query or will raise a QuerySyntaxError if there are any syntax errors in the query.
Alternatively, passing the query at initialization automatically processes it.
Translating ADQL
Translation of ADQL queries is done similarly by first creating an instance of the ADQLQueryTranslator class
from queryparser.adql import ADQLQueryTranslator
adql = "SELECT TOP 100 POINT('ICRS', ra, de) FROM db.tab;"
adt = ADQLQueryTranslator(adql)
and calling
adt.to_mysql()
which returns a translated string representing a valid MySQL query if the ADQL query had no errors. The MySQL query can then be parsed with the MySQLQueryProcessor in the same way as shown above.
Testing
First, install pytest
pip install pytest
then run the test suite for a version of python you would like to test with
pytest lib/python2
pytest lib/python3
Metadata
Release files for queryparser-python2 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| queryparser-python2-0.4.2.tar.gz | 308.9 kB | Without provenance | Details |
Release files / queryparser-python2-0.4.2.tar.gz
| Download URL | queryparser-python2-0.4.2.tar.gz |
|---|---|
| Size | 308.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c63ff52b9d21896f7c1a619fc4f2f84c832971b7b6c3a3e8d273224bc9f3088
|
|
BLAKE2b-256 checksum How to use checksums |
f4929f83e21a1f43844474ef20e945df639c859439a074026a458563d89e3a55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/32.3.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3
|
Security for queryparser-python2 0.4.2
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.