Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Build queryparser
run: |
wget http://www.antlr.org/download/antlr-4.13.1-complete.jar
wget http://www.antlr.org/download/antlr-4.13.2-complete.jar
make
pip install -I -e .[test]
pip install pytest-cov
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To generate the parsers you need `python3` , `java` above version
The current version of `antlr-4.*-complete.jar` can be downloaded via

```bash
wget http://www.antlr.org/download/antlr-4.13.1-complete.jar
wget http://www.antlr.org/download/antlr-4.13.2-complete.jar
```

After cloning the project run
Expand All @@ -63,9 +63,9 @@ to install the generated parser in your virtual environment.
Additional requirements
-----------------------
The queryparser assumes that the PostgreSQL database has the extension
[pg_sphere](https://github.com/kimakan/pgsphere/tree/aiprdbms16) installed.
Although the `pg_sphere` is not required for the python module, the PostgreSQL
**queries will not run** without this extension installed on the database.
[pg_sphere](https://github.com/postgrespro/pgsphere) installed.
Although `pg_sphere` is not required for the Python module, PostgreSQL
**queries will not run** without this extension installed in the database.


Parsing MySQL and PostgreSQL
Expand Down Expand Up @@ -120,7 +120,7 @@ the `ADQLQueryTranslator` class

```python
from queryparser.adql import ADQLQueryTranslator
adql = "SELECT TOP 100 POINT('ICRS', ra, de) FROM db.tab;"
adql = "SELECT TOP 100 POINT('ICRS', ra, dec) FROM db.tab;"
adt = ADQLQueryTranslator(adql)
```

Expand All @@ -130,7 +130,7 @@ and calling
adt.to_postgresql()
```

which returns a translated string representing a valid MySQL query if
which returns a translated string representing a valid PostgreSQL query if
the ADQL query had no errors. The PostgreSQL query can then be parsed with the
`PostgreSQLQueryProcessor` in the same way as shown above.

Expand All @@ -149,4 +149,3 @@ then run the test suite with
```bash
python -m pytest lib/
```

9 changes: 4 additions & 5 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ processed and can be used to check, for example, for permissions before the
query is sent to the server.

In addition, queryparser can also work with ADQL queries which can be translated
to either MySQL or PostgreSQL language and then further processed the same
way.
to PostgreSQL and then further processed the same way.

Below is a more detailed description along with instructions for anyone who is
interested in further developing the package.
Expand Down Expand Up @@ -49,14 +48,14 @@ Individual dialect functionality (MySQL in this case) with increased verbosity
can be tested with

```bash
pytest /lib/queryparser/testing/test_mysql.py -v
pytest lib/queryparser/testing/test_mysql.py -v
```

Individual tests (20th MySQL test in this case, but otherwise any test
that includes the string 't20') are ran with

```bash
pytest /lib/queryparser/testing/test_mysql.py -k t20
pytest lib/queryparser/testing/test_mysql.py -k t20
```

If the package `pytest-cov` is installed then the detailed coverage report
Expand Down Expand Up @@ -120,7 +119,7 @@ and an ADQL translator. The processors accept any SELECT-like query and
after the process_query() method has been executed, several elements of
the query are extracted (all touch columns and tables, used keywords and functions).
Before the processing the query is validated and invalid queries are rejected.
The ADQL translator allows translating valid ADQL queries to MySQL or PostgreSQL.
The ADQL translator allows translating valid ADQL queries to PostgreSQL.

Most of the processor code is shared between MySQL and PostgreSQL and is
therefore merged together inside of the `common.py`. This file consists
Expand Down
2 changes: 1 addition & 1 deletion generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
import re

ANTLR_JAR = 'antlr-4.13.1-complete.jar'
ANTLR_JAR = 'antlr-4.13.2-complete.jar'
ANTLR_DIRS = ('.', '/usr/local/lib/', '/usr/local/bin/')

QUERYPARSER_SRC = 'src/queryparser/'
Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ description = "Package for parsing PostgreSQL/MySQL and translating ADQL to Post
readme = "README.md"
dynamic = ["version"]
license = { text = "Apache-2.0" }
authors = [{ name = "Gal Matijevic", email = "gmatijevic@aip.de" }]
authors = [
{ name = "Kirill Makan", email = "kmakan@aip.de" },
{ name = "Gal Matijevic", email = "gmatijevic@aip.de" }
]
maintainers = [
{ name = "Kirill Makan", email = "kmakan@aip.de" },
{ name = "Simeon Reusch", email = "sreusch@aip.de" },
]
requires-python = ">=3.9"
classifiers = [
Expand All @@ -24,8 +26,10 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = ["antlr4-python3-runtime==4.13.1"]
dependencies = ["antlr4-python3-runtime==4.13.2"]

[project.optional-dependencies]
test = ["pytest~=8.2.0", "PyYAML~=6.0"]
Expand Down
2 changes: 1 addition & 1 deletion src/queryparser/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.4'
__version__ = '0.8.0'
12 changes: 6 additions & 6 deletions src/queryparser/adql/ADQLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ HEX_DIGIT:
( '0x' (HEX_DIGIT_FRAGMENT)+ )
;

CSL: SQ ('\u0020' .. '\u0026' | '\u0028' .. '\u007f')+ SQ;
CSL: SQ ( SQ SQ | '\u0020' .. '\u0026' | '\u0028' .. '\u007f' )* SQ;

ID:
(( 'A'..'Z' | 'a'..'z' | '_' | '%' | '$') ( 'A'..'Z' | 'a'..'z' | '_' | '$' | '%' | '0'..'9' )*) |
//(DQ NQC+ DQ)
(DQ ('\u0020' .. '\u0021' | '\u0023' .. '\u007f')+ DQ)
;
DELIMITED_ID:
DQ ('\u0020' .. '\u0021' | '\u0023' .. '\u007f')+ DQ;

ID:
( 'A'..'Z' | 'a'..'z' )
( 'A'..'Z' | 'a'..'z' | '_' | '0'..'9' )*;

//NDQC: 'A'..'Z' | 'a'..'z' | '_' | '0'..'9' ;

Expand Down
16 changes: 8 additions & 8 deletions src/queryparser/adql/ADQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ box:
( coord_sys COMMA )?
coordinates COMMA numeric_value_expression COMMA numeric_value_expression
RPAREN ;
catalog_name: ID ;
catalog_name: ID | DELIMITED_ID ;
// centroid: CENTROID LPAREN geometry_value_expression RPAREN ;
// character_representation: nonquote_character ;// | SQ SQ ;
char_function: LOWER LPAREN character_string_literal RPAREN ;
Expand Down Expand Up @@ -52,7 +52,7 @@ coordinates: coordinate1 COMMA coordinate2 ;
correlation_name: identifier ;
correlation_specification: ( AS )? correlation_name ;
//default_function_prefix: // this is empty in the document!
delimited_identifier: DQ ID DQ ;
delimited_identifier: DELIMITED_ID ;
derived_column: value_expression ( as_clause )? ;
derived_table: table_subquery ;
distance:
Expand All @@ -70,9 +70,9 @@ factor: ( sign )? numeric_primary ;
from_clause: FROM table_reference ( COMMA table_reference )* ;
general_literal: character_string_literal ;
general_set_function: set_function_type LPAREN ( set_quantifier )? value_expression RPAREN ;
geometry_value_expression: box | circle | point | polygon | user_defined_function ; //| centroid | region
geometry_value_expression: value_expression_primary | box | circle | point | polygon | user_defined_function ; //| centroid | region
group_by_clause: GROUP BY grouping_column_reference_list ;
grouping_column_reference: column_reference ;
grouping_column_reference: value_expression ;
grouping_column_reference_list: grouping_column_reference ( COMMA grouping_column_reference )* ;
having_clause: HAVING search_condition ;
identifier: regular_identifier | delimited_identifier ;
Expand Down Expand Up @@ -160,7 +160,7 @@ query_term: non_join_query_primary | query_term INTERSECT (
radius: numeric_value_expression ;
//region: REGION LPAREN string_value_expression RPAREN ;
regular_identifier: ID ;
schema_name: ID ; //( catalog_name DOT )? unqualified_schema_name ;
schema_name: ID | DELIMITED_ID ; //( catalog_name DOT )? unqualified_schema_name ;
search_condition: boolean_term | search_condition OR boolean_term ;
select_list: ( select_sublist ( COMMA select_sublist )* ) | ( ASTERISK ( COMMA select_sublist ( COMMA select_sublist )* )? ) ;
select_query: SELECT ( set_quantifier )? ( set_limit )? select_list table_expression ;
Expand Down Expand Up @@ -194,15 +194,14 @@ table_reference:
table_subquery: subquery ;
term: factor | term ASTERISK factor | term SOLIDUS factor | term MOD_SYM factor;
trig_function: ACOS LPAREN numeric_value_expression RPAREN
| ACOS LPAREN numeric_value_expression RPAREN
| ASIN LPAREN numeric_value_expression RPAREN
| ATAN LPAREN numeric_value_expression RPAREN
| ATAN2 LPAREN numeric_value_expression COMMA numeric_value_expression RPAREN
| COS LPAREN numeric_value_expression RPAREN
| COT LPAREN numeric_value_expression RPAREN
| SIN LPAREN numeric_value_expression RPAREN
| TAN LPAREN numeric_value_expression RPAREN ;
unqualified_schema_name: ID ;
unqualified_schema_name: ID | DELIMITED_ID ;
unsigned_decimal: INT ;
unsigned_hexadecimal: HEX_DIGIT ;
unsigned_literal: unsigned_numeric_literal | general_literal ;
Expand All @@ -216,7 +215,8 @@ user_defined_function:
user_defined_function_name: regular_identifier ; //( default_function_prefix )? regular_identifier ;
user_defined_function_param: value_expression ;
value_expression:
numeric_value_expression
NULL
| numeric_value_expression
| string_value_expression
| boolean_value_expression
| geometry_value_expression ;
Expand Down
Loading
Loading