-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Spark: Add some tests for variant fixup #12497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
a43bf5c
23f7291
f036b59
74c5118
c64903c
01c58d0
347be8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this behavior is correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please further explain this? Do you mean that we need to restrict There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cases that are fixed up are in @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 |
||
Schema schema = new Schema(Types.NestedField.required(1, "field", Types.VariantType.get())); | ||
Schema referenceSchema = | ||
new Schema(Types.NestedField.required(1, "field", Types.StringType.get())); | ||
|
||
Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); | ||
|
||
assertThat(fixedSchema.findType("field")).isSameAs(Types.VariantType.get()); | ||
} | ||
|
||
@Test | ||
void fixupShouldCorrectlyFixTimestamp() { | ||
Schema schema = | ||
new Schema(Types.NestedField.required(1, "field", Types.TimestampType.withZone())); | ||
Schema referenceSchema = | ||
new Schema(Types.NestedField.required(1, "field", Types.TimestampType.withoutZone())); | ||
|
||
Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); | ||
|
||
assertThat(fixedSchema.findType("field")).isSameAs(Types.TimestampType.withoutZone()); | ||
} | ||
|
||
@Test | ||
void fixupShouldHandleNestedStructs() { | ||
Schema schema = | ||
new Schema( | ||
Types.NestedField.required( | ||
1, | ||
"struct", | ||
Types.StructType.of( | ||
Types.NestedField.required(2, "field", Types.StringType.get())))); | ||
Schema referenceSchema = | ||
new Schema( | ||
Types.NestedField.required( | ||
1, | ||
"struct", | ||
Types.StructType.of(Types.NestedField.required(2, "field", Types.UUIDType.get())))); | ||
|
||
Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); | ||
|
||
assertThat(fixedSchema.findType("struct")) | ||
.isEqualTo( | ||
Types.StructType.of(Types.NestedField.required(2, "field", Types.UUIDType.get()))); | ||
} | ||
|
||
@Test | ||
void fixupShouldHandleLists() { | ||
Schema schema = | ||
new Schema( | ||
Types.NestedField.required( | ||
1, "list", Types.ListType.ofRequired(2, Types.StringType.get()))); | ||
Schema referenceSchema = | ||
new Schema( | ||
Types.NestedField.required( | ||
1, "list", Types.ListType.ofRequired(2, Types.UUIDType.get()))); | ||
|
||
Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); | ||
|
||
assertThat(fixedSchema.findType("list")) | ||
.isEqualTo(Types.ListType.ofRequired(2, Types.UUIDType.get())); | ||
} | ||
|
||
@Test | ||
void fixupShouldHandleMaps() { | ||
Schema schema = | ||
new Schema( | ||
Types.NestedField.required( | ||
1, | ||
"map", | ||
Types.MapType.ofRequired(2, 3, Types.StringType.get(), Types.StringType.get()))); | ||
Schema referenceSchema = | ||
new Schema( | ||
Types.NestedField.required( | ||
1, | ||
"map", | ||
Types.MapType.ofRequired(2, 3, Types.UUIDType.get(), Types.UUIDType.get()))); | ||
|
||
Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); | ||
|
||
assertThat(fixedSchema.findType("map")) | ||
.isEqualTo(Types.MapType.ofRequired(2, 3, Types.UUIDType.get(), Types.UUIDType.get())); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.