Skip to content

Commit 5e429bd

Browse files
make getNonNullType more developer friendly
1 parent 13c3728 commit 5e429bd

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchema.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,14 @@ public boolean isNullable() {
723723
}
724724

725725
/**
726-
* If this is a union schema, returns the non-null type.
726+
* If this is a union schema, returns the non-null type. Otherwise, returns this schema.
727727
*
728-
* @return the non-null schema from a union
729-
* @throws IllegalStateException if this is not a nullable union
728+
* @return the non-null schema from a union or the current schema
729+
* @throws IllegalStateException if the union has more than two types
730730
*/
731731
public HoodieSchema getNonNullType() {
732732
if (type != HoodieSchemaType.UNION) {
733-
throw new IllegalStateException("Cannot get non-null type from non-union schema: " + type);
733+
return this;
734734
}
735735

736736
List<HoodieSchema> types = getTypes();

hudi-common/src/test/java/org/apache/hudi/common/schema/TestHoodieSchema.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ public void testUnionSchemaTypeAccess() {
317317
stringSchema.getTypes();
318318
}, "Should throw exception when getting types from non-union schema");
319319

320-
assertThrows(IllegalStateException.class, () -> {
321-
stringSchema.getNonNullType();
322-
}, "Should throw exception when getting non-null type from non-union schema");
320+
assertSame(stringSchema, stringSchema.getNonNullType());
323321
}
324322

325323
@Test

0 commit comments

Comments
 (0)