-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Use timestamp precision 3 in CTAS in MySQL #7166
Conversation
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thansk for the test method renames. It's much clearer now.
Some changes requested.
{ | ||
Session session = Session.builder(getSession()) | ||
.setTimeZoneKey(TimeZoneKey.getTimeZoneKey(sessionZone.getId())) | ||
.build(); | ||
|
||
// TODO merge this into the above SqlDataTypeTest once we support writing and reading timestamps with precisions other than 3 (TODO https://github.com/trinodb/trino/issues/6910) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this comment into the javadoc now. And change into the above
to testTimestampFromTrino
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on this comment, I've dropped this comment entirely. We don't need it to remind us that we'll need more tests when we support more precisions.
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
@@ -352,7 +352,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) | |||
} | |||
if (TIMESTAMP_MILLIS.equals(type)) { | |||
// TODO use `timestampWriteFunction` (https://github.com/trinodb/trino/issues/6910) | |||
return WriteMapping.longMapping("datetime", timestampWriteFunctionUsingSqlTimestamp(TIMESTAMP_MILLIS)); | |||
return WriteMapping.longMapping("datetime(3)", timestampWriteFunctionUsingSqlTimestamp(TIMESTAMP_MILLIS)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am reading correctly, this would only write TIMESTAMP(3)
as datetime(3)
and fallback to legacy write mapping for other types (which doesn't have a mapping for TIMESTAMP type at all so throwing an "Unsupported column type" error).
Let's change this branch to run for anything that is a TimestampType
and try to see if we can write as timestamp(p)
where p
is the precision obtained from the type. See SqlServerClient for reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a relatively straightforward change. I was comparing to create table
instead of insert
, but that way makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I think this way might be better, especially if we fix #6910 any time soon.
It doesn't really make sense for CTAS to allow more precisions than INSERT
, so I think we should always write as DATETIME(3)
until #6910.
That leaves us with the option to automatically convert all TIMESTAMP
s to precision 3 before inserting on CTAS, but I think that rejecting them is a less surprising behavior, especially if we're soon going to change it to allow other precisions soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely correct change. @hashhar note that other timesamps with other precision are simply not supported here and cannot be created at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this @jirassimok and @findepi . I missed that CTAS flow differs from INSERT.
I'll fix it in #6910 .
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
0c69010
to
8f58db6
Compare
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
/** | ||
* Read {@code TIMESTAMP}s inserted by MySql as Trino {@code TIMESTAMP}s | ||
*/ | ||
// TODO reuse these test cases in testTimestampFromTrino once we support timestamps with precisions other than 3 (https://github.com/trinodb/trino/issues/6910) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it will be reusable, unless MySQL supports picosecond precision
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Reuse" is the wrong word here.
Since we separated these tests into their own method, I think this comment is probably unnecessary. We'll need to add more tests when we support more precisions, which is all that this comment is saying now.
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
@@ -352,7 +352,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) | |||
} | |||
if (TIMESTAMP_MILLIS.equals(type)) { | |||
// TODO use `timestampWriteFunction` (https://github.com/trinodb/trino/issues/6910) | |||
return WriteMapping.longMapping("datetime", timestampWriteFunctionUsingSqlTimestamp(TIMESTAMP_MILLIS)); | |||
return WriteMapping.longMapping("datetime(3)", timestampWriteFunctionUsingSqlTimestamp(TIMESTAMP_MILLIS)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely correct change. @hashhar note that other timesamps with other precision are simply not supported here and cannot be created at all
- Separate tests that insert timestamps with Trino from tests that insert from MySQL - Move the Trino-insert tests after the MySQL-insert tests - Rename the timestamp test methods to state how they insert data
8f58db6
to
9a18806
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % leftover TODO comment.
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/TestMySqlTypeMapping.java
Outdated
Show resolved
Hide resolved
9a18806
to
2f2c19e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Do we have the same problem for MemSQL? |
Yes; I'm looking into it. |
This addresses #6909.
The first two commits are minor refactors to the MySql timestamp tests so they are organized in a way that separates CTAS failures from other failures.