duckdb / duckdb/duckdb-spatial
Bug in native geometry types casting to geometry while reading from parquet.
- Dominant language
- C
- Stars
- 708
- Forks
- 96
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 5
Description
I'm doing some heavy operations on geometries and I thought that I might optimize the queries by using POINT_2D, LINESTRING_2D and POLYGON_2D objects for saving in parquet files and skip reading from and to `wkb` between steps when saving to parquet.
Casting from linestring (or polygon) to geometry works flawlessly when I create the geometries natively in DuckDB, but when I try to read it from parquet, it doesn't work and I get this error: `Conversion Error: Unimplemented type for cast (STRUCT(x DOUBLE, y DOUBLE)[] -> GEOMETRY)`
Steps to reproduce:
```python
import duckdb
connection = duckdb.connect()
for extension_name in ["parquet", "spatial"]:
connection.install_extension(extension_name)
connection.load_extension(extension_name)
connection.sql(f"""
SELECT [struct_pack(x := 10, y := 2), struct_pack(x := 7, y := 4)]::LINESTRING_2D linestring
""")
# ┌──────────────────────────────┐
# │ linestring │
# │ struct(x double, y double)[] │
# ├──────────────────────────────┤
# │ LINESTRING (10 2, 7 4) │
# └──────────────────────────────┘
connection.sql(f"""
SELECT [struct_pack(x := 10, y := 2), struct_pack(x := 7, y := 4)]::LINESTRING_2D::GEOMETRY linestring
""")
# ┌────────────────────────┐
# │ linestring │
# │ geometry │
# ├────────────────────────┤
# │ LINESTRING (10 2, 7 4) │
# └────────────────────────┘
connection.sql(f"""
COPY (
SELECT [struct_pack(x := 10, y := 2), struct_pack(x := 7, y := 4)]::LINESTRING_2D linestring
) TO 'test.parquet' (FORMAT 'parquet')
""")
connection.sql(f"""
SELECT linestring::LINESTRING_2D FROM read_parquet('test.parquet')
""")
# ┌───────────────────────────────────────────────┐
# │ parsed_linestring │
# │ struct(x double, y double)[] │
# ├───────────────────────────────────────────────┤
# │ [{'x': 10.0, 'y': 2.0}, {'x': 7.0, 'y': 4.0}] │
# └───────────────────────────────────────────────┘
connection.sql(f"""
SELECT linestring::LINESTRING_2D::GEOMETRY FROM read_parquet('test.parquet')
""")
# ConversionException: Conversion Error: Unimplemented type for cast (STRUCT(x DOUBLE, y DOUBLE)[] -> GEOMETRY)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.