Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASB-29242: Update reserved ADQL/SQL keywords #28

Merged
merged 6 commits into from
Oct 21, 2024
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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "vo-models"
version = "0.4.1"
version = "0.4.2"
authors = [
{name = "Joshua Fraustro", email="[email protected]"},
{name = "MAST Archive Developers", email="[email protected]"}
Expand Down
18 changes: 18 additions & 0 deletions tests/vodataservice/vodataservice_models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ def test_write_to_xml(self):
canonicalize(self.test_xml, strip_text=True),
)

def test_reserved_adql_words(self):
"""Test that reserved ADQL/SQL words are properly escaped in column names"""

non_reserved = TableParam(column_name="aperture")
reserved_no_quotes = TableParam(column_name="distance")
reserved_single_quotes = TableParam(column_name="'offset'")
reserved_mixed_quotes = TableParam(column_name='"\'top\'"')

self.assertEqual(non_reserved.column_name, "aperture")
self.assertEqual(reserved_no_quotes.column_name, '"distance"')
self.assertEqual(reserved_single_quotes.column_name, '"offset"')
self.assertEqual(reserved_mixed_quotes.column_name, '"top"')

self.assertIn("<name>aperture</name>", non_reserved.to_xml(encoding=str))
self.assertIn("<name>\"distance\"</name>", reserved_no_quotes.to_xml(encoding=str))
self.assertIn("<name>\"offset\"</name>", reserved_single_quotes.to_xml(encoding=str))
self.assertIn("<name>\"top\"</name>", reserved_mixed_quotes.to_xml(encoding=str))


class TestTableElement(TestCase):
"""Test the Table element model"""
Expand Down
13 changes: 11 additions & 2 deletions vo_models/adql/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"CATALOG",
"CHAR",
"CHARACTER",
"CHARACTER_LENGTH",
"CHAR_LENGTH",
"CHARACTER_LENGTH",
"CHECK",
"CLOSE",
"COALESCE",
Expand Down Expand Up @@ -238,6 +238,7 @@
"ATAN2",
"CEILING",
"COS",
"COT",
"DEGREES",
"EXP",
"FLOOR",
Expand All @@ -252,7 +253,6 @@
"SIN",
"SQRT",
"TAN",
"TOP",
"TRUNCATE",
# ADQL geometry keywords
"AREA",
Expand All @@ -268,4 +268,13 @@
"POINT",
"POLYGON",
"REGION",
# Cast functions and datatypes
"BIGINT",
# String functions and operators
"ILIKE",
# Conversion functions
"IN_UNIT",
# Cardinality
"OFFSET",
"TOP",
]
3 changes: 2 additions & 1 deletion vo_models/vodataservice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def validate_colname(cls, value: str):

value: - The column name to escape.
"""
if value.upper() in ADQL_SQL_KEYWORDS:
if value.strip("'\"").upper() in ADQL_SQL_KEYWORDS:
value = value.strip("'\"")
value = f'"{value}"'
return value

Expand Down