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

support geometric data types #302

Open
tconbeer opened this issue Nov 2, 2023 · 2 comments
Open

support geometric data types #302

tconbeer opened this issue Nov 2, 2023 · 2 comments
Labels
duckdb enhancement New feature or request

Comments

@tconbeer
Copy link
Owner

tconbeer commented Nov 2, 2023

e.g., POINT from spatial renders as binary instead of something like POINT (-117.93367 34.34613)

@tconbeer tconbeer added the enhancement New feature or request label Nov 2, 2023
@tconbeer
Copy link
Owner Author

image

load spatial;
select st_point(0, 0) as pt

@tconbeer
Copy link
Owner Author

tconbeer commented Nov 10, 2023

This will be hard, since duckdb casts it to binary when fetching an arrow table:

>>> cur = conn.sql("select st_point(0, 0) as pt")
>>> pat = cur.fetch_arrow_table()
>>> pat
pyarrow.Table
pt: binary
----
pt: [[0000180000000000000000000100000000000000000000000000000000000000]]

It's also binary when casting to python:

>>> cur.fetchall()
[(b'\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',)]

It does, however, tell you that it's a GEOMETRY type:

>>> cur.dtypes
[GEOMETRY]

The st_astext spatial function exports well:

>>> cur = conn.sql("select st_astext(st_point(0, 0)) as pt")
>>> cur.fetch_arrow_table()
pyarrow.Table
pt: string
----
pt: [["POINT (0 0)"]]

So this would work:

>>> cur = conn.sql("select st_point(0, 0) as pt")
>>> rewritten = cur.project("st_astext(pt)")
>>> rewritten.fetch_arrow_table()
pyarrow.Table
st_astext(pt): string
----
st_astext(pt): [["POINT (0 0)"]]

(We would NOT want to do this rewriting when exporting the data, only when loading the table; we would also need to maintain the types)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duckdb enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant