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

Add read-only timestamp type support for vertica #24264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vlad-lyutenko
Copy link
Contributor

@vlad-lyutenko vlad-lyutenko commented Nov 26, 2024

Description

Vertica database has type - timestamp without time zone, but Vertica jdbc driver use java.sql.Timestamp for handling this type instead of java.time.LocalDateTime as other jdbc drivers.

So we cannot use this type for any write operations and pushdowns, because values will be automatically converted (because of java.sql.Timestamp) and
we can not guarantee correct results especially with DST rules.

However there is a way to overcome this issue, when we read the data. We can omit wrappers of java.sql.Timestampt by reading values directly as String from ResultSet. In this case we can correctly show this values in Trino.

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`issuenumber`)

@@ -118,6 +123,8 @@ public class VerticaClient
.appendValueReduced(ChronoField.YEAR, 4, 7, 1000)
.appendPattern("-MM-dd[ G]")
.toFormatter();
private static final DateTimeFormatter FORMATTER_ZERO_SCALE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter FORMATTER_SIX_SCALE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use optional fraction like OracleClient.TIMESTAMP_NANO_OPTIONAL_FORMATTER?

@@ -435,4 +444,36 @@ public OptionalInt getMaxColumnNameLength(ConnectorSession session)
{
return this.getMaxColumnNameLengthFromDatabaseMetaData(session);
}

private static LongWriteFunction timestampWriteFunction(TimestampType timestampType)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Move this method under timestampColumnMappingUsingString. We usually put a helper method after the caller.

@@ -228,6 +235,8 @@ public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connect
DATE,
(resultSet, index) -> LocalDate.parse(resultSet.getString(index), DATE_READ_FORMATTER).toEpochDay(),
dateWriteFunctionUsingString()));
case Types.TIMESTAMP:
Copy link
Member

Choose a reason for hiding this comment

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

Can we update vertica.md?

.build();

SqlDataTypeTest.create()
// before epoch
Copy link
Member

Choose a reason for hiding this comment

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

Can we add the following roundtrips?

@@ -228,6 +235,8 @@ public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connect
DATE,
(resultSet, index) -> LocalDate.parse(resultSet.getString(index), DATE_READ_FORMATTER).toEpochDay(),
dateWriteFunctionUsingString()));
case Types.TIMESTAMP:
return Optional.of(timestampColumnMappingUsingString(createTimestampType(typeHandle.requiredDecimalDigits())));
Copy link
Member

Choose a reason for hiding this comment

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

Vertica jdbc driver doesn't differentiate this types and use java.sql.Timestamp

I think we can recognize the type with JdbcTypeHandle#jdbcTypeName. Vertica returns Timestamp for timestamp type and TimestampTz for 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.

I think I need to rephrase this sentence, I mean - that Vertica jdbc driver use java.sql.Timestamp for both of this types, despite other drivers use java.time.LocalDateTime for timestamp without Time Zone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants