Skip to content

Sanitize geomcolname #769

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

Merged
merged 4 commits into from
Mar 14, 2025
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 lonboard/_geoarrow/_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _from_geometry(
# A poor-man's string interpolation check
# We can't pass in SQL-templated strings for the column name
re_match = r"[a-zA-Z][a-zA-Z0-9_]*"
assert re.match(
assert re.fullmatch(
re_match,
geom_col_name,
), f"Expected geometry column name to match regex: {re_match}"
Expand Down
22 changes: 22 additions & 0 deletions tests/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,25 @@ def test_geometry_only_column_type_geometry():

# Should create layer without erroring
_layer = ScatterplotLayer.from_duckdb(query, con)


def test_sanitize_column_name():
# For WKB parsing
pytest.importorskip("shapely")

con = duckdb.connect()
sql = f"""
INSTALL spatial;
LOAD spatial;
SELECT
* EXCLUDE geom,
geom as "non_alphanum_colname_()"
FROM ST_Read("{cities_gdal_path}");
"""
rel = con.sql(sql)

with pytest.raises(
AssertionError,
match="Expected geometry column name to match regex:",
):
viz(rel, con=con)