jbonofre commented on code in PR #12897: URL: https://github.com/apache/iceberg/pull/12897#discussion_r2061143136
########## 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: I added a test in `TestPartitionSpecParser` testing when neither `source-id` and `source-ids` are provided: `testFromJsonWithoutSourceIdAndSourceIds()`. I will add additional tests regarding your previous comment. -- 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