liamzwbao commented on code in PR #13072: URL: https://github.com/apache/iceberg/pull/13072#discussion_r2159777330
########## flink/v2.0/flink/src/test/java/org/apache/iceberg/flink/sink/TestFlinkIcebergSinkV2DistributionMode.java: ########## @@ -122,7 +122,7 @@ public void before() throws IOException { @TestTemplate Review Comment: Did not add TableSchema tests for V2 as it is experimental ########## flink/v2.0/flink/src/test/java/org/apache/iceberg/flink/TestFlinkSchemaUtil.java: ########## @@ -369,6 +652,61 @@ public void testConvertFlinkSchemaBaseOnIcebergSchema() { Types.NestedField.optional(102, "string", Types.StringType.get())), Sets.newHashSet(101)); + ResolvedSchema flinkSchema = + new ResolvedSchema( + List.of( + Column.physical("int", DataTypes.INT().notNull()), + Column.physical("string", DataTypes.STRING().nullable())), + Collections.emptyList(), + UniqueConstraint.primaryKey("pk", List.of("int"))); + Schema convertedSchema = FlinkSchemaUtil.convert(baseSchema, flinkSchema); + assertThat(convertedSchema.asStruct()).isEqualTo(baseSchema.asStruct()); + assertThat(convertedSchema.identifierFieldIds()).containsExactly(101); + } + + @Test + public void testConvertFlinkSchemaWithPrimaryKeys() { + Schema icebergSchema = + new Schema( + Lists.newArrayList( + Types.NestedField.required(1, "int", Types.IntegerType.get()), + Types.NestedField.required(2, "string", Types.StringType.get())), + Sets.newHashSet(1, 2)); + + ResolvedSchema resolvedSchema = FlinkSchemaUtil.toResolvedSchema(icebergSchema); + assertThat(resolvedSchema.getPrimaryKey()) + .isPresent() + .get() + .satisfies(k -> assertThat(k.getColumns()).containsExactly("int", "string")); + } + + @Test + public void testConvertFlinkSchemaWithNestedColumnInPrimaryKeys() { + Schema icebergSchema = + new Schema( + Lists.newArrayList( + Types.NestedField.required( + 1, + "struct", + Types.StructType.of( + Types.NestedField.required(2, "inner", Types.IntegerType.get())))), + Sets.newHashSet(2)); + + assertThatThrownBy(() -> FlinkSchemaUtil.toResolvedSchema(icebergSchema)) + .isInstanceOf(ValidationException.class) + .hasMessageStartingWith("Invalid primary key") + .hasMessageContaining("Column 'struct.inner' does not exist."); + } + + @Test + public void testConvertFlinkTableSchemaBaseOnIcebergSchema() { + Schema baseSchema = Review Comment: Thanks for your feedback! It's much cleaner now -- 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. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org