Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions api/src/main/java/org/apache/iceberg/PartitionSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
* represented by a named {@link PartitionField}.
*/
public class PartitionSpec implements Serializable {
// IDs for partition fields start at 1000
private static final int PARTITION_DATA_ID_START = 1000;
// IDs for partition fields start at 10000
private static final int PARTITION_DATA_ID_START = 10000;

private final Schema schema;

Expand Down Expand Up @@ -575,8 +575,8 @@ static void checkCompatibility(PartitionSpec spec, Schema schema) {
}

static boolean hasSequentialIds(PartitionSpec spec) {
for (int i = 0; i < spec.fields.length; i += 1) {
if (spec.fields[i].fieldId() != PARTITION_DATA_ID_START + i) {
for (int i = 1; i < spec.fields.length; i += 1) {
if (spec.fields[i].fieldId() != spec.fields[i - 1].fieldId() + 1) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,40 +297,40 @@ public void testAutoSettingPartitionFieldIds() {
.truncate("s", 1, "custom_truncate")
.build();

assertThat(spec.fields().get(0).fieldId()).isEqualTo(1000);
assertThat(spec.fields().get(1).fieldId()).isEqualTo(1001);
assertThat(spec.fields().get(2).fieldId()).isEqualTo(1002);
assertThat(spec.fields().get(3).fieldId()).isEqualTo(1003);
assertThat(spec.lastAssignedFieldId()).isEqualTo(1003);
assertThat(spec.fields().get(0).fieldId()).isEqualTo(10000);
assertThat(spec.fields().get(1).fieldId()).isEqualTo(10001);
assertThat(spec.fields().get(2).fieldId()).isEqualTo(10002);
assertThat(spec.fields().get(3).fieldId()).isEqualTo(10003);
assertThat(spec.lastAssignedFieldId()).isEqualTo(10003);
}

@Test
public void testAddPartitionFieldsWithFieldIds() {
PartitionSpec spec =
PartitionSpec.builderFor(SCHEMA)
.add(1, 1005, "id_partition1", Transforms.bucket(4))
.add(1, 1006, "id_partition2", Transforms.bucket(5))
.add(1, 1002, "id_partition3", Transforms.bucket(6))
.add(1, 10005, "id_partition1", Transforms.bucket(4))
.add(1, 10006, "id_partition2", Transforms.bucket(5))
.add(1, 10002, "id_partition3", Transforms.bucket(6))
.build();

assertThat(spec.fields().get(0).fieldId()).isEqualTo(1005);
assertThat(spec.fields().get(1).fieldId()).isEqualTo(1006);
assertThat(spec.fields().get(2).fieldId()).isEqualTo(1002);
assertThat(spec.lastAssignedFieldId()).isEqualTo(1006);
assertThat(spec.fields().get(0).fieldId()).isEqualTo(10005);
assertThat(spec.fields().get(1).fieldId()).isEqualTo(10006);
assertThat(spec.fields().get(2).fieldId()).isEqualTo(10002);
assertThat(spec.lastAssignedFieldId()).isEqualTo(10006);
}

@Test
public void testAddPartitionFieldsWithAndWithoutFieldIds() {
PartitionSpec spec =
PartitionSpec.builderFor(SCHEMA)
.add(1, "id_partition2", Transforms.bucket(5))
.add(1, 1005, "id_partition1", Transforms.bucket(4))
.add(1, 10005, "id_partition1", Transforms.bucket(4))
.truncate("s", 1, "custom_truncate")
.build();

assertThat(spec.fields().get(0).fieldId()).isEqualTo(1000);
assertThat(spec.fields().get(1).fieldId()).isEqualTo(1005);
assertThat(spec.fields().get(2).fieldId()).isEqualTo(1006);
assertThat(spec.lastAssignedFieldId()).isEqualTo(1006);
assertThat(spec.fields().get(0).fieldId()).isEqualTo(10000);
assertThat(spec.fields().get(1).fieldId()).isEqualTo(10005);
assertThat(spec.fields().get(2).fieldId()).isEqualTo(10006);
assertThat(spec.lastAssignedFieldId()).isEqualTo(10006);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static String dataFileJsonWithRequiredOnly(PartitionSpec spec) {
+ "\"partition\":{},\"file-size-in-bytes\":10,\"record-count\":1,\"sort-order-id\":0}";
} else {
return "{\"spec-id\":0,\"content\":\"DATA\",\"file-path\":\"/path/to/data-a.parquet\",\"file-format\":\"PARQUET\","
+ "\"partition\":{\"1000\":1},\"file-size-in-bytes\":10,\"record-count\":1,\"sort-order-id\":0}";
+ "\"partition\":{\"10000\":1},\"file-size-in-bytes\":10,\"record-count\":1,\"sort-order-id\":0}";
}
}

Expand All @@ -144,7 +144,7 @@ private static String dataFileJsonWithAllOptional(PartitionSpec spec) {
+ "\"split-offsets\":[128,256],\"sort-order-id\":1}";
} else {
return "{\"spec-id\":0,\"content\":\"DATA\",\"file-path\":\"/path/to/data-with-stats.parquet\","
+ "\"file-format\":\"PARQUET\",\"partition\":{\"1000\":1},\"file-size-in-bytes\":350,\"record-count\":10,"
+ "\"file-format\":\"PARQUET\",\"partition\":{\"10000\":1},\"file-size-in-bytes\":350,\"record-count\":10,"
+ "\"column-sizes\":{\"keys\":[3,4],\"values\":[100,200]},"
+ "\"value-counts\":{\"keys\":[3,4],\"values\":[90,180]},"
+ "\"null-value-counts\":{\"keys\":[3,4],\"values\":[10,20]},"
Expand Down Expand Up @@ -281,7 +281,7 @@ private static String deleteFileJsonWithRequiredOnly(PartitionSpec spec) {
+ "\"file-format\":\"PARQUET\",\"partition\":{},\"file-size-in-bytes\":1234,\"record-count\":9}";
} else {
return "{\"spec-id\":0,\"content\":\"POSITION_DELETES\",\"file-path\":\"/path/to/delete-a.parquet\","
+ "\"file-format\":\"PARQUET\",\"partition\":{\"1000\":9},\"file-size-in-bytes\":1234,\"record-count\":9}";
+ "\"file-format\":\"PARQUET\",\"partition\":{\"10000\":9},\"file-size-in-bytes\":1234,\"record-count\":9}";
}
}

Expand All @@ -299,7 +299,7 @@ private static String deleteFileJsonWithAllOptional(PartitionSpec spec) {
+ "\"split-offsets\":[128],\"equality-ids\":[3],\"sort-order-id\":1}";
} else {
return "{\"spec-id\":0,\"content\":\"EQUALITY_DELETES\",\"file-path\":\"/path/to/delete-with-stats.parquet\","
+ "\"file-format\":\"PARQUET\",\"partition\":{\"1000\":9},\"file-size-in-bytes\":1234,\"record-count\":10,"
+ "\"file-format\":\"PARQUET\",\"partition\":{\"10000\":9},\"file-size-in-bytes\":1234,\"record-count\":10,"
+ "\"column-sizes\":{\"keys\":[3,4],\"values\":[100,200]},"
+ "\"value-counts\":{\"keys\":[3,4],\"values\":[90,180]},"
+ "\"null-value-counts\":{\"keys\":[3,4],\"values\":[10,20]},"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ private String expectedFileScanTaskJson() {
+ "{\"id\":3,\"name\":\"id\",\"required\":true,\"type\":\"int\"},"
+ "{\"id\":4,\"name\":\"data\",\"required\":true,\"type\":\"string\"}]},"
+ "\"spec\":{\"spec-id\":0,\"fields\":[{\"name\":\"data_bucket\","
+ "\"transform\":\"bucket[16]\",\"source-id\":4,\"field-id\":1000}]},"
+ "\"transform\":\"bucket[16]\",\"source-id\":4,\"field-id\":10000}]},"
+ "\"data-file\":{\"spec-id\":0,\"content\":\"DATA\",\"file-path\":\"/path/to/data-a.parquet\","
+ "\"file-format\":\"PARQUET\",\"partition\":{\"1000\":0},"
+ "\"file-format\":\"PARQUET\",\"partition\":{\"10000\":0},"
+ "\"file-size-in-bytes\":10,\"record-count\":1,\"sort-order-id\":0},"
+ "\"start\":0,\"length\":10,"
+ "\"delete-files\":[{\"spec-id\":0,\"content\":\"POSITION_DELETES\","
+ "\"file-path\":\"/path/to/data-a-deletes.parquet\",\"file-format\":\"PARQUET\","
+ "\"partition\":{\"1000\":0},\"file-size-in-bytes\":10,\"record-count\":1},"
+ "\"partition\":{\"10000\":0},\"file-size-in-bytes\":10,\"record-count\":1},"
+ "{\"spec-id\":0,\"content\":\"EQUALITY_DELETES\",\"file-path\":\"/path/to/data-a2-deletes.parquet\","
+ "\"file-format\":\"PARQUET\",\"partition\":{\"1000\":0},\"file-size-in-bytes\":10,"
+ "\"file-format\":\"PARQUET\",\"partition\":{\"10000\":0},\"file-size-in-bytes\":10,"
+ "\"record-count\":1,\"equality-ids\":[1],\"sort-order-id\":0}],"
+ "\"residual-filter\":{\"type\":\"eq\",\"term\":\"id\",\"value\":1}}";
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/org/apache/iceberg/TestManifestReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testManifestReaderWithPartitionMetadata() throws IOException {
List<Types.NestedField> fields =
((PartitionData) entry.file().partition()).getPartitionType().fields();
assertThat(fields).hasSize(1);
assertThat(fields.get(0).fieldId()).isEqualTo(1000);
assertThat(fields.get(0).fieldId()).isEqualTo(10000);
assertThat(fields.get(0).name()).isEqualTo("data_bucket");
assertThat(fields.get(0).type()).isEqualTo(Types.IntegerType.get());
}
Expand All @@ -108,11 +108,11 @@ public void testManifestReaderWithUpdatedPartitionMetadataForV1Table() throws IO
List<Types.NestedField> fields =
((PartitionData) entry.file().partition()).getPartitionType().fields();
assertThat(fields).hasSize(2);
assertThat(fields.get(0).fieldId()).isEqualTo(1000);
assertThat(fields.get(0).fieldId()).isEqualTo(10000);
assertThat(fields.get(0).name()).isEqualTo("id_bucket");
assertThat(fields.get(0).type()).isEqualTo(Types.IntegerType.get());

assertThat(fields.get(1).fieldId()).isEqualTo(1001);
assertThat(fields.get(1).fieldId()).isEqualTo(10001);
assertThat(fields.get(1).name()).isEqualTo("data_bucket");
assertThat(fields.get(1).type()).isEqualTo(Types.IntegerType.get());
}
Expand Down
20 changes: 10 additions & 10 deletions core/src/test/java/org/apache/iceberg/TestMergeAppend.java
Original file line number Diff line number Diff line change
Expand Up @@ -1277,28 +1277,28 @@ public void testUpdatePartitionSpecFieldIdsForV1Table() {

List<PartitionSpec> partitionSpecs = table.ops().current().specs();
PartitionSpec partitionSpec = partitionSpecs.get(0);
Assert.assertEquals(1000, partitionSpec.lastAssignedFieldId());
Assert.assertEquals(10000, partitionSpec.lastAssignedFieldId());

Types.StructType structType = partitionSpec.partitionType();
List<Types.NestedField> fields = structType.fields();
Assert.assertEquals(1, fields.size());
Assert.assertEquals("data_bucket", fields.get(0).name());
Assert.assertEquals(1000, fields.get(0).fieldId());
Assert.assertEquals(10000, fields.get(0).fieldId());

partitionSpec = partitionSpecs.get(1);
Assert.assertEquals(1003, partitionSpec.lastAssignedFieldId());
Assert.assertEquals(10003, partitionSpec.lastAssignedFieldId());

structType = partitionSpec.partitionType();
fields = structType.fields();
Assert.assertEquals(4, fields.size());
Assert.assertEquals("id_bucket", fields.get(0).name());
Assert.assertEquals(1000, fields.get(0).fieldId());
Assert.assertEquals(10000, fields.get(0).fieldId());
Assert.assertEquals("data", fields.get(1).name());
Assert.assertEquals(1001, fields.get(1).fieldId());
Assert.assertEquals(10001, fields.get(1).fieldId());
Assert.assertEquals("data_bucket", fields.get(2).name());
Assert.assertEquals(1002, fields.get(2).fieldId());
Assert.assertEquals(10002, fields.get(2).fieldId());
Assert.assertEquals("data_partition", fields.get(3).name());
Assert.assertEquals(1003, fields.get(3).fieldId());
Assert.assertEquals(10003, fields.get(3).fieldId());
}

@Test
Expand Down Expand Up @@ -1375,10 +1375,10 @@ public void testManifestEntryFieldIdsForChangedPartitionSpecForV1Table() {
.next();
Types.NestedField field =
((PartitionData) entry.file().partition()).getPartitionType().fields().get(0);
Assert.assertEquals(1000, field.fieldId());
Assert.assertEquals(10000, field.fieldId());
Assert.assertEquals("id_bucket", field.name());
field = ((PartitionData) entry.file().partition()).getPartitionType().fields().get(1);
Assert.assertEquals(1001, field.fieldId());
Assert.assertEquals(10001, field.fieldId());
Assert.assertEquals("data_bucket", field.name());

entry =
Expand All @@ -1387,7 +1387,7 @@ public void testManifestEntryFieldIdsForChangedPartitionSpecForV1Table() {
.iterator()
.next();
field = ((PartitionData) entry.file().partition()).getPartitionType().fields().get(0);
Assert.assertEquals(1000, field.fieldId());
Assert.assertEquals(10000, field.fieldId());
Assert.assertEquals("data_bucket", field.name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public void testPartitionsTableScanNoFilter() {
required(
1,
"partition",
Types.StructType.of(optional(1000, "data_bucket", Types.IntegerType.get()))))
Types.StructType.of(optional(10000, "data_bucket", Types.IntegerType.get()))))
.asStruct();
TableScan scanNoFilter = partitionsTable.newScan().select("partition.data_bucket");
assertThat(scanNoFilter.schema().asStruct()).isEqualTo(expected);
Expand Down Expand Up @@ -573,11 +573,11 @@ public void testFilesTableScanWithDroppedPartition() throws IOException {
Types.StructType actualType = schema.findField(DataFile.PARTITION_ID).type().asStructType();
Types.StructType expectedType =
Types.StructType.of(
Types.NestedField.optional(1000, "data_bucket", Types.IntegerType.get()),
Types.NestedField.optional(1001, "data_bucket_16", Types.IntegerType.get()),
Types.NestedField.optional(1002, "data_trunc_2", Types.StringType.get()));
Types.NestedField.optional(10000, "data_bucket", Types.IntegerType.get()),
Types.NestedField.optional(10001, "data_bucket_16", Types.IntegerType.get()),
Types.NestedField.optional(10002, "data_trunc_2", Types.StringType.get()));
assertThat(actualType).as("Partition type must match").isEqualTo(expectedType);
Accessor<StructLike> accessor = schema.accessorForField(1000);
Accessor<StructLike> accessor = schema.accessorForField(10000);

try (CloseableIterable<FileScanTask> tasks = scan.planFiles()) {
Set<Integer> results =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public void testPartitionsTableScanWithAddPartitionOnNestedField() {
1,
"partition",
Types.StructType.of(
optional(1000, "id", Types.IntegerType.get()),
optional(1001, "nested.id", Types.IntegerType.get()))))
optional(10000, "id", Types.IntegerType.get()),
optional(10001, "nested.id", Types.IntegerType.get()))))
.asStruct();

TableScan scanNoFilter = partitionsTable.newScan().select("partition");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ public void testAddPartitionSpecFromJsonWithFieldId() {
+ "\"name\":\"id_bucket\","
+ "\"transform\":\"bucket[8]\","
+ "\"source-id\":1,"
+ "\"field-id\":1000"
+ "\"field-id\":10000"
+ "},{"
+ "\"name\":\"data_bucket\","
+ "\"transform\":\"bucket[16]\","
+ "\"source-id\":2,"
+ "\"field-id\":1001"
+ "\"field-id\":10001"
+ "}]"
+ "}";

Expand All @@ -209,8 +209,8 @@ public void testAddPartitionSpecFromJsonWithFieldId() {

@Test
public void testAddPartitionSpecFromJsonWithoutFieldId() {
// partition field ids are missing in old PartitionSpec, they always auto-increment from 1000 in
// declared order
// partition field ids are missing in old PartitionSpec, they always auto-increment from 10000
// in declared order
String action = MetadataUpdateParser.ADD_PARTITION_SPEC;
String specString =
"{"
Expand Down Expand Up @@ -252,12 +252,12 @@ public void testAddPartitionSpecToJson() {
+ "\"name\":\"id_bucket\","
+ "\"transform\":\"bucket[8]\","
+ "\"source-id\":1,"
+ "\"field-id\":1000"
+ "\"field-id\":10000"
+ "},{"
+ "\"name\":\"data_bucket\","
+ "\"transform\":\"bucket[16]\","
+ "\"source-id\":2,"
+ "\"field-id\":1001"
+ "\"field-id\":10001"
+ "}]"
+ "}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testToJsonForV1Table() {
+ " \"name\" : \"data_bucket\",\n"
+ " \"transform\" : \"bucket[16]\",\n"
+ " \"source-id\" : 2,\n"
+ " \"field-id\" : 1000\n"
+ " \"field-id\" : 10000\n"
+ " } ]\n"
+ "}";
Assert.assertEquals(expected, PartitionSpecParser.toJson(table.spec(), true));
Expand All @@ -52,12 +52,12 @@ public void testToJsonForV1Table() {
+ " \"name\" : \"id_bucket\",\n"
+ " \"transform\" : \"bucket[8]\",\n"
+ " \"source-id\" : 1,\n"
+ " \"field-id\" : 1000\n"
+ " \"field-id\" : 10000\n"
+ " }, {\n"
+ " \"name\" : \"data_bucket\",\n"
+ " \"transform\" : \"bucket[16]\",\n"
+ " \"source-id\" : 2,\n"
+ " \"field-id\" : 1001\n"
+ " \"field-id\" : 10001\n"
+ " } ]\n"
+ "}";
Assert.assertEquals(expected, PartitionSpecParser.toJson(table.spec(), true));
Expand All @@ -72,21 +72,21 @@ public void testFromJsonWithFieldId() {
+ " \"name\" : \"id_bucket\",\n"
+ " \"transform\" : \"bucket[8]\",\n"
+ " \"source-id\" : 1,\n"
+ " \"field-id\" : 1001\n"
+ " \"field-id\" : 10001\n"
+ " }, {\n"
+ " \"name\" : \"data_bucket\",\n"
+ " \"transform\" : \"bucket[16]\",\n"
+ " \"source-id\" : 2,\n"
+ " \"field-id\" : 1000\n"
+ " \"field-id\" : 10000\n"
+ " } ]\n"
+ "}";

PartitionSpec spec = PartitionSpecParser.fromJson(table.schema(), specString);

Assert.assertEquals(2, spec.fields().size());
// should be the field ids in the JSON
Assert.assertEquals(1001, spec.fields().get(0).fieldId());
Assert.assertEquals(1000, spec.fields().get(1).fieldId());
Assert.assertEquals(10001, spec.fields().get(0).fieldId());
Assert.assertEquals(10000, spec.fields().get(1).fieldId());
}

@Test
Expand All @@ -109,8 +109,8 @@ public void testFromJsonWithoutFieldId() {

Assert.assertEquals(2, spec.fields().size());
// should be the default assignment
Assert.assertEquals(1000, spec.fields().get(0).fieldId());
Assert.assertEquals(1001, spec.fields().get(1).fieldId());
Assert.assertEquals(10000, spec.fields().get(0).fieldId());
Assert.assertEquals(10001, spec.fields().get(1).fieldId());
}

@Test
Expand Down
Loading