pvary commented on a change in pull request #3912:
URL: https://github.com/apache/iceberg/pull/3912#discussion_r790760598



##########
File path: 
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveSchemaUtil.java
##########
@@ -170,6 +172,38 @@ public void testConversionWithoutLastComment() {
     Assert.assertEquals(expected.asStruct(), schema.asStruct());
   }
 
+  @Test
+  public void testRebuildSchemaWithIdentifierFieldIds() {
+    Schema actualSchema = 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+            ImmutableSet.of("id", "name"));
+
+    List<Types.NestedField> columns = 
Lists.newArrayList(COMPLEX_ICEBERG_SCHEMA.columns());
+    columns.set(0, columns.get(0).asRequired());
+    columns.set(1, columns.get(1).asRequired());
+    Schema expectedSchema = new Schema(columns, ImmutableSet.of(0, 1));
+
+    Assert.assertEquals(SchemaParser.toJson(expectedSchema), 
SchemaParser.toJson(actualSchema));
+  }
+
+  @Test
+  public void testRebuildSchemaWithIdentifierFieldIdsError() {
+    Assert.assertThrows("Cannot add field `not_exist_column` as an identifier 
field: " +
+                    "the field must exist on the root level",
+            IllegalArgumentException.class,
+            () -> 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+                    ImmutableSet.of("id", "not_exist_column")));
+    Assert.assertThrows("Cannot add field `employee_info.id` as an identifier 
field: " +
+                    "the field must exist on the root level",
+            IllegalArgumentException.class,
+            () -> 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+                    ImmutableSet.of("id", "employee_info.id")));
+    Assert.assertThrows("Cannot add field `employee_info` as an identifier 
field: " +
+                    "only primitive fields are allowed",
+            IllegalArgumentException.class,
+            () -> 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+                    ImmutableSet.of("id", "employee_info")));
+  }
+

Review comment:
       Can we add tests for the new `convert` methods where we check the 
identifiers?

##########
File path: 
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveSchemaUtil.java
##########
@@ -170,6 +172,38 @@ public void testConversionWithoutLastComment() {
     Assert.assertEquals(expected.asStruct(), schema.asStruct());
   }
 
+  @Test
+  public void testRebuildSchemaWithIdentifierFieldIds() {
+    Schema actualSchema = 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+            ImmutableSet.of("id", "name"));
+
+    List<Types.NestedField> columns = 
Lists.newArrayList(COMPLEX_ICEBERG_SCHEMA.columns());
+    columns.set(0, columns.get(0).asRequired());
+    columns.set(1, columns.get(1).asRequired());
+    Schema expectedSchema = new Schema(columns, ImmutableSet.of(0, 1));
+
+    Assert.assertEquals(SchemaParser.toJson(expectedSchema), 
SchemaParser.toJson(actualSchema));
+  }
+
+  @Test
+  public void testRebuildSchemaWithIdentifierFieldIdsError() {
+    Assert.assertThrows("Cannot add field `not_exist_column` as an identifier 
field: " +
+                    "the field must exist on the root level",
+            IllegalArgumentException.class,
+            () -> 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+                    ImmutableSet.of("id", "not_exist_column")));
+    Assert.assertThrows("Cannot add field `employee_info.id` as an identifier 
field: " +
+                    "the field must exist on the root level",
+            IllegalArgumentException.class,
+            () -> 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+                    ImmutableSet.of("id", "employee_info.id")));
+    Assert.assertThrows("Cannot add field `employee_info` as an identifier 
field: " +
+                    "only primitive fields are allowed",
+            IllegalArgumentException.class,
+            () -> 
HiveSchemaUtil.rebuildSchemaWithIdentifierFieldIds(COMPLEX_ICEBERG_SCHEMA,
+                    ImmutableSet.of("id", "employee_info")));
+  }
+

Review comment:
       Could we add tests for the new `convert` methods where we check the 
identifiers please?




-- 
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: [email protected]

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to