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

Fix row/map block builder for hive thrift reader #119

Merged
Merged
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 @@ -603,13 +603,12 @@ private static Block serializeMap(Type type, ThriftFieldIdResolver resolver, Blo
Type valueType = typeParameters.get(1);
ThriftFieldIdResolver keyResolver = resolver.getNestedResolver(0);
ThriftFieldIdResolver valueResolver = resolver.getNestedResolver(1);
BlockBuilder currentBuilder;
if (builder != null) {
currentBuilder = builder.beginBlockEntry();
}
else {
currentBuilder = type.createBlockBuilder(new BlockBuilderStatus(), map.size());
boolean builderSynthesized = false;
if (builder == null) {
builderSynthesized = true;
builder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
}
BlockBuilder currentBuilder = builder.beginBlockEntry();

for (Map.Entry<?, ?> entry : map.entrySet()) {
// Hive skips map entries with null keys
Expand All @@ -619,27 +618,26 @@ private static Block serializeMap(Type type, ThriftFieldIdResolver resolver, Blo
}
}

if (builder != null) {
builder.closeEntry();
return null;
builder.closeEntry();
if (builderSynthesized) {
return (Block) type.getObject(builder, 0);
}
else {
Block resultBlock = currentBuilder.build();
return resultBlock;
return null;
}
}

private static Block serializeStruct(Type type, ThriftFieldIdResolver resolver, BlockBuilder builder, Object object, DateTimeZone hiveStorageTimeZone)
{
ThriftGenericRow structData = (ThriftGenericRow) requireNonNull(object, "object is null");
List<Type> typeParameters = type.getTypeParameters();
BlockBuilder currentBuilder;
if (builder != null) {
currentBuilder = builder.beginBlockEntry();
}
else {
currentBuilder = type.createBlockBuilder(new BlockBuilderStatus(), typeParameters.size());

boolean builderSynthesized = false;
if (builder == null) {
builderSynthesized = true;
builder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
}
BlockBuilder currentBuilder = builder.beginBlockEntry();

for (int i = 0; i < typeParameters.size(); i++) {
Object fieldValue = structData.getFieldValueForThriftId(resolver.getThriftId(i));
Expand All @@ -651,13 +649,12 @@ private static Block serializeStruct(Type type, ThriftFieldIdResolver resolver,
}
}

if (builder != null) {
builder.closeEntry();
return null;
builder.closeEntry();
if (builderSynthesized) {
return (Block) type.getObject(builder, 0);
}
else {
Block resultBlock = currentBuilder.build();
return resultBlock;
return null;
}
}

Expand Down