Add support for PostgreSQL arrays#317
Add support for PostgreSQL arrays#317findepi merged 4 commits intotrinodb:masterfrom vincentpoon:jdbc_arrays
Conversation
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/BaseJdbcClient.java
Outdated
Show resolved
Hide resolved
...tgresql/src/test/java/io/prestosql/plugin/postgresql/TestPostgreSqlIntegrationSmokeTest.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
|
Thanks @ebyhr , updated with your suggestions |
|
@ebyhr thanks for doing first review pass. Appreciated! @vincentpoon thanks for your PR! In my opinion, there are some design changes to be done. In particular, I don't like the fact that we're constructing My suggestion regarding moving it forward:
I don't have yet answer on how cc @electrum |
|
Thanks for looking at this @findepi . Agree that the new methods in BaseJdbcClient here aren't ideal - I think that was a result of me trying to push as much reusable code up into BaseJdbcClient as possible. This work actually came out of my work on the Phoenix connector (#76) as I figured I could get rid of a lot of array-specific stuff there if I made a more general solution. But as you suggest, perhaps it's best to leave a lot of this in the specific jdbc implementations. The Let me try to rework this a little. AFAIK, the main thing with jdbc ARRAY is there's no standard naming convention (but that's already true with other types, which is why we have e.g. WriteMapping#getDataType), and no standard in terms of what ResultSet#getArray returns you (as the javadoc clearly states). |
|
@findepi I updated this, now that #454 is merged. There's less impact on base-jdbc now, and all the ARRAY-related functionality is in presto-postgresql. I couldn't quite implement Let me know what you think, thanks! |
findepi
left a comment
There was a problem hiding this comment.
@vincentpoon apologies, i didn't review the main part (the value handling) of the PR.
Here are some comments I have so far. Please ping me back if you have any doubts (or when PR updated).
good job, btw!
There was a problem hiding this comment.
Recently, there was a need to further customize the metadata loading.
See
#408 (comment)
#408 (comment)
in that PR we ended up with a bit of a hack, but I was thinking about changing the base jdbc client to make such customized metadata loading possible. For that, the subclass would need to be able to control not only ResultSet → JdbcTypeHandle conversion but also how the ResultSet is init'd.
However, I'm also thinking that sometimes, a connector would override io.prestosql.plugin.jdbc.BaseJdbcClient#getColumns(io.prestosql.spi.connector.ConnectorSession, io.prestosql.plugin.jdbc.JdbcTableHandle) directly (for example if i would like to add some caching in my connector). So I don't see clearly yet how such extensible API would look like.
Also, in current approach, getArrayDimensions(ConnectorSession session, JdbcTableHandle tableHandle, String columnName) gets called for every array column separately and roundtrip times add up.
For these reasons, I would suggest that you do not introduce this method. Instead, I'd suggest that you override getColumns in postgres client directly. I am aware this will introduce code duplication.
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcTypeHandle.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
That's not correct. With legacy timestamp semantics (default), prestoNative is a utc millis (Java timestamp) which interpreted in session zone yields year/month/day/hour/minutes that the value represents.
OTOH, java.sql.TImestamp(x) treats x as utc millis (Java timestamp) which interpreted in JVM zone yields year/month/day/hour/minutes that the value represents.
To fix this you would need:
- write different conversion code
- pass
ConnectorSessionso that the code can do condition onio.prestosql.spi.connector.ConnectorSession#isLegacyTimestamp
... and even then the code would not be generic. java.sql.Timestamp cannot represent certain values and many JDBC drivers (but not all) support java.time.LocalDateTime and we should use that.
For this reasons, the prestoNativeToJdbcObject cannot be done in a generic way, without connector-specific code. I would therefore suggest two things:
- move this conversion to PostgresClient (or some companion helper utility class -- if possible)
- then make sure there are no unnecessary changes in
StandardColumnMappings.java(i would expect none are needed)
- then make sure there are no unnecessary changes in
- pass
ConnectorSessionhere - remove support for time and timestamp types from this PR. It's easy to get them wrong and it's better that we focus on more generic stuff first and add timestamp arrays later.
- to ensure we (and others) do not forget about timesamps and the necessary abstractions they require, I would keep the
TIMESTAMP.equals(prestoType)condition like:if (TIMESTAMP.equals(prestoType)) { throw new PrestoException(.....); // TODO
- to ensure we (and others) do not forget about timesamps and the necessary abstractions they require, I would keep the
There was a problem hiding this comment.
It's safer to throw when we don't know what to do:
throw new PrestoException( .... "Unsupported type: " + prestoType);
There was a problem hiding this comment.
prestoTypeis what actually matters, so include that in the message (prestoNative.getClass()will be alwaysSlicehere)- i am not sure
FUNCTION_IMPLEMENTATION_ERRORis the right error code... if you can't find anything more proper, use generic err code instead
There was a problem hiding this comment.
nit: per the code style, we do not write else when not necessary, ie when the then block always returns.
I would remove else and also add blank space before subsequent if (here & for all cases below)
|
@findepi I've updated this with two separate commits. The first only adds Thanks for your helpful comments, it's looking a lot better now. |
|
@vincentpoon thanks! i'll try to look into this during the week. I understanding this is taking time, but conceptually not a simple change. (at least for me.) @guyco33 i remember you saying you're using postgres arrays and |
@vincentpoon to be clear: i am not sure this will be applicable. This needs trying / more thinking. |
|
Thanks, I'll take a look at |
|
@findepi I've pushed another commit with new Also, apparently PostgreSQL's JDBC driver doesn't yet support varbinary arrays, so I removed support for that. |
findepi
left a comment
There was a problem hiding this comment.
@vincentpoon good job!
this looks very well.
I had a bunch of comments, mostly editorial.
Sorry for having you wait long. I am very busy lately.
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcTypeHandle.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
is it possible? Do you have a test with char[] created in postgres?
There was a problem hiding this comment.
test is in table prestoCreateAsSelect("test_array_parameterized_char_unicode")
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/TypeUtils.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/TypeUtils.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/TypeUtils.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/TypeUtils.java
Outdated
Show resolved
Hide resolved
|
@findepi Thanks again for the review, I have pushed a new squashed revision. I believe I have addressed all the comments, and have replied to some specifically. |
|
LGTM. Thanks @vincentpoon for working on this. |
|
@findepi rebased |
findepi
left a comment
There was a problem hiding this comment.
@vincentpoon apologies. Apparently I didn't publish my comments when I was writing "LGTM".
Publishing them now.
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/TypeUtils.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/TypeUtils.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/test/java/io/prestosql/plugin/postgresql/TestPostgreSqlTypeMapping.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
|
Thanks @findepi , addressed your latest comments |
|
Merged, thanks! |
|
Note: as per #687, this needs to be explicitly enabled. cc @hashbash (prestodb/presto#11422), @troels (prestodb/presto#8849) |
This adds support for multidimensional ARRAY types in PostgreSql.