-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add WKB Support for PostGIS Geometry Columns #5580
Comments
For anyone wanting to work on this, this would probably be similar to how we handle PostgreSQL's json and jsonb types |
GeoAlchemy2 has wrapper classes for parsing and handling them (eg. WKBElement) |
i have the same erro too. can i have some way to read postgis geometry by trino? |
For a workaround until this is implemented see https://trinodb.slack.com/archives/CFLB9AMBN/p1624597418210800?thread_ts=1624544478.194000&cid=CFLB9AMBN |
It's true. And If data I achieved this by overriding @Override
public PreparedStatement buildSql(ConnectorSession session, Connection connection, JdbcSplit split, JdbcTableHandle table, List<JdbcColumnHandle> columns)
throws SQLException
{
Map<String, String> supposedColumnExpressions = new HashMap<>();
for (JdbcColumnHandle column : columns) {
JdbcTypeHandle jdbcTypeHandle = column.getJdbcTypeHandle();
if (jdbcTypeHandle.getJdbcTypeName().isPresent() && jdbcTypeHandle.getJdbcTypeName().get().equals("geometry")) {
String columnName = column.getColumnName();
log.info("Find geometry type, changing '%s' to '%s'", columnName, "ST_AsBinary(\"" + columnName + "\")");
supposedColumnExpressions.put(columnName, "ST_AsBinary(\"" + columnName + "\")");
}
}
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (Map.Entry<String, String> entry : supposedColumnExpressions.entrySet()) {
builder.put(entry.getKey(), entry.getValue());
}
Map<String, String> columnExpressions = builder.build();
PreparedQuery preparedQuery = prepareQuery(session, connection, table, Optional.empty(), columns, columnExpressions, Optional.of(split));
return new QueryBuilder(this).prepareStatement(session, connection, preparedQuery);
} To see the difference, I have a simple query:
This is the output after changing:
The result of If you have any suggestions, feel free to comment. |
Hi, some more progress here(keep up with the following changes). Adding private static ColumnMapping geometryColumnMapping()
{
return ColumnMapping.sliceMapping(
GEOMETRY,
(resultSet, columnIndex) -> stGeomFromBinary(wrappedBuffer(resultSet.getBytes(columnIndex))),
(statement, index, value) -> { throw new TrinoException(NOT_SUPPORTED, "Geometry type is not supported for INSERT"); },
DISABLE_PUSHDOWN);
} And adding lines in switch (jdbcTypeName) {
case "geometry":
return Optional.of(geometryColumnMapping());
case "money":
return Optional.of(moneyColumnMapping()); Finally I got result with a little trick like:
The reason for my trick is related with the type verifying process, specifically related with lines in verify(
columnHandle.getColumnType().equals(columnMapping.getType()),
"Type mismatch: column handle has type %s but %s is mapped to %s",
columnHandle.getColumnType(), columnHandle.getJdbcTypeHandle(), columnMapping.getType()); I can't pass this verification until I override I guess there is some problem in @findepi @hashhar Sorry for bothering, but I have been working on the following problem for days and didn't get significant progress. I think with this problem solved we'll be very close to the final solution. |
I closed #9845. I found getting this.jsonType = typeManager.getType(new TypeSignature(JSON)); Now I'm really close to the final solution. One more thing to pass through is to pass postgres-connector's test. |
@njanakiev, @lerenah I've created a PR for this issue. |
Thanks, will give it a shot! |
any luck the |
If possible I will give some time to retry solving this issue. The last PR is holding for too long time, I my self don't think it could be successfully merged. |
we patched your pr and played a bit. yes it shows geometry better, we could do some cross db sjoin now :) |
No, currently these pushdowns should be implemented by yourself. Filter expression can be easily implemented in JDBC connectors if you understand the usage of expression rewriter in #7994. I start focusing on these issues this time last year, but moved to another work this year. And since I can see your company in your profile. I guess you are working on similar thing like last year I do. To support better spatial query ability, Trino definitely has a long way to go, so you should be very careful to think about the cost if you decide to use Trino. |
I think this issue could be closed since PR #24053 was merged |
Thanks for reminding @umartin, indeed. |
Hello, thanks for the great project!
While trying to access geometry columns with the PostgreSQL connector, I wasn't able to access the PostGIS geometry column inside a table:
The same query works with Python together Pandas and SQLAlchemy:
As far as I understand PostGIS stores geometries in the WKB format including more metadata like SRID:
I think this would be a great addition to do spatial joins with federated queries by simply treating the geometry columns as WKB without the projection for example. PostGIS differentiates between Geometries and Geography. Geometry columns are more common from what I know.
Tested on Presto version 344 (with Java 11)
The text was updated successfully, but these errors were encountered: