Skip to main content

Parses MySQL and translates ADQL to MySQL.

Project description

Let’s parse some MySQL and ADQL!

Build Status Coverage Status

Parsing MySQL

Processing of MySQL queries is done by first 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 will include columns, functions, and keywords used 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 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 `

TODO

  • more Documentation

  • ADQL coordinate systems

  • ADQL mixed coordinates

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

queryparser-python3-0.1.3.tar.gz (211.6 kB view details)

Uploaded Source

File details

Details for the file queryparser-python3-0.1.3.tar.gz.

File metadata

File hashes

Hashes for queryparser-python3-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7a884b98c8cd8dea51fb93d9f0c8d09dc32ffc2e8a0cb497f2897ffa13573e3a
MD5 529141b5daafc7d3cd4cf9a1e7b5aca3
BLAKE2b-256 15941c8ce90a4d9943d30e4d58b52c2ded6c3168aa7b0880ba1df90b2f16a0b6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page