11queryparser
22===========
33
4- ** Tool for parsing and processing of MySQL/PostgreSQL and translation of
4+ ** Tool for parsing and processing of ( MySQL\* ) /PostgreSQL and translation of
55ADQL SELECT-like queries**
66
77Designed to be used in conjunction with [ django-daiquri] ( https://github.com/django-daiquiri/daiquiri )
88as a query processing backend but it can be easily used as a stand-alone tool
99or integrated into another project.
1010
11+ ** \* NOTE: Since version 0.7.0 MySQL is not supported (maintained) anymore.**
12+
1113
1214[ ![ pytest Workflow Status] ( https://github.com/aipescience/queryparser/actions/workflows/pytest.yml/badge.svg )] ( https://github.com/aipescience/queryparser/actions/workflows/pytest.yml )
1315[ ![ Coverage Status] ( https://coveralls.io/repos/aipescience/queryparser/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/aipescience/queryparser?branch=master )
@@ -22,9 +24,7 @@ Installation
2224The easiest way to install the package is by using the pip tool:
2325
2426``` bash
25-
26- pip install queryparser-python3
27-
27+ python -m pip install queryparser-python3
2828```
2929
3030Alternatively, you can clone the repository and install it from there.
@@ -37,45 +37,62 @@ Generating the parser from the git repository
3737
3838To generate the parsers you need ` python3 ` , ` java ` above version
39397, and ` antlr4 ` (` antlr-4.*-complete.jar ` has to be installed inside the
40- ` /usr/local/lib/ ` or ` /usr/local/bin/ ` directories).
40+ ` /usr/local/lib/ ` , ` /usr/local/bin/ ` or root directory of the project).
41+
42+ The current version of ` antlr-4.*-complete.jar ` can be downloaded via
43+
44+ ``` bash
45+ wget http://www.antlr.org/download/antlr-4.13.1-complete.jar
46+ ```
4147
4248After cloning the project run
4349
4450``` bash
45- make
51+ make
4652```
4753
4854and a ` lib ` directory will be created. After that, run
4955
5056``` bash
51- python setup.py install
57+ python -m pip install .
5258```
5359
5460to install the generated parser in your virtual environment.
5561
5662
63+ Additional requirements
64+ -----------------------
65+ The queryparser assumes that the PostgreSQL database has the extension
66+ [ pg_sphere] ( https://github.com/kimakan/pgsphere/tree/aiprdbms16 ) installed.
67+ Although the ` pg_sphere ` is not required for the python module, the PostgreSQL
68+ ** queries will not run** without this extension installed on the database.
69+
70+
5771Parsing MySQL and PostgreSQL
5872----------------------------
5973
74+ ** Since version 0.7, MySQL part of the parser is not maintained anymore.
75+ Thus, the MySQL related functionality cannot be guaranteed!**
76+
6077Parsing and processing of MySQL queries can be done by creating an instance
6178of the ` MySQLQueryProcessor ` class
6279
6380``` python
64- from queryparser.mysql import MySQLQueryProcessor
65- qp = MySQLQueryProcessor()
81+ from queryparser.mysql import MySQLQueryProcessor
82+ qp = MySQLQueryProcessor()
6683```
6784
6885feeding it a MySQL query
6986
7087``` python
71- sql = " SELECT a FROM db.tab;"
72- qp.set_query(sql)
88+ sql = " SELECT a FROM db.tab;"
89+ qp.set_query(sql)
7390```
7491
7592and running it with
7693
7794``` python
78- qp.process_query()
95+ qp.process_query()
7996```
8097
8198After the processing is completed, the processor object ` qp ` will include
@@ -88,8 +105,8 @@ PostgreSQL parsing is very similar to MySQL, except it requires importing
88105the ` PostgreSQLProcessor ` class:
89106
90107``` python
91- from queryparser.postgresql import PostgreSQLQueryProcessor
92- qp = PostgreSQLQueryProcessor()
108+ from queryparser.postgresql import PostgreSQLQueryProcessor
109+ qp = PostgreSQLQueryProcessor()
93110```
94111
95112The rest of the functionality remains the same.
@@ -102,35 +119,34 @@ Translation of ADQL queries is done similarly by first creating an instance of
102119the ` ADQLQueryTranslator ` class
103120
104121``` python
105- from queryparser.adql import ADQLQueryTranslator
106- adql = " SELECT TOP 100 POINT('ICRS', ra, de) FROM db.tab;"
107- adt = ADQLQueryTranslator(adql)
122+ from queryparser.adql import ADQLQueryTranslator
123+ adql = " SELECT TOP 100 POINT('ICRS', ra, de) FROM db.tab;"
124+ adt = ADQLQueryTranslator(adql)
108125```
109126
110127and calling
111128
112129``` python
113- adt.to_mysql ()
130+ adt.to_postgresql ()
114131```
115132
116133which returns a translated string representing a valid MySQL query if
117- the ADQL query had no errors. The MySQL query can then be parsed with the
118- ` MySQLQueryProcessor ` in the same way as shown above.
119-
134+ the ADQL query had no errors. The PostgreSQL query can then be parsed with the
135+ ` PostgreSQLQueryProcessor ` in the same way as shown above.
120136
121137Testing
122138-------
123139
124- First, install ` pytest `
140+ First in the root directory of the project, install optional dependencies
141+ (` PyYAML ` and ` pytest ` ) by running
125142
126143``` bash
127- pip install pytest
144+ python -m pip install .[test]
128145```
129146
130- then run the test suite for a version of python you would like to test with
147+ then run the test suite with
131148
132149``` bash
133- pytest lib/
150+ python -m pytest lib/
134151```
135152
136- More elaborate testing procedures can be found in the development notes.
0 commit comments