-
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a43bf5c
Spark: Add some tests for variant fixup
xxubai 23f7291
Implement variant in PruneColumnsWithoutReordering and add UnknownTyp…
xxubai f036b59
Add variant method in Spark3.4 PruneColumnsWithoutReordering
xxubai 74c5118
Add support for VariantType in SparkFixupTypes tests
xxubai c64903c
Refactor RandomData and TestSparkFixupTypes: remove unused variant me…
xxubai 01c58d0
Remove variant in spark3.4
xxubai 347be8b
Fixup to VARIANT type in BINARY checks
xxubai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
spark/v3.4/spark/src/test/java/org/apache/iceberg/spark/TestSparkFixupTypes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* 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 java.util.stream.Stream; | ||
import org.apache.iceberg.Schema; | ||
import org.apache.iceberg.types.Type; | ||
import org.apache.iceberg.types.Types; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class TestSparkFixupTypes { | ||
|
||
private static Stream<Arguments> primitiveTypes() { | ||
return Stream.of( | ||
Arguments.of(Types.UnknownType.get()), | ||
Arguments.of(Types.BooleanType.get()), | ||
Arguments.of(Types.IntegerType.get()), | ||
Arguments.of(Types.LongType.get()), | ||
Arguments.of(Types.FloatType.get()), | ||
Arguments.of(Types.DoubleType.get()), | ||
Arguments.of(Types.DateType.get()), | ||
Arguments.of(Types.TimeType.get()), | ||
Arguments.of(Types.TimestampType.withoutZone()), | ||
Arguments.of(Types.TimestampType.withZone()), | ||
Arguments.of(Types.TimestampNanoType.withoutZone()), | ||
Arguments.of(Types.TimestampNanoType.withZone()), | ||
Arguments.of(Types.StringType.get()), | ||
Arguments.of(Types.UUIDType.get()), | ||
Arguments.of(Types.FixedType.ofLength(3)), | ||
Arguments.of(Types.FixedType.ofLength(4)), | ||
Arguments.of(Types.BinaryType.get()), | ||
Arguments.of(Types.DecimalType.of(9, 2)), | ||
Arguments.of(Types.DecimalType.of(11, 2)), | ||
Arguments.of(Types.DecimalType.of(9, 3)), | ||
Arguments.of(Types.VariantType.get())); | ||
xxubai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@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)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("primitiveTypes") | ||
void fixupShouldNotChangeNonMatchingPrimitiveTypes(Type type) { | ||
Schema schema = new Schema(Types.NestedField.optional(1, "field", type)); | ||
Schema referenceSchema = | ||
new Schema(Types.NestedField.optional(1, "field", Types.IntegerType.get())); | ||
|
||
Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); | ||
|
||
assertThat(fixedSchema.findType("field")).isSameAs(type); | ||
xxubai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@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())); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/TestSparkFixupTypes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* 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 java.util.stream.Stream; | ||
import org.apache.iceberg.Schema; | ||
import org.apache.iceberg.types.Type; | ||
import org.apache.iceberg.types.Types; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class TestSparkFixupTypes { | ||
|
||
private static Stream<Arguments> primitiveTypes() { | ||
return Stream.of( | ||
Arguments.of(Types.UnknownType.get()), | ||
Arguments.of(Types.BooleanType.get()), | ||
xxubai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Arguments.of(Types.IntegerType.get()), | ||
Arguments.of(Types.LongType.get()), | ||
Arguments.of(Types.FloatType.get()), | ||
Arguments.of(Types.DoubleType.get()), | ||
Arguments.of(Types.DateType.get()), | ||
Arguments.of(Types.TimeType.get()), | ||
Arguments.of(Types.TimestampType.withoutZone()), | ||
Arguments.of(Types.TimestampType.withZone()), | ||
Arguments.of(Types.TimestampNanoType.withoutZone()), | ||
Arguments.of(Types.TimestampNanoType.withZone()), | ||
Arguments.of(Types.StringType.get()), | ||
Arguments.of(Types.UUIDType.get()), | ||
Arguments.of(Types.FixedType.ofLength(3)), | ||
Arguments.of(Types.FixedType.ofLength(4)), | ||
Arguments.of(Types.BinaryType.get()), | ||
Arguments.of(Types.DecimalType.of(9, 2)), | ||
Arguments.of(Types.DecimalType.of(11, 2)), | ||
Arguments.of(Types.DecimalType.of(9, 3)), | ||
Arguments.of(Types.VariantType.get())); | ||
} | ||
|
||
@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)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("primitiveTypes") | ||
void fixupShouldNotChangeNonMatchingPrimitiveTypes(Type type) { | ||
Schema schema = new Schema(Types.NestedField.optional(1, "field", type)); | ||
Schema referenceSchema = | ||
new Schema(Types.NestedField.optional(1, "field", Types.IntegerType.get())); | ||
|
||
Schema fixedSchema = SparkFixupTypes.fixup(schema, referenceSchema); | ||
|
||
assertThat(fixedSchema.findType("field")).isSameAs(type); | ||
} | ||
|
||
@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())); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.