Skip to content

Commit

Permalink
Add single union schema conversion logic for hive to iceberg (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhang10 authored Jan 10, 2024
1 parent 59b5423 commit 16e05f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public Type list(ListTypeInfo list, Type elementResult) {
// Mimic the struct call behavior to construct a union converted struct type
@Override
public Type union(UnionTypeInfo union, List<Type> unionResults) {
// if the union is single-typed, return the type directly
if (union.getAllUnionObjectTypeInfos().size() == 1) {
return unionResults.get(0);
}
// else, it's a complex union
List<Types.NestedField> fields = Lists.newArrayListWithExpectedSize(unionResults.size() + 1);
fields.add(Types.NestedField.required(allocateId(), "tag", Types.IntegerType.get()));
for (int i = 0; i < unionResults.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public void testConversions() {
"length:int,count:int,list:array<struct<lastword:string,lastwordlength:int>>," +
"wordcounts:map<string,int>>");
check("struct<1: tag: required int, 2: field0: optional int, 3: field1: optional string>", "uniontype<int,string>");
// single type union
check("int", "uniontype<int>");
}

private static void check(String icebergTypeStr, String hiveTypeStr) {
Expand Down

0 comments on commit 16e05f7

Please sign in to comment.