Skip to content
Merged
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
26 changes: 13 additions & 13 deletions api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ private static Stream<Arguments> testTypes() {
@MethodSource("testTypes")
public void testAssignIdsWithType(Type testType) {
Types.StructType sourceType =
Types.StructType.of(required(0, "id", IntegerType.get()), required(1, "data", testType));
Types.StructType.of(required(0, "id", IntegerType.get()), optional(1, "data", testType));
Type expectedType =
Types.StructType.of(required(10, "id", IntegerType.get()), required(11, "data", testType));
Types.StructType.of(required(10, "id", IntegerType.get()), optional(11, "data", testType));

Type assignedType = TypeUtil.assignIds(sourceType, oldId -> oldId + 10);
assertThat(assignedType).isEqualTo(expectedType);
Expand All @@ -676,20 +676,20 @@ public void testAssignIdsWithType(Type testType) {
@ParameterizedTest
@MethodSource("testTypes")
public void testAssignFreshIdsWithType(Type testType) {
Schema schema = new Schema(required(0, "id", IntegerType.get()), required(1, "data", testType));
Schema schema = new Schema(required(0, "id", IntegerType.get()), optional(1, "data", testType));

Schema assignedSchema = TypeUtil.assignFreshIds(schema, new AtomicInteger(10)::incrementAndGet);
Schema expectedSchema =
new Schema(required(11, "id", IntegerType.get()), required(12, "data", testType));
new Schema(required(11, "id", IntegerType.get()), optional(12, "data", testType));
assertThat(assignedSchema.asStruct()).isEqualTo(expectedSchema.asStruct());
}

@ParameterizedTest
@MethodSource("testTypes")
public void testReassignIdsWithType(Type testType) {
Schema schema = new Schema(required(0, "id", IntegerType.get()), required(1, "data", testType));
Schema schema = new Schema(required(0, "id", IntegerType.get()), optional(1, "data", testType));
Schema sourceSchema =
new Schema(required(1, "id", IntegerType.get()), required(2, "data", testType));
new Schema(required(1, "id", IntegerType.get()), optional(2, "data", testType));

Schema reassignedSchema = TypeUtil.reassignIds(schema, sourceSchema);
assertThat(reassignedSchema.asStruct()).isEqualTo(sourceSchema.asStruct());
Expand All @@ -698,7 +698,7 @@ public void testReassignIdsWithType(Type testType) {
@ParameterizedTest
@MethodSource("testTypes")
public void testIndexByIdWithType(Type testType) {
Schema schema = new Schema(required(0, "id", IntegerType.get()), required(1, "data", testType));
Schema schema = new Schema(required(0, "id", IntegerType.get()), optional(1, "data", testType));

Map<Integer, Types.NestedField> indexByIds = TypeUtil.indexById(schema.asStruct());
assertThat(indexByIds.get(1).type()).isEqualTo(testType);
Expand All @@ -707,7 +707,7 @@ public void testIndexByIdWithType(Type testType) {
@ParameterizedTest
@MethodSource("testTypes")
public void testIndexNameByIdWithType(Type testType) {
Schema schema = new Schema(required(0, "id", IntegerType.get()), required(1, "data", testType));
Schema schema = new Schema(required(0, "id", IntegerType.get()), optional(1, "data", testType));

Map<Integer, String> indexNameByIds = TypeUtil.indexNameById(schema.asStruct());
assertThat(indexNameByIds.get(1)).isEqualTo("data");
Expand All @@ -716,17 +716,17 @@ public void testIndexNameByIdWithType(Type testType) {
@ParameterizedTest
@MethodSource("testTypes")
public void testProjectWithType(Type testType) {
Schema schema = new Schema(required(0, "id", IntegerType.get()), required(1, "data", testType));
Schema schema = new Schema(required(0, "id", IntegerType.get()), optional(1, "data", testType));

Schema expectedSchema = new Schema(required(1, "data", testType));
Schema expectedSchema = new Schema(optional(1, "data", testType));
Schema projectedSchema = TypeUtil.project(schema, Sets.newHashSet(1));
assertThat(projectedSchema.asStruct()).isEqualTo(expectedSchema.asStruct());
}

@ParameterizedTest
@MethodSource("testTypes")
public void testGetProjectedIdsWithType(Type testType) {
Schema schema = new Schema(required(0, "id", IntegerType.get()), required(1, "data", testType));
Schema schema = new Schema(required(0, "id", IntegerType.get()), optional(1, "data", testType));

Set<Integer> projectedIds = TypeUtil.getProjectedIds(schema);
assertThat(Set.of(0, 1)).isEqualTo(projectedIds);
Expand All @@ -735,10 +735,10 @@ public void testGetProjectedIdsWithType(Type testType) {
@ParameterizedTest
@MethodSource("testTypes")
public void testReassignDocWithType(Type testType) {
Schema schema = new Schema(required(0, "id", IntegerType.get()), required(1, "data", testType));
Schema schema = new Schema(required(0, "id", IntegerType.get()), optional(1, "data", testType));
Schema docSourceSchema =
new Schema(
required(0, "id", IntegerType.get(), "id"), required(1, "data", testType, "data"));
required(0, "id", IntegerType.get(), "id"), optional(1, "data", testType, "data"));

Schema reassignedSchema = TypeUtil.reassignDoc(schema, docSourceSchema);
assertThat(reassignedSchema.asStruct()).isEqualTo(docSourceSchema.asStruct());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public void testAddTopLevelListOfPrimitives() {
@Test
public void testAddTopLevelMapOfPrimitives() {
for (Type primitiveType : primitiveTypes()) {
if (primitiveType.equals(UnknownType.get())) {
// The UnknownType has to be optional, and this conflicts with the map key that must be
// required
continue;
}

Schema newSchema =
new Schema(
optional(1, "aMap", Types.MapType.ofOptional(2, 3, primitiveType, primitiveType)));
Expand Down