Skip to main content

Parses MySQL and translates ADQL to MySQL.

Project description

Let’s parse some MySQL and ADQL!

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 b;"
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 a,b FROM c"
adt = ADQLQueryTranslator(adql)

and calling

adt.to_mysql()

which returns a translated string.

Examples

There are some example queries in the queryparser/examples directory. Have a look there, edit run.py (just comment out/uncomment the line you want in main) and run it:

python queryparser/examples/run.py

This will parse a number of queries (specified in the corresponding example-files) and print the query, the parsed columns and the parsing time.

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

python make.py

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.

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-python2-0.1.tar.gz (216.8 kB view details)

Uploaded Source

File details

Details for the file queryparser-python2-0.1.tar.gz.

File metadata

File hashes

Hashes for queryparser-python2-0.1.tar.gz
Algorithm Hash digest
SHA256 f27309f35d926875ff509b48c82d9be4c5fa3bc64978d1a5069d6e3b2f7e2690
MD5 b9026bc4f9424e4db3e03d375c294407
BLAKE2b-256 c21449c1892276dfa976a4bf40a3bbbfceec1e09ecf215ca3b5642b4a09eeea1

See more details on using hashes here.

Supported by

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