danny0405 commented on a change in pull request #11950:
URL: https://github.com/apache/flink/pull/11950#discussion_r421991959



##########
File path: 
flink-table/flink-table-planner-blink/src/test/java/org/apache/flink/table/planner/operations/SqlToOperationConverterTest.java
##########
@@ -634,6 +697,139 @@ public void testAlterTable() throws Exception {
                assertEquals(properties, 
alterTablePropertiesOperation.getCatalogTable().getProperties());
        }
 
+       @Test
+       public void testAlterTableAddPkConstraint() throws Exception {
+               Catalog catalog = new GenericInMemoryCatalog("default", 
"default");
+               catalogManager.registerCatalog("cat1", catalog);
+               catalog.createDatabase("db1", new CatalogDatabaseImpl(new 
HashMap<>(), null), true);
+               CatalogTable catalogTable = new CatalogTableImpl(
+                               TableSchema.builder()
+                                               .field("a", 
DataTypes.STRING().notNull())
+                                               .field("b", 
DataTypes.BIGINT().notNull())
+                                               .field("c", DataTypes.BIGINT())
+                                               .build(),
+                               new HashMap<>(),
+                               "tb1");
+               catalogManager.setCurrentCatalog("cat1");
+               catalogManager.setCurrentDatabase("db1");
+               catalog.createTable(new ObjectPath("db1", "tb1"), catalogTable, 
true);
+               // Test alter add table constraint.
+               Operation operation = parse("alter table tb1 add constraint ct1 
primary key(a, b) not enforced",
+                               SqlDialect.DEFAULT);
+               assert operation instanceof AlterTableAddConstraintOperation;
+               AlterTableAddConstraintOperation addConstraintOperation =
+                               (AlterTableAddConstraintOperation) operation;
+               assertThat(addConstraintOperation.asSummaryString(),
+                               is("ALTER TABLE ADD CONSTRAINT: (identifier: 
[`cat1`.`db1`.`tb1`], "
+                                               + "constraintName: [ct1], 
columns: [a, b])"));
+               // Test alter table add pk on nullable column
+               exceptionRule.expect(ValidationException.class);
+               exceptionRule.expectMessage("Could not create a PRIMARY KEY 
'ct1'. Column 'c' is nullable.");
+               parse("alter table tb1 add constraint ct1 primary key(c) not 
enforced",
+                               SqlDialect.DEFAULT);
+       }
+
+       @Test
+       public void testAlterTableAddPkConstraintEnforced() throws Exception {

Review comment:
       Yes, i changes to test the unique constraint enforced.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to