Skip to content

Commit

Permalink
The Freetext constraint now qualifies res_subject.
Browse files Browse the repository at this point in the history
This helps certain SQLServer-based implementations while not impacting
compliant ones; consider this defensive programming.
  • Loading branch information
msdemlei committed May 8, 2023
1 parent 0b6b7b6 commit dec257d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/registry/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ RegTAP services using:
... for r in res)))
http://dc.zah.uni-heidelberg.de/tap
http://gavo.aip.de/tap
http://vao.stsci.edu/RegTAP/TapService.aspx
http://voparis-rr.obspm.fr:80/tap
https://vao.stsci.edu/RegTAP/TapService.aspx



Expand Down
16 changes: 8 additions & 8 deletions pyvo/dal/tests/test_tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,21 +751,21 @@ def test_missing_featurelist(self, tapservice):

def test_get_featurelist(self, tapservice):
features = tapservice.get_tap_cap().get_adql().get_feature_list(
"ivo://ivoa.net/std/TAPRegExt#features-adqlgeo")
"ivo://ivoa.net/std/TAPRegExt#features-adqlgeo")
assert set(f.form for f in features) == {
'CENTROID', 'CONTAINS', 'COORD1', 'POLYGON',
'INTERSECTS', 'COORD2', 'BOX', 'AREA', 'DISTANCE',
'REGION', 'CIRCLE', 'POINT'}
'CENTROID', 'CONTAINS', 'COORD1', 'POLYGON',
'INTERSECTS', 'COORD2', 'BOX', 'AREA', 'DISTANCE',
'REGION', 'CIRCLE', 'POINT'}

def test_get_missing_feature(self, tapservice):
assert tapservice.get_tap_cap().get_adql().get_feature(
"ivo://ivoa.net/std/TAPRegExt#features-adqlgeo",
"Garage") == None
"ivo://ivoa.net/std/TAPRegExt#features-adqlgeo",
"Garage") == None

def test_get_feature(self, tapservice):
feature = tapservice.get_tap_cap().get_adql().get_feature(
"ivo://ivoa.net/std/TAPRegExt#features-adqlgeo",
"AREA")
"ivo://ivoa.net/std/TAPRegExt#features-adqlgeo",
"AREA")
assert feature.form == "AREA"
assert feature.description == None

Expand Down
6 changes: 3 additions & 3 deletions pyvo/registry/rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _get_union_condition(self, service):
"SELECT ivoid FROM rr.resource WHERE"
" 1=ivo_hasword(res_title, {{{parname}}})",
"SELECT ivoid FROM rr.res_subject WHERE"
" res_subject ILIKE {{{parpatname}}}"]
" rr.res_subject.res_subject ILIKE {{{parpatname}}}"]
self._fillers, subqueries = {}, []

for index, word in enumerate(self.words):
Expand All @@ -266,7 +266,7 @@ def _get_or_condition(self, service):
base_queries = [
" 1=ivo_hasword(res_description, {{{parname}}})",
" 1=ivo_hasword(res_title, {{{parname}}})",
" res_subject ILIKE {{{parpatname}}}"]
" rr.res_subject.res_subject ILIKE {{{parpatname}}}"]
self._fillers, conditions = {}, []

for index, word in enumerate(self.words):
Expand Down Expand Up @@ -660,7 +660,7 @@ def get_search_condition(self, service):
# something as esoteric as a server that understands
# MOC-based geometries but does not have a MOC function.
if not service.get_tap_cap().get_adql().get_feature(
"ivo://org.gavo.dc/std/exts#extra-adql-keywords", "MOC"):
"ivo://org.gavo.dc/std/exts#extra-adql-keywords", "MOC"):
raise RegTAPFeatureMissing("Current RegTAP service"
" does not support MOC.")

Expand Down
2 changes: 1 addition & 1 deletion pyvo/registry/tests/commonfixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_tap_cap(self):


FAKE_GAVO = _FakeTAPService({
("ivo://ivoa.net/std/TAPRegExt#features-adql-sets", "UNION"),
("ivo://ivoa.net/std/TAPRegExt#features-adql-sets", "UNION"),
("ivo://org.gavo.dc/std/exts#extra-adql-keywords", "MOC"),
}, {
"rr.stc_spatial": None,
Expand Down
5 changes: 3 additions & 2 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def keywordstest_callback(request, context):
assert "ivo_hasword(res_description, 'vizier')" in query
assert "1=ivo_hasword(res_title, 'vizier')" in query

assert " res_subject ILIKE '%pulsar%'" in query
assert ".res_subject ILIKE '%pulsar%'" in query
assert "1=ivo_hasword(res_description, 'pulsar')" in query
assert "1=ivo_hasword(res_title, 'pulsar')" in query

Expand All @@ -88,7 +88,7 @@ def keywordstest_callback(request, context):
data = dict(parse_qsl(request.body))
query = data['QUERY']

assert "OR res_subject ILIKE '%single%'" in query
assert "OR rr.res_subject.res_subject ILIKE '%single%'" in query
assert "1=ivo_hasword(res_description, 'single') " in query
assert "1=ivo_hasword(res_title, 'single')" in query

Expand Down Expand Up @@ -840,6 +840,7 @@ def test_sia2_service_operation():
assert "s_dec" in res.to_table().columns


@pytest.mark.remote_data
def test_endpoint_switching():
alt_svc = "http://vao.stsci.edu/RegTAP/TapService.aspx"
previous_url = regtap.REGISTRY_BASEURL
Expand Down
27 changes: 13 additions & 14 deletions pyvo/registry/tests/test_rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,30 @@ def test_basic(self):
assert rtcons.Freetext("star").get_search_condition(FAKE_GAVO) == (
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'star') "
"UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'star') "
"UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%star%')")
"UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%star%')")

def test_interesting_literal(self):
assert rtcons.Freetext("α Cen's planets").get_search_condition(FAKE_GAVO) == (
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'α Cen''s planets')"
" UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'α Cen''s planets')"
" UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%α Cen''s planets%')")
" UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%α Cen''s planets%')")

def test_multipleLiterals(self):
assert rtcons.Freetext("term1", "term2"
).get_search_condition(FAKE_GAVO) == (
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'term1')"
" UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'term1')"
" UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%term1%')"
" UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%term1%')"
" AND "
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'term2')"
" UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'term2')"
" UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%term2%')")
" UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%term2%')")

def test_adaption_to_service(self):
assert rtcons.Freetext("term1", "term2"
).get_search_condition(FAKE_PLAIN) == (
"( 1=ivo_hasword(res_description, 'term1') OR 1=ivo_hasword(res_title, 'term1') OR res_subject ILIKE '%term1%')"
" AND ( 1=ivo_hasword(res_description, 'term2') OR 1=ivo_hasword(res_title, 'term2') OR res_subject ILIKE '%term2%')")
"( 1=ivo_hasword(res_description, 'term1') OR 1=ivo_hasword(res_title, 'term1') OR rr.res_subject.res_subject ILIKE '%term1%')"
" AND ( 1=ivo_hasword(res_description, 'term2') OR 1=ivo_hasword(res_title, 'term2') OR rr.res_subject.res_subject ILIKE '%term2%')")


class TestAuthorConstraint:
Expand Down Expand Up @@ -253,14 +253,14 @@ def test_SkyCoord_Circle(self):
assert cons._extra_tables == ["rr.stc_spatial"]

def test_no_MOC(self):
cons = registry.Spatial((SkyCoord(3 * units.deg, -30 * units.deg), 3))
cons = registry.Spatial((SkyCoord(3 * u.deg, -30 * u.deg), 3))
with pytest.raises(rtcons.RegTAPFeatureMissing) as excinfo:
cons.get_search_condition(FAKE_PLAIN)
assert (str(excinfo.value)
== "Current RegTAP service does not support MOC.")

def test_no_spatial_table(self):
cons = registry.Spatial((SkyCoord(3 * units.deg, -30 * units.deg), 3))
cons = registry.Spatial((SkyCoord(3 * u.deg, -30 * u.deg), 3))
previous = FAKE_GAVO.tables.pop("rr.stc_spatial")
try:
with pytest.raises(rtcons.RegTAPFeatureMissing) as excinfo:
Expand Down Expand Up @@ -310,7 +310,7 @@ def test_frequency_interval(self):
" 5.830941732e-26, 6.758591553e-26)")

def test_no_spectral(self):
cons = registry.Spectral((88 * units.MHz, 102 * units.MHz))
cons = registry.Spectral((88 * u.MHz, 102 * u.MHz))
with pytest.raises(rtcons.RegTAPFeatureMissing) as excinfo:
cons.get_search_condition(FAKE_PLAIN)
assert (str(excinfo.value)
Expand Down Expand Up @@ -341,15 +341,14 @@ def test_multi_times_rejected(self):
" be made from single time instants.")

def test_no_temporal(self):
cons = registry.Temporal((time.Time(2459000, format='jd'),
time.Time(59002, format='mjd')))
cons = registry.Temporal((Time(2459000, format='jd'),
Time(59002, format='mjd')))
with pytest.raises(rtcons.RegTAPFeatureMissing) as excinfo:
cons.get_search_condition(FAKE_PLAIN)
assert (str(excinfo.value)
== "stc_temporal missing on current RegTAP service")



class TestWhereClauseBuilding:
@staticmethod
def where_clause_for(*args, **kwargs):
Expand Down Expand Up @@ -401,11 +400,11 @@ def test_with_legacy_keyword(self):
'(ivoid IN (SELECT ivoid FROM rr.resource WHERE '
"1=ivo_hasword(res_description, 'plain') UNION SELECT ivoid FROM rr.resource "
"WHERE 1=ivo_hasword(res_title, 'plain') UNION SELECT ivoid FROM "
"rr.res_subject WHERE res_subject ILIKE '%plain%'))\n"
"rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%plain%'))\n"
' AND (ivoid IN (SELECT ivoid FROM rr.resource WHERE '
"1=ivo_hasword(res_description, 'string') UNION SELECT ivoid FROM rr.resource "
"WHERE 1=ivo_hasword(res_title, 'string') UNION SELECT ivoid FROM "
"rr.res_subject WHERE res_subject ILIKE '%string%'))")
"rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%string%'))")


class TestSelectClause:
Expand Down

0 comments on commit dec257d

Please sign in to comment.