Parses MySQL and translates ADQL to MySQL.
Project description
Tool for parsing and processing MySQL and ADQL 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.
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 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.
Generating the parser from the git repository
To generate the parsers you need python (either 2 or 3), java above version 7, and antlr4 (which 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 you virtual env.
Testing
First, install pytest
pip install pytest
then, run the test suite:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file queryparser-python3-0.2.2.tar.gz
.
File metadata
- Download URL: queryparser-python3-0.2.2.tar.gz
- Upload date:
- Size: 216.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53a72871eb0c8e50bb9bfd2ffc292888c5c2c274c2b5f5bcafe3fa38b571b8a1 |
|
MD5 | 2db8150a150844014b9a4a0e3b4c46d9 |
|
BLAKE2b-256 | e5e0b5d38945d91d0554f95efdc95d7abdd8496c95ca59d77891c02d4fda4beb |