-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Hello !
I encountered an error when casting LINESTRING_3D to GEOMETRY after reading from a Parquet file.
When I declare a geometry using the GeoArrow style, everything works fine:
SELECT [{'x': -122, 'y': 47, 'z': 18},
{'x': -123, 'y': 46, 'z': 17},
{'x': -124, 'y': 45, 'z': 17}]::LINESTRING_3D::GEOMETRY AS geometry
However, when I store this geometry as LINESTRING_3D in a Parquet file :
COPY(
SELECT [{'x': -122, 'y': 47, 'z': 18},
{'x': -123, 'y': 46, 'z': 17},
{'x': -124, 'y': 45, 'z': 17}]::LINESTRING_3D as geometry
) TO 'test_linestring_3d_float.parquet' (FORMAT 'parquet')
And then try to read and cast it to GEOMETRY, I get the following error:
SELECT geometry::LINESTRING_3D::GEOMETRY AS geom
FROM read_parquet('test_linestring_3d.parquet')
Error message:
Conversion Error: Unimplemented type for cast (STRUCT(x DOUBLE, y DOUBLE, z DOUBLE)[] -> GEOMETRY)
when casting from source column geometry (Line Number: 1)
Casting works if I first cast to LINESTRING_2D instead of LINESTRING_3D.
Additional Observation
I was able to cast the LINESTRING_3D from Parquet to GEOMETRY by first casting it to STRUCT(x FLOAT, y FLOAT, z FLOAT)[], then to LINESTRING_3D, and finally to GEOMETRY.
Here’s the query that works:
SELECT geometry::STRUCT(x FLOAT, y FLOAT, z FLOAT)[]::LINESTRING_3D::GEOMETRY AS geom
FROM read_parquet('test_linestring_3d_float.parquet')
This raises two questions:
- Why is it necessary to go through a STRUCT of FLOAT instead of DOUBLE?
- This workaround introduces an extra cast and, if the file is stored as FLOAT, it becomes unreadable by GDAL and QGIS.
It reminds me of a related issue: (#197)
DuckDB version: 1.4.1
Thanks