-
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
Support setting column types in PostgreSQL connector #15591
Conversation
abf6c4e
to
433df5f
Compare
976659d
to
7458bc8
Compare
JdbcTableHandle tableHandle = (JdbcTableHandle) table; | ||
JdbcColumnHandle columnHandle = (JdbcColumnHandle) column; | ||
verify(!tableHandle.isSynthetic(), "Not a table reference: %s", tableHandle); | ||
jdbcClient.setColumnType(session, tableHandle, columnHandle, 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.
jdbcClient can be given the table name (JdbcNamedRelationHandle
), not the full handle
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.
The context of existing full handle seems that third-party developers may use authorization
field. Let me keep as-is in this PR.
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.
cc: @Praveen2112 It seems if authorization field is non-empty we should fail all operations?
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.
Yes.
protected SetColumnTypeSetup applyColumnMapping(SetColumnTypeSetup setup) | ||
{ | ||
if (setup.oldColumnType().equals("timestamp(3) with time zone")) { | ||
return new SetColumnTypeSetup(setup.oldColumnType(), setup.newColumnType(), setup.oldValueLiteral(), "timestamp '2020-02-12 14:03:00.123000 +00: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.
Add a comment
.build(); | ||
} | ||
|
||
public record SetColumnTypeSetup(String oldColumnType, String newColumnType, String oldValueLiteral, String newValueLiteral) {} |
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.
add null checks
public SetColumnTypeSetup
{
requireNonNull(oldColumnType, "oldColumnType is null");
requireNonNull(newColumnType, "newColumnType is null");
requireNonNull(oldValueLiteral, "oldValueLiteral is null");
requireNonNull(newValueLiteral, "newValueLiteral is null");
}
public void testSetColumnType(SetColumnTypeSetup setup) | ||
{ | ||
if (!hasBehavior(SUPPORTS_SET_COLUMN_TYPE)) { | ||
assertQueryFails("ALTER TABLE nation ALTER COLUMN nationkey SET DATA TYPE bigint", "This connector does not support setting column 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.
the check ignores @DataProvider
(and that's fine), so it should be invoked once
not @DataProvider
's element count times
.matches("VALUES " + setup.newValueLiteral); | ||
} | ||
finally { | ||
assertUpdate("DROP TABLE IF EXISTS " + tableName); |
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.
Use TestTable please
.add(new SetColumnTypeSetup("smallint", "integer", "32767", "32767")) | ||
.add(new SetColumnTypeSetup("integer", "bigint", "2147483647", "bigint '2147483647'")) | ||
.add(new SetColumnTypeSetup("bigint", "integer", "-2147483648", "-2147483648")) | ||
.add(new SetColumnTypeSetup("decimal(5,3)", "decimal(38,3)", "12.345", "12.345")) |
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.
for decimals, let's exercise
short -> short
long -> long
short -> long
also, we should exercise precision reduction
- when actual values can be converted without loss
- when actual values need to be rounded (i think they should round, instead of faliing)
.add(new SetColumnTypeSetup("decimal(5,3)", "decimal(38,3)", "12.345", "12.345")) | ||
.add(new SetColumnTypeSetup("date", "date", "date '2023-01-04'", "date '2023-01-04'")) | ||
.add(new SetColumnTypeSetup("time(3)", "time(6)", "time '15:03:00.123'", "time '15:03:00.123000'")) | ||
.add(new SetColumnTypeSetup("timestamp(3)", "timestamp(6)", "timestamp '2020-02-12 15:03:00.123'", "timestamp '2020-02-12 15:03:00.123000'")) |
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.
Add tests with time/timestamp precision reduction
- when actual values can be converted without loss
- when actual values need to be rounded (i think they should round, instead of faliing)
.add(new SetColumnTypeSetup("timestamp(3)", "timestamp(6)", "timestamp '2020-02-12 15:03:00.123'", "timestamp '2020-02-12 15:03:00.123000'")) | ||
.add(new SetColumnTypeSetup("timestamp(3) with time zone", "timestamp(6) with time zone", "timestamp '2020-02-12 15:03:00.123 +01:00'", "timestamp '2020-02-12 15:03:00.123000 +01:00'")) | ||
.add(new SetColumnTypeSetup("char(100)", "varchar", "'char-to-varchar'", "'char-to-varchar'")) | ||
.add(new SetColumnTypeSetup("varchar", "char(100)", "'varchar-to-char'", "cast('varchar-to-char' as char(100))")) |
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.
add char & varchar tests with length reduction
.collect(toDataProvider()); | ||
} | ||
|
||
protected SetColumnTypeSetup applyColumnMapping(SetColumnTypeSetup setup) |
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.
Can we give this method a better name?
also
- how a connector can say this particular conversion isn't support in this connector case? (ie turn positive test case into a negative one)
- see
io.trino.testing.BaseConnectorTest.DataMappingTestSetup#asUnsupported
- see
- how a connector can say this particular conversion is problematic, needs to be skipped (TODO + issue)?
- see
io.trino.testing.BaseConnectorTest#filterDataMappingSmokeTestData
, it returns Optional for this reason
- see
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.
how a connector can say this particular conversion isn't support in this connector case? (ie turn positive test case into a negative one)
Let me handle this in follow-up as the logic is unreachable in this PR.
how a connector can say this particular conversion is problematic, needs to be skipped (TODO + issue)?
Changed to optional type.
} | ||
|
||
@DataProvider | ||
public Object[][] setColumnTypesProvider() |
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.
Provider -> DataProvider (at least that's my convention)
2a73a62
to
b60541d
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.
I don't have useful comments - just about enum ordering. Sorry.
Looks good otherwise.
case SUPPORTS_SET_COLUMN_TYPE: | ||
return false; | ||
|
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.
above SUPPORTS_DELETE?
@@ -87,6 +87,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_COMMENT_ON_COLUMN: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT
?
@@ -96,6 +96,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_COMMENT_ON_COLUMN: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT
@@ -70,6 +70,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT?
@@ -86,6 +86,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_ADD_COLUMN_WITH_COMMENT: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT
@@ -105,6 +105,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_ADD_COLUMN_WITH_COMMENT: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT?
@@ -76,6 +76,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_ADD_COLUMN_WITH_COMMENT: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT
@@ -78,6 +78,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_ADD_COLUMN_WITH_COMMENT: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT
@@ -66,6 +66,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | |||
case SUPPORTS_ADD_COLUMN_WITH_COMMENT: | |||
return false; | |||
|
|||
case SUPPORTS_SET_COLUMN_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.
together with ADD_COLUMN_WITH_COMMENT
d657f05
to
e217f11
Compare
e217f11
to
5575667
Compare
@ebyhr should we add any docs for this? |
@colebow We need to refactor the docs first as the current granularity is |
Description
Relates to #15515
Additional context and related issues
Release notes
(x) Release notes are required, with the following suggested text: