Skip to content

Commit 2723ec3

Browse files
committed
remove the obsolete handling of the indexed objects
1 parent 21b77c4 commit 2723ec3

File tree

4 files changed

+19
-106
lines changed

4 files changed

+19
-106
lines changed

src/queryparser/common/common.py

+1-36
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,7 @@ def process_query(self, replace_schema_name=None, indexed_objects=None):
734734
:param replace_schema_name:
735735
A new schema name to be put in place of the original.
736736
737-
:param indexed_objects:
738-
A dictionary defining pgsphere objects to be replaced with
739-
precomputed (on the database level) columns. For example,
740-
741-
iob = {'spoint': ((('gdr2', 'gaia_source', 'ra'),
742-
('gdr2', 'gaia_source', 'dec'), 'pos'),)}
743-
744-
will replace 'spoint(RADIANS(ra), RADIANS(dec))' with a 'pos'
745-
column.
737+
:param indexed_objects: Deprecated
746738
747739
"""
748740
# Antlr objects
@@ -893,14 +885,6 @@ def process_query(self, replace_schema_name=None, indexed_objects=None):
893885
for i in mc])
894886
raise QueryError("Unreferenced column(s): '%s'." % unref_cols)
895887

896-
# If we have indexed_objects, we are also accessing those. We
897-
# need to add them into the columns stack:
898-
if indexed_objects is not None:
899-
for k, v in indexed_objects.items():
900-
for vals in v:
901-
touched_columns.append([[vals[0][0], vals[0][1], vals[2],
902-
None], None])
903-
904888
touched_columns = set([tuple(i[0]) for i in touched_columns])
905889

906890
# extract display_columns
@@ -942,25 +926,6 @@ def process_query(self, replace_schema_name=None, indexed_objects=None):
942926
if i[0][1] is not None else i[0][1]])
943927
for i in tables]))
944928

945-
# If there are any sphere-like objects (pgsphere...) that are indexed
946-
# we need to replace the ADQL translated query parts with the indexed
947-
# column names
948-
if indexed_objects is not None and self.sphere_listener is not None:
949-
# we need to correctly alias 'pos' columns
950-
for k, v in indexed_objects.items():
951-
indexed_objects[k] = list([list(i) for i in v])
952-
for i, vals in enumerate(v):
953-
for t in tables:
954-
if vals[0][0] == t[0][0] and vals[0][1] == t[0][1] and\
955-
t[1] is not None:
956-
indexed_objects[k][i][2] = t[1] + '.' +\
957-
indexed_objects[k][i][2]
958-
959-
sphere_listener = self.sphere_listener(columns, indexed_objects)
960-
self.walker.walk(sphere_listener, tree)
961-
for k, v in sphere_listener.replace_dict.items():
962-
self._query = self._query.replace(k, v)
963-
964929
@property
965930
def query(self):
966931
"""
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,3 @@
11
# -*- coding: utf-8 -*-
2-
3-
from __future__ import (absolute_import, print_function)
4-
5-
import antlr4
6-
7-
from .PostgreSQLParserListener import PostgreSQLParserListener
8-
9-
from ..common import process_column_name, get_column_name_listener
10-
11-
12-
class PgSphereListener(PostgreSQLParserListener):
13-
14-
def __init__(self, columns, indexed_objects=None):
15-
self.column_name_listener = get_column_name_listener(
16-
PostgreSQLParserListener)()
17-
self.walker = antlr4.ParseTreeWalker()
18-
19-
self.cctx_dict = {}
20-
for c in columns:
21-
try:
22-
# PgSphere sphere stuff can't be in the USING statement
23-
self.cctx_dict[c[3]] = c[:3]
24-
except IndexError:
25-
pass
26-
27-
self.indexed_objects = indexed_objects
28-
self.replace_dict = {}
29-
30-
def enterSpoint(self, ctx):
31-
try:
32-
spoint = self.indexed_objects['spoint']
33-
except KeyError:
34-
return
35-
36-
cn = process_column_name(self.column_name_listener, self.walker, ctx,
37-
'"')
38-
cols = []
39-
40-
for c in cn:
41-
try:
42-
cols.append(self.cctx_dict[c[3]])
43-
except KeyError:
44-
pass
45-
46-
if len(cols):
47-
for sp in spoint:
48-
if sp[0] == cols[0] and sp[1] == cols[1]:
49-
rt = ctx.start.getInputStream().getText(ctx.start.start,
50-
ctx.stop.stop)
51-
self.replace_dict[rt] = sp[2]
2+
#
3+
# Put any PostgreSQL specific listeners here.

src/queryparser/postgresql/postgresqlprocessor.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
from .PostgreSQLParser import PostgreSQLParser
1515
from .PostgreSQLParserListener import PostgreSQLParserListener
1616

17-
from .postgresqllisteners import PgSphereListener
18-
1917
from ..common import SQLQueryProcessor
2018

2119

2220
class PostgreSQLQueryProcessor(SQLQueryProcessor):
2321
def __init__(self, query=None):
2422
super().__init__(PostgreSQLLexer, PostgreSQLParser,
25-
PostgreSQLParserListener, '"', query,
26-
PgSphereListener)
23+
PostgreSQLParserListener, '"', query)

src/queryparser/testing/tests.yaml

+15-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# - display columns in form col_name: db.tab.col
88
# - tables accessed by the query
99
# - schema replacement name (optional)
10-
# - indexed objects (optional)
1110

1211
common_tests:
1312
-
@@ -164,7 +163,7 @@ common_tests:
164163
- ['foo.tab']
165164
- 'd': 'foo'
166165

167-
-
166+
-
168167
- SELECT DISTINCT t.table_name
169168
FROM tap_schema.tabs AS t
170169
JOIN tap_schema.cols AS c USING (table_name)
@@ -197,12 +196,12 @@ common_tests:
197196
- ['MDR1.FOF.x', 'MDR1.FOF.y', 'MDR1.FOF.z', 'MDR1.FOF.mass',
198197
'MDR1.FOF.snapnum']
199198
- ['limit', 'order by', 'group by']
200-
-
199+
-
201200
- ['x: MDR1.FOF.x', 'y: MDR1.FOF.y', 'z: MDR1.FOF.z',
202201
'mass: MDR1.FOF.mass']
203202
- ['MDR1.FOF']
204203

205-
-
204+
-
206205
- SELECT h.Mvir, h.spin, g.diskMassStellar,
207206
g.diskMassStellar/h.Mvir AS mass_ratio
208207
FROM MDPL2.Rockstar AS h, MDPL2.Galacticus AS g
@@ -380,16 +379,16 @@ common_tests:
380379
-
381380
-
382381
- ['db.tab', 'db.blem']
383-
382+
384383
-
385384
- SELECT t1.a, t2.b, t3.c, t4.z
386385
FROM d.tab t1, db2.tab t2, foo.tab t3, x.y t4
387386
- ['foo.tab.a', 'bar.tab.b', 'bas.tab.c', 'x.y.z']
388-
-
387+
-
389388
-
390389
- ['a: foo.tab.a', 'b: bar.tab.b', 'c: bas.tab.c', 'z: x.y.z']
391390
- ['foo.tab', 'bas.tab', 'bar.tab', 'x.y']
392-
-
391+
-
393392
'd': 'foo'
394393
'db2': 'bar'
395394
'foo': 'bas'
@@ -495,7 +494,7 @@ common_translation_tests:
495494
-
496495
-
497496

498-
497+
499498
mysql_tests:
500499
-
501500
- SELECT `fi@1`, fi2
@@ -624,20 +623,20 @@ mysql_tests:
624623
postgresql_tests:
625624
-
626625
- SELECT pdist(1000, 10, 11, 12, 11, 11, 12)
627-
-
628-
-
626+
-
627+
-
629628
- ['pdist']
630-
-
631-
-
629+
-
630+
-
632631

633632
-
634633
- SELECT DISTINCT ON ("source"."tycho2_id") "tycho2_id", "source"."tycho2_dist"
635634
FROM "applause_dr3"."source_calib" AS "source"
636635
- ['applause_dr3.source_calib.tycho2_id', 'applause_dr3.source_calib.tycho2_dist']
637-
-
638-
-
639-
-
640-
-
636+
-
637+
-
638+
-
639+
-
641640

642641
-
643642
- SELECT ra, dec FROM gdr1.gaia_source

0 commit comments

Comments
 (0)