-
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
Improve type mapping for Snowflake Connector #21012
Conversation
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.
Docs look like a great improvements .. just minor suggestion. For code reviews I pulled in Erik and Teng
plugin/trino-snowflake/src/main/java/io/trino/plugin/snowflake/SnowflakeClient.java
Outdated
Show resolved
Hide resolved
ColumnMapping columnMap = standardColumnMappings.get(type); | ||
if (columnMap != null) { | ||
return Optional.of(columnMap); | ||
switch (type) { |
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.
Please change the case
orders as PostgreSqlClient. Same for toWriteMapping method.
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 can do that. But would it be a better idea to let the order be same as what's in https://docs.snowflake.com/en/sql-reference/intro-summary-data-types?
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.
Please do. Orders in Trino is more important than Snowflake for consistency with other connectors.
plugin/trino-snowflake/src/main/java/io/trino/plugin/snowflake/SnowflakeClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-snowflake/src/main/java/io/trino/plugin/snowflake/SnowflakeClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-snowflake/src/main/java/io/trino/plugin/snowflake/SnowflakeClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-snowflake/src/main/java/io/trino/plugin/snowflake/SnowflakeClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-snowflake/src/main/java/io/trino/plugin/snowflake/SnowflakeClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-snowflake/src/test/java/io/trino/plugin/snowflake/TestSnowflakeConnectorTest.java
Show resolved
Hide resolved
plugin/trino-snowflake/src/test/java/io/trino/plugin/snowflake/TestSnowflakeTypeMapping.java
Outdated
Show resolved
Hide resolved
.addRoundTrip("TIMESTAMP_TZ(0)", "'2020-09-27 12:34:56 -08:00'::TIMESTAMP_TZ", createTimestampWithTimeZoneType(0), "TIMESTAMP '2020-09-27 12:34:56 -08:00'") | ||
.addRoundTrip("TIMESTAMP_TZ(3)", "'2020-09-27 12:34:56.333 -08:00'::TIMESTAMP_TZ", createTimestampWithTimeZoneType(3), "TIMESTAMP '2020-09-27 12:34:56.333 -08:00'") | ||
.addRoundTrip("TIMESTAMP_TZ(9)", "'2020-09-27 12:34:56.999999999 -08:00'::TIMESTAMP_TZ", createTimestampWithTimeZoneType(9), "TIMESTAMP '2020-09-27 12:34:56.999999999 -08:00'") | ||
.execute(getQueryRunner(), session, snowflakeCreateAndInsert("tpch.test_timestamptz_sf_insert")); | ||
SqlDataTypeTest.create() | ||
.addRoundTrip("TIMESTAMP(0) WITH TIME ZONE", "TIMESTAMP '2020-09-27 12:34:56 -08:00'", createTimestampWithTimeZoneType(0), "TIMESTAMP '2020-09-27 12:34:56 -08:00'") | ||
.addRoundTrip("TIMESTAMP(3) WITH TIME ZONE", "TIMESTAMP '2020-09-27 12:34:56.333 -08:00'", createTimestampWithTimeZoneType(3), "TIMESTAMP '2020-09-27 12:34:56.333 -08:00'") | ||
.addRoundTrip("TIMESTAMP(9) WITH TIME ZONE", "TIMESTAMP '2020-09-27 12:34:56.999999999 -08:00'", createTimestampWithTimeZoneType(9), "TIMESTAMP '2020-09-27 12:34:56.999999999 -08:00'") |
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.
Please add more test cases, e.g. null, min, max, julian->gregorian calendar switch and etc.
You can refer to TestPostgreSqlTypeMapping class.
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.
Ack. I just read the existing test cases in TestSnowflakeTypeMapping::testDate
. It's testing min/max values like 0001-01-01
and 99999-12-31
. However, years beyond the range 1582~9999
are not recommended by Snowflake: https://docs.snowflake.com/en/sql-reference/data-types-datetime#date. Do we actually want to remove them? Also, I feel it's best to test Gregorian Calendar with leap days like 2024-02-29
. I can actually create a separate PR to clean this up, altogether with testDate
, testTimestamp
, and testTimestampWithTimeZone
. What do you think?
Could you rebase on master to resolve conflicts? |
So sorry @lxynov but it looks like there is another rebase necessary since there is a conflict. I hope we can get this reviewed and merged before we get another conflict. Maybe @oneonestar @dprophet or @yuuteng can chime in if necesssary |
@mosabua No worry at all. Happy to rebase it again. Conflicts should be minimal. Thanks for keeping an eye on this. @ebyhr Could you help look at this #21012 (comment)? If it makes sense, I'll go ahead rebasing this PR. |
The current commit and PR title is unclear. Please clarify what is improved. |
Sure
|
Thanks for your explanation. Also, please split into some commits so that we can review easily.
Why do we want to make it configurable? |
It's not a design decision to "change all numeric types to decimal". It's just to make things correct. In Snowflake, fixed-point types Additionally, even if you create a
If the service admin is sure that all decimal columns don't have values larger than
IMOO I don't think we need to split it into multiple commits. Essentially, this PR is to improve the implementation of CC'ing @hashhar @findepi @martint if you have bandwidth to also take a look. |
keeping cleanup separate from type mapping change would be very very helpful to review. otherwise it's hard to see which changes impact logic vs which ones don't. I'll try and take a look anyway but unlikely to merge in current shape. |
This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua |
Applied stale-ignore label .. we definitely want this improvement. Please rebase @lxynov and let us know if you need any help |
Superseded by #21755 |
Description
For #20977
Please reference
snowflake.md
diff for the exact type conversion behavior.References for source-of-truths:
Additional context and related issues
JDBC_TREAT_DECIMAL_AS_INT
is set toFALSE
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.
(x) Release notes are required, with the following suggested text: