RussellSpitzer commented on code in PR #12897:
URL: https://github.com/apache/iceberg/pull/12897#discussion_r2060518830
##########
core/src/test/java/org/apache/iceberg/TestPartitionSpecParser.java:
##########
@@ -95,6 +96,56 @@ public void testFromJsonWithFieldId() {
assertThat(spec.fields().get(1).fieldId()).isEqualTo(1000);
}
+ @TestTemplate
+ public void testFromJsonWithSourceIds() {
+ String specString =
+ "{\n"
+ + " \"spec-id\" : 1,\n"
+ + " \"fields\" : [ {\n"
+ + " \"name\" : \"id_bucket\",\n"
+ + " \"transform\" : \"bucket[8]\",\n"
+ + " \"source-ids\" : [ 1, 2 ],\n"
+ + " \"field-id\" : 1001\n"
+ + " }, {\n"
+ + " \"name\" : \"data_bucket\",\n"
+ + " \"transform\" : \"bucket[16]\",\n"
+ + " \"source-ids\" : [ 2, 3 ],\n"
+ + " \"field-id\" : 1000\n"
+ + " } ]\n"
+ + "}";
+
+ PartitionSpec spec = PartitionSpecParser.fromJson(table.schema(),
specString);
+
+ assertThat(spec.fields()).hasSize(2);
+ assertThat(spec.fields().get(0).sourceIds()).hasSize(2);
+ assertThat(spec.fields().get(1).sourceIds()).hasSize(2);
+ }
+
+ @TestTemplate
+ public void testFromJsonWithoutSourceIdAndSourceIds() {
+ String specString =
+ "{\n"
+ + " \"spec-id\" : 1,\n"
+ + " \"fields\" : [ {\n"
+ + " \"name\" : \"id_bucket\",\n"
+ + " \"transform\" : \"bucket[8]\",\n"
+ + " \"field-id\" : 1001\n"
+ + " }, {\n"
+ + " \"name\" : \"data_bucket\",\n"
+ + " \"transform\" : \"bucket[16]\",\n"
+ + " \"field-id\" : 1000\n"
+ + " } ]\n"
+ + "}";
+
+ assertThatThrownBy(
+ () -> {
+ PartitionSpecParser.fromJson(table.schema(), specString);
+ })
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(
+ "Cannot parse partition field, either source-id or source-ids has
to be present");
+ }
Review Comment:
We should have some tests for "toJson" as well?
We also need a check that the validation for identity transforms still holds
true. Ie you cannot make a multi-arg transform with the same name as any of the
columns
--
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]