Conversation
50a7742 to
e7b8684
Compare
b03db2f to
de13a86
Compare
ZacBlanco
left a comment
There was a problem hiding this comment.
A few initial comments
presto-postgresql/src/main/java/com/facebook/presto/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/com/facebook/presto/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/main/java/com/facebook/presto/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
c065212 to
84ded12
Compare
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 91a8685...1218d8c. No notifications. |
3af817a to
5f8e951
Compare
pratyakshsharma
left a comment
There was a problem hiding this comment.
Thank you for raising the PR @infvg
Taken first pass and have few comments. Please let me know if something remains unclear
| .put(TIMESTAMP_WITH_TIME_ZONE, "timestamp with timezone") | ||
| .put(UuidType.UUID, "uuid") | ||
| private static final Map<Type, WriteMapping> TYPE_MAPPINGS = ImmutableMap.<Type, WriteMapping>builder() | ||
| .put(BOOLEAN, booleanMapping("boolean", (BooleanWriteFunction) booleanColumnMapping().getWriteFunction())) |
There was a problem hiding this comment.
Are these explicit casts to respective writeFunctions needed?
There was a problem hiding this comment.
Yes these are the default write functions for these types & will be used when getting a write function for a specific type.
presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BaseJdbcClient.java
Show resolved
Hide resolved
presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BaseJdbcClient.java
Outdated
Show resolved
Hide resolved
| } | ||
| else { | ||
| throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName()); | ||
| ((ObjectWriteFunction) writeFunction).set(statement, parameter, type.getObject(block, position)); |
There was a problem hiding this comment.
Wondering if this can cover all other types properly and if we should wrap this in try-catch with a proper user facing error?
There was a problem hiding this comment.
read Object flow is wrapped in try-catch already.
| else { | ||
| throw new UnsupportedOperationException("Can't handle type: " + typeAndValue.getType()); | ||
| //no inspection, unchecked raw types | ||
| ((ObjectWriteFunction) writeFunction).set(statement, parameterIndex, value); |
There was a problem hiding this comment.
Need a try-catch here as well
| public static ColumnMapping sliceMapping(Type prestoType, SliceReadFunction readFunction, SliceWriteFunction writeFunction) | ||
| { | ||
| return new ColumnMapping(prestoType, readFunction, writeFunction); | ||
| } |
There was a problem hiding this comment.
ColumnMapping for objects is missing. Please add that and move the class variables above the methods.
There was a problem hiding this comment.
Added a column mapping method - although currently it will be unused since none of the current supported types need it (postgresql array type will need it in the future).
| this.writeFunction = requireNonNull(writeFunction, "writeFunction is null"); | ||
| checkArgument( | ||
| type.getJavaType() == readFunction.getJavaType(), | ||
| "Presto type %s is not compatible with read function %s returning %s", |
There was a problem hiding this comment.
nit: returning -> using
There was a problem hiding this comment.
I think this is still not done. Please double check.
There was a problem hiding this comment.
My bad seems like it didn't get added to the commit - fixed.
| readFunction.getJavaType()); | ||
| checkArgument( | ||
| type.getJavaType() == writeFunction.getJavaType(), | ||
| "Presto type %s is not compatible with write function %s returning %s", |
| { | ||
| super(connectorId, config, "\"", new DriverConnectionFactory(new Driver(), config)); | ||
| this.jsonType = typeManager.getType(new TypeSignature(StandardTypes.JSON)); | ||
| this.uuidType = typeManager.getType(new TypeSignature(StandardTypes.UUID)); |
There was a problem hiding this comment.
why are we removing this? I think you mentioned something about this during our discussion that I cannot recall now.
There was a problem hiding this comment.
This was needed for to create the columnMapping for UUID types but since that is already in StandardColumnMappings we can remove the redundant implementation:
https://github.com/prestodb/presto/pull/25124/files#diff-625237786d8bc595087896db71d758467722c6dfeb8556e48c99420f96d5c842R125
| import static com.facebook.presto.common.type.SmallintType.SMALLINT; | ||
| import static com.facebook.presto.common.type.TimeType.TIME; | ||
| import static com.facebook.presto.common.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; | ||
| import static com.facebook.presto.common.type.TimestampType.TIMESTAMP; |
There was a problem hiding this comment.
Did we miss adding support for this since you have added support for TIME, TIME_WITH_TIME_ZONE and TIMESTAMP_WITH_TIME_ZONE.?
There was a problem hiding this comment.
Yeah I didn't see any implementations for them in the original (although I don't think they had proper support back then so it probably was not missed, just not needed).
There was a problem hiding this comment.
Right, all of them were not supported back then. Since you added support for some of them now, was just checking to see if you missed TIMESTAMP somehow
There was a problem hiding this comment.
Ah, I see - Timestamp types require some type info to get the correct write function so the implementation for timestamp is here:
https://github.com/prestodb/presto/pull/25124/files#diff-a585323eb9886bcb1569de59ffc9ba78fb29e5da66b43666aa0072a8de747172R816
3b33147 to
5e75eb4
Compare
|
@ZacBlanco can you please take another pass on this |
9651460 to
f0d25c6
Compare
Co-authored-by: pratyakshsharma <pratyaksh13@gmail.com>
f0d25c6 to
1218d8c
Compare
|
@tdcmeehan @aaneja @ZacBlanco can you guys take a pass and approve this? |
|
@ethanyzhang imported this issue as lakehouse/tracker #25124 |
Description
Currently, write mapping is hard coded in JdbcPageSink.appendColumn, making it difficult to add additional write support. This PR adds WriteMapping to match the ReadMapping functionality & make it possible to add additional type support on a per connector basis.
Motivation and Context
It will allow us to support additional types on a per connector basis
Impact
None
Test Plan
Unit tests
Contributor checklist
Release Notes