Skip to content

Commit 364dcfa

Browse files
Copilotgitosaurus
andcommitted
Integrate bin/adql_to_lsdb for ADQL query processing
Co-authored-by: gitosaurus <[email protected]>
1 parent b84bd26 commit 364dcfa

File tree

6 files changed

+165
-339
lines changed

6 files changed

+165
-339
lines changed

tap_server/README.md

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,31 @@ A prototype implementation of a TAP (Table Access Protocol) server following the
44

55
## Overview
66

7-
This TAP server prototype accepts ADQL (Astronomical Data Query Language) queries and returns results in VOTable format. The server is built using Flask and includes:
7+
This TAP server prototype accepts ADQL (Astronomical Data Query Language) queries and returns results in VOTable format. The server is built using Flask and integrates with the `bin/adql_to_lsdb` module to convert ADQL queries to LSDB-compatible operations.
88

9-
- **ADQL Query Parser** (`adql_to_lsdb.py`): Parses ADQL queries and converts them to LSDB-compatible operations
9+
Components:
10+
- **ADQL to LSDB Converter** (`../bin/adql_to_lsdb.py`): Comprehensive ADQL parser using queryparser library
1011
- **TAP Server** (`tap_server.py`): Flask-based HTTP server implementing TAP protocol endpoints
1112

1213
## Features
1314

1415
### Implemented
1516
- ✅ Synchronous query endpoint (`/sync`)
16-
- ✅ ADQL query parsing (SELECT, FROM, WHERE, LIMIT)
17+
- ✅ Advanced ADQL query parsing using queryparser library
18+
- SELECT with column list or *
19+
- FROM with table names (including schema.table)
20+
- WHERE clause with comparison operators
21+
- CONTAINS with POINT and CIRCLE for cone searches
22+
- TOP/LIMIT clauses
23+
- ✅ ADQL to LSDB code generation
1724
- ✅ VOTable XML response format
1825
- ✅ Service capabilities endpoint (`/capabilities`)
1926
- ✅ Tables metadata endpoint (`/tables`)
2027
- ✅ Error handling with VOTable error responses
21-
- ✅ Sample data generation
28+
- ✅ Sample data generation (for testing without actual LSDB catalogs)
2229

2330
### Not Yet Implemented
24-
- ⏳ Actual query execution against database
31+
- ⏳ Actual query execution against LSDB catalogs (currently returns sample data)
2532
- ⏳ Asynchronous query support (`/async`)
2633
- ⏳ Additional output formats (CSV, JSON, FITS)
2734
- ⏳ Authentication and authorization
@@ -52,12 +59,20 @@ The server will start on `http://localhost:5000`
5259
curl -X POST http://localhost:5000/sync \
5360
-d "REQUEST=doQuery" \
5461
-d "LANG=ADQL" \
55-
-d "QUERY=SELECT ra, dec, mag FROM ztf_dr14 WHERE mag < 20 LIMIT 10"
62+
-d "QUERY=SELECT TOP 10 ra, dec, mag FROM ztf_dr14 WHERE mag < 20"
63+
```
64+
65+
#### Cone Search Query:
66+
```bash
67+
curl -X POST http://localhost:5000/sync \
68+
-d "REQUEST=doQuery" \
69+
-d "LANG=ADQL" \
70+
-d "QUERY=SELECT TOP 15 source_id, ra, dec, phot_g_mean_mag FROM gaia_dr3.gaia WHERE 1 = CONTAINS(POINT('ICRS', 270.0, 23.0), CIRCLE('ICRS', 270.0, 23.0, 0.25))"
5671
```
5772

5873
#### Using curl (GET request):
5974
```bash
60-
curl "http://localhost:5000/sync?REQUEST=doQuery&LANG=ADQL&QUERY=SELECT%20*%20FROM%20ztf_dr14%20LIMIT%205"
75+
curl "http://localhost:5000/sync?REQUEST=doQuery&LANG=ADQL&QUERY=SELECT%20TOP%205%20*%20FROM%20ztf_dr14"
6176
```
6277

6378
#### Using Python requests:
@@ -68,7 +83,7 @@ url = 'http://localhost:5000/sync'
6883
params = {
6984
'REQUEST': 'doQuery',
7085
'LANG': 'ADQL',
71-
'QUERY': 'SELECT ra, dec, mag FROM ztf_dr14 WHERE mag < 20 LIMIT 10'
86+
'QUERY': 'SELECT TOP 10 ra, dec, mag FROM ztf_dr14 WHERE mag < 20'
7287
}
7388

7489
response = requests.post(url, data=params)
@@ -84,41 +99,64 @@ print(response.text)
8499

85100
### ADQL Query Examples
86101

87-
Select all columns:
102+
Select all columns with TOP:
88103
```sql
89-
SELECT * FROM ztf_dr14 LIMIT 10
104+
SELECT TOP 10 * FROM ztf_dr14
90105
```
91106

92107
Select specific columns:
93108
```sql
94-
SELECT ra, dec, mag FROM ztf_dr14 LIMIT 100
109+
SELECT TOP 100 ra, dec, mag FROM ztf_dr14
95110
```
96111

97112
With WHERE clause:
98113
```sql
99-
SELECT ra, dec, mag FROM ztf_dr14 WHERE mag < 20 LIMIT 50
114+
SELECT TOP 50 ra, dec, mag FROM ztf_dr14 WHERE mag < 20
115+
```
116+
117+
Cone search with spatial constraint:
118+
```sql
119+
SELECT TOP 15 source_id, ra, dec, phot_g_mean_mag
120+
FROM gaia_dr3.gaia
121+
WHERE 1 = CONTAINS(
122+
POINT('ICRS', 270.0, 23.0),
123+
CIRCLE('ICRS', 270.0, 23.0, 0.25)
124+
)
100125
```
101126

102127
## ADQL to LSDB Conversion
103128

104-
The `adql_to_lsdb.py` module can also be used standalone to convert ADQL queries to LSDB code:
129+
The TAP server uses the `bin/adql_to_lsdb` module to convert ADQL queries to LSDB Python code. This module can also be used standalone:
105130

106-
```python
107-
from adql_to_lsdb import adql_to_lsdb, parse_adql
131+
```bash
132+
cd ../bin
133+
python adql_to_lsdb.py < sample.adql
134+
```
108135

109-
# Parse an ADQL query
110-
query = "SELECT ra, dec, mag FROM ztf_dr14 WHERE mag < 20 LIMIT 100"
111-
parsed = parse_adql(query)
112-
print(parsed)
136+
Or from Python:
137+
```python
138+
import sys
139+
sys.path.insert(0, '../bin')
140+
from adql_to_lsdb import adql_to_lsdb
113141

114-
# Generate LSDB code
142+
query = "SELECT TOP 15 source_id, ra, dec FROM gaia_dr3.gaia WHERE phot_g_mean_mag < 16"
115143
lsdb_code = adql_to_lsdb(query)
116144
print(lsdb_code)
117145
```
118146

119-
Run the module directly to see example usage:
120-
```bash
121-
python adql_to_lsdb.py
147+
The generated code will look like:
148+
```python
149+
import lsdb
150+
151+
cat = lsdb.open_catalog(
152+
'https://data.lsdb.io/hats/gaia_dr3/gaia/',
153+
columns=[
154+
"source_id", "ra", "dec"
155+
],
156+
filters=[('phot_g_mean_mag', '<', 16)],
157+
)
158+
159+
result = cat.head(15)
122160
```
123161

124162
## Response Format

tap_server/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
44
A prototype implementation of a TAP (Table Access Protocol) server
55
following the IVOA TAP specification v1.1.
6-
"""
76
8-
from .adql_to_lsdb import parse_adql, adql_to_lsdb, ADQLParser
7+
This server uses the bin/adql_to_lsdb module to convert ADQL queries
8+
to LSDB Python code.
9+
"""
910

10-
__version__ = '0.1.0'
11-
__all__ = ['parse_adql', 'adql_to_lsdb', 'ADQLParser']
11+
__version__ = '0.2.0'

tap_server/adql_to_lsdb.py

Lines changed: 0 additions & 162 deletions
This file was deleted.

tap_server/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
Flask>=2.0.0
2+
queryparser-python3
3+
pandas

0 commit comments

Comments
 (0)