Skip to content
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

Add single union schema conversion logic for hive to iceberg #152

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading