1
1
queryparser
2
2
===========
3
3
4
- ** Tool for parsing and processing of MySQL/PostgreSQL and translation of
4
+ ** Tool for parsing and processing of ( MySQL\* ) /PostgreSQL and translation of
5
5
ADQL SELECT-like queries**
6
6
7
7
Designed to be used in conjunction with [ django-daiquri] ( https://github.com/django-daiquiri/daiquiri )
8
8
as a query processing backend but it can be easily used as a stand-alone tool
9
9
or integrated into another project.
10
10
11
+ ** \* NOTE: Since version 0.7.0 MySQL is not supported (maintained) anymore.**
12
+
11
13
12
14
[ ![ pytest Workflow Status] ( https://github.com/aipescience/queryparser/actions/workflows/pytest.yml/badge.svg )] ( https://github.com/aipescience/queryparser/actions/workflows/pytest.yml )
13
15
[ ![ 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
22
24
The easiest way to install the package is by using the pip tool:
23
25
24
26
``` bash
25
-
26
- pip install queryparser-python3
27
-
27
+ python -m pip install queryparser-python3
28
28
```
29
29
30
30
Alternatively, you can clone the repository and install it from there.
@@ -37,45 +37,62 @@ Generating the parser from the git repository
37
37
38
38
To generate the parsers you need ` python3 ` , ` java ` above version
39
39
7, 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
+ ```
41
47
42
48
After cloning the project run
43
49
44
50
``` bash
45
- make
51
+ make
46
52
```
47
53
48
54
and a ` lib ` directory will be created. After that, run
49
55
50
56
``` bash
51
- python setup.py install
57
+ python -m pip install .
52
58
```
53
59
54
60
to install the generated parser in your virtual environment.
55
61
56
62
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
+
57
71
Parsing MySQL and PostgreSQL
58
72
----------------------------
59
73
74
+ ** Since version 0.7, MySQL part of the parser is not maintained anymore.
75
+ Thus, the MySQL related functionality cannot be guaranteed!**
76
+
60
77
Parsing and processing of MySQL queries can be done by creating an instance
61
78
of the ` MySQLQueryProcessor ` class
62
79
63
80
``` python
64
- from queryparser.mysql import MySQLQueryProcessor
65
- qp = MySQLQueryProcessor()
81
+ from queryparser.mysql import MySQLQueryProcessor
82
+ qp = MySQLQueryProcessor()
66
83
```
67
84
68
85
feeding it a MySQL query
69
86
70
87
``` 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)
73
90
```
74
91
75
92
and running it with
76
93
77
94
``` python
78
- qp.process_query()
95
+ qp.process_query()
79
96
```
80
97
81
98
After 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
88
105
the ` PostgreSQLProcessor ` class:
89
106
90
107
``` python
91
- from queryparser.postgresql import PostgreSQLQueryProcessor
92
- qp = PostgreSQLQueryProcessor()
108
+ from queryparser.postgresql import PostgreSQLQueryProcessor
109
+ qp = PostgreSQLQueryProcessor()
93
110
```
94
111
95
112
The rest of the functionality remains the same.
@@ -102,35 +119,34 @@ Translation of ADQL queries is done similarly by first creating an instance of
102
119
the ` ADQLQueryTranslator ` class
103
120
104
121
``` 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)
108
125
```
109
126
110
127
and calling
111
128
112
129
``` python
113
- adt.to_mysql ()
130
+ adt.to_postgresql ()
114
131
```
115
132
116
133
which 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.
120
136
121
137
Testing
122
138
-------
123
139
124
- First, install ` pytest `
140
+ First in the root directory of the project, install optional dependencies
141
+ (` PyYAML ` and ` pytest ` ) by running
125
142
126
143
``` bash
127
- pip install pytest
144
+ python -m pip install .[test]
128
145
```
129
146
130
- then run the test suite for a version of python you would like to test with
147
+ then run the test suite with
131
148
132
149
``` bash
133
- pytest lib/
150
+ python -m pytest lib/
134
151
```
135
152
136
- More elaborate testing procedures can be found in the development notes.
0 commit comments