rdblue commented on code in PR #12497: URL: https://github.com/apache/iceberg/pull/12497#discussion_r2005968071
########## spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/TestSparkFixupTypes.java: ########## @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.spark; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.iceberg.Schema; +import org.apache.iceberg.types.Types; +import org.junit.jupiter.api.Test; + +public class TestSparkFixupTypes { + + @Test + void fixupShouldCorrectlyFixUUID() { + Schema schema = new Schema(Types.NestedField.required(1, "field", Types.StringType.get())); + Schema referenceSchema = + new Schema(Types.NestedField.required(1, "field", Types.UUIDType.get())); + + Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); + + assertThat(fixedSchema.findType("field")).isSameAs(Types.UUIDType.get()); + } + + @Test + void fixupShouldCorrectlyFixBinary() { + Schema schema = new Schema(Types.NestedField.required(1, "field", Types.BinaryType.get())); + Schema referenceSchema = + new Schema(Types.NestedField.required(1, "field", Types.FixedType.ofLength(16))); + + Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); + + assertThat(fixedSchema.findType("field")).isEqualTo(Types.FixedType.ofLength(16)); + } + + @Test + void fixupShouldCorrectlyFixVariant() { Review Comment: The cases that are fixed up are in `SparkFixupTypes`: ```java @Override protected boolean fixupPrimitive(Type.PrimitiveType type, Type source) { switch (type.typeId()) { case STRING: if (source.typeId() == Type.TypeID.UUID) { return true; } break; case BINARY: if (source.typeId() == Type.TypeID.FIXED) { return true; } break; case TIMESTAMP: if (source.typeId() == Type.TypeID.TIMESTAMP) { return true; } break; default: } return false; } ``` Currently, the behavior is to always use the type from schema and never override with the reference schema's type. The test here validates that the type is _not_ fixed, but what we care about are cases where a type does get fixed. I think the case where a type does get fixed is when we are exposing variant as binary. So I would expect an update to `SparkFixupTypes` and the base `FixupTypes` to override binary with variant when variant is in the reference schema. Otherwise, the variant type is never "fixed" and we don't really need a new test suite. -- 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