Skip to content

Write mapping support#25124

Merged
aaneja merged 1 commit intoprestodb:masterfrom
infvg:write-mapping
Jun 18, 2025
Merged

Write mapping support#25124
aaneja merged 1 commit intoprestodb:masterfrom
infvg:write-mapping

Conversation

@infvg
Copy link
Contributor

@infvg infvg commented May 15, 2025

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

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

== RELEASE NOTES ==

JDBC Driver Changes
* Improve type mapping API to add WriteMapping functionality.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label May 15, 2025
@infvg infvg marked this pull request as ready for review May 15, 2025 16:38
@infvg infvg requested a review from a team as a code owner May 15, 2025 16:38
@infvg infvg requested a review from ZacBlanco May 15, 2025 16:38
@prestodb-ci prestodb-ci requested review from a team, NivinCS and bibith4 and removed request for a team May 15, 2025 16:38
@infvg infvg force-pushed the write-mapping branch 4 times, most recently from 50a7742 to e7b8684 Compare May 15, 2025 17:13
@infvg infvg requested a review from pratyakshsharma May 15, 2025 17:13
@infvg infvg force-pushed the write-mapping branch 8 times, most recently from b03db2f to de13a86 Compare May 20, 2025 09:16
@infvg infvg changed the title [DNR] Write mapping support Write mapping support May 20, 2025
Copy link
Contributor

@ZacBlanco ZacBlanco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few initial comments

@infvg infvg force-pushed the write-mapping branch 2 times, most recently from c065212 to 84ded12 Compare May 22, 2025 08:31
@github-actions
Copy link

github-actions bot commented May 22, 2025

Codenotify: Notifying subscribers in CODENOTIFY files for diff 91a8685...1218d8c.

No notifications.

@infvg infvg force-pushed the write-mapping branch 2 times, most recently from 3af817a to 5f8e951 Compare May 25, 2025 08:15
Copy link
Contributor

@pratyakshsharma pratyakshsharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these explicit casts to respective writeFunctions needed?

Copy link
Contributor Author

@infvg infvg May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes these are the default write functions for these types & will be used when getting a write function for a specific type.

}
else {
throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
((ObjectWriteFunction) writeFunction).set(statement, parameter, type.getObject(block, position));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this can cover all other types properly and if we should wrap this in try-catch with a proper user facing error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read Object flow is wrapped in try-catch already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

else {
throw new UnsupportedOperationException("Can't handle type: " + typeAndValue.getType());
//no inspection, unchecked raw types
((ObjectWriteFunction) writeFunction).set(statement, parameterIndex, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a try-catch here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

public static ColumnMapping sliceMapping(Type prestoType, SliceReadFunction readFunction, SliceWriteFunction writeFunction)
{
return new ColumnMapping(prestoType, readFunction, writeFunction);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ColumnMapping for objects is missing. Please add that and move the class variables above the methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: returning -> using

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still not done. Please double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
super(connectorId, config, "\"", new DriverConnectionFactory(new Driver(), config));
this.jsonType = typeManager.getType(new TypeSignature(StandardTypes.JSON));
this.uuidType = typeManager.getType(new TypeSignature(StandardTypes.UUID));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we removing this? I think you mentioned something about this during our discussion that I cannot recall now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we miss adding support for this since you have added support for TIME, TIME_WITH_TIME_ZONE and TIMESTAMP_WITH_TIME_ZONE.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@infvg infvg force-pushed the write-mapping branch 2 times, most recently from 3b33147 to 5e75eb4 Compare May 28, 2025 13:10
@pratyakshsharma
Copy link
Contributor

@ZacBlanco can you please take another pass on this

ZacBlanco
ZacBlanco previously approved these changes Jun 9, 2025
Co-authored-by: pratyakshsharma <pratyaksh13@gmail.com>
@pratyakshsharma
Copy link
Contributor

@tdcmeehan @aaneja @ZacBlanco can you guys take a pass and approve this?

@prestodb-ci
Copy link
Contributor

@ethanyzhang imported this issue as lakehouse/tracker #25124

@aaneja aaneja merged commit f19fee9 into prestodb:master Jun 18, 2025
97 checks passed
@prestodb-ci prestodb-ci mentioned this pull request Jul 28, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants