Skip to content

Commit 22c0b2c

Browse files
committed
Deny adding a not null column in Redshift connector
1 parent 989e624 commit 22c0b2c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import io.trino.plugin.jdbc.ObjectWriteFunction;
3939
import io.trino.plugin.jdbc.PreparedQuery;
4040
import io.trino.plugin.jdbc.QueryBuilder;
41+
import io.trino.plugin.jdbc.RemoteTableName;
4142
import io.trino.plugin.jdbc.SliceWriteFunction;
4243
import io.trino.plugin.jdbc.StandardColumnMappings;
4344
import io.trino.plugin.jdbc.WriteMapping;
@@ -58,6 +59,7 @@
5859
import io.trino.spi.TrinoException;
5960
import io.trino.spi.connector.AggregateFunction;
6061
import io.trino.spi.connector.ColumnHandle;
62+
import io.trino.spi.connector.ColumnMetadata;
6163
import io.trino.spi.connector.ConnectorSession;
6264
import io.trino.spi.connector.JoinCondition;
6365
import io.trino.spi.connector.JoinStatistics;
@@ -442,6 +444,17 @@ public OptionalLong delete(ConnectorSession session, JdbcTableHandle handle)
442444
}
443445
}
444446

447+
@Override
448+
protected void addColumn(ConnectorSession session, Connection connection, RemoteTableName table, ColumnMetadata column)
449+
throws SQLException
450+
{
451+
if (!column.isNullable()) {
452+
// Redshift doesn't support adding not null columns without default expression
453+
throw new TrinoException(NOT_SUPPORTED, "This connector does not support adding not null columns");
454+
}
455+
super.addColumn(session, connection, table, column);
456+
}
457+
445458
@Override
446459
protected void verifySchemaName(DatabaseMetaData databaseMetadata, String schemaName)
447460
throws SQLException

plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftConnectorTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
7676
return false;
7777

7878
case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
79+
case SUPPORTS_ADD_COLUMN_NOT_NULL_CONSTRAINT:
7980
case SUPPORTS_SET_COLUMN_TYPE:
8081
return false;
8182

@@ -198,6 +199,15 @@ public Object[][] redshiftTypeToTrinoTypes()
198199
{"TIMESTAMPTZ", "timestamp(6) with time zone"}};
199200
}
200201

202+
@Test
203+
public void testRedshiftAddNotNullColumn()
204+
{
205+
try (TestTable table = new TestTable(getQueryRunner()::execute, TEST_SCHEMA + ".test_add_column_", "(col int)")) {
206+
assertThatThrownBy(() -> onRemoteDatabase().execute("ALTER TABLE " + table.getName() + " ADD COLUMN new_col int NOT NULL"))
207+
.hasMessageContaining("ERROR: ALTER TABLE ADD COLUMN defined as NOT NULL must have a non-null default expression");
208+
}
209+
}
210+
201211
@Override
202212
public void testDelete()
203213
{

0 commit comments

Comments
 (0)