Skip to content

Commit 9bf7075

Browse files
authored
Fix issue with complex union avro record (#126)
1 parent fbdb9a7 commit 9bf7075

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

hoptimator-avro/src/main/java/com/linkedin/hoptimator/avro/AvroConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ public static RelDataType rel(Schema schema, RelDataTypeFactory typeFactory, boo
123123
Schema innerType = schema.getTypes().stream().filter(x -> x.getType() != Schema.Type.NULL).findFirst().get();
124124
return typeFactory.createTypeWithNullability(rel(innerType, typeFactory, true), true);
125125
}
126+
// Since we collapse complex unions into separate fields, each of these fields needs to be nullable
127+
// as only one of the group will be present in any given record.
126128
return typeFactory.createTypeWithNullability(typeFactory.createStructType(schema.getTypes().stream()
127129
.filter(x -> x.getType() != Schema.Type.NULL)
128-
.map(x -> new AbstractMap.SimpleEntry<>(x.getName(), rel(x, typeFactory, isNullable)))
130+
.map(x -> new AbstractMap.SimpleEntry<>(x.getName(), rel(x, typeFactory, true)))
129131
.filter(x -> x.getValue().getSqlTypeName() != SqlTypeName.NULL)
130132
.filter(x -> x.getValue().getSqlTypeName() != unknown.getSqlTypeName())
131133
.collect(Collectors.toList())), isNullable);

0 commit comments

Comments
 (0)