Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoramirez committed Oct 25, 2024
1 parent 13bf442 commit 6f8c350
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ protected Object parseFlatRecord(FlatRecordOrdinalReader reader, int ordinal) {
FlatRecordOrdinalReader.Offset offset = reader.getOffsetAtDataStartOf(ordinal);
int size = reader.readSize(offset);
Map<Object, Object> collection = new HashMap<>(size);
int keyOrdinal = 0;
int previousKeyOrdinal = 0;
for (int i = 0; i < size; i++) {
long keyOrdinalDeltaAndValueOrdinal = reader.readMapKeyOrdinalDeltaAndValueOrdinal(offset);
keyOrdinal += (int) (keyOrdinalDeltaAndValueOrdinal >>> 32);
int valueOrdinal = (int) keyOrdinalDeltaAndValueOrdinal;
long keyAndValueOrdinals = reader.readMapKeyAndValueOrdinals(offset, previousKeyOrdinal);
previousKeyOrdinal = (int) (keyAndValueOrdinals >>> 32);
int valueOrdinal = (int) keyAndValueOrdinals;

Object key = keyMapper.parseFlatRecord(reader, keyOrdinal);
Object key = keyMapper.parseFlatRecord(reader, previousKeyOrdinal);
Object value = valueMapper.parseFlatRecord(reader, valueOrdinal);
collection.put(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected Object parseFlatRecord(FlatRecordOrdinalReader reader, int ordinal) {
if (posInPojoSchema != -1) {
obj = mappedFields.get(posInPojoSchema).parseBoxedWrapper(reader, offset);
} else {
reader.skipField(offset, schema.getFieldType(i));
reader.skipField(offset, flatRecordSchema.getFieldType(i));
}
}
} else if (clazz.isEnum()) {
Expand All @@ -270,7 +270,7 @@ protected Object parseFlatRecord(FlatRecordOrdinalReader reader, int ordinal) {
if (fieldName.equals(MappedFieldType.ENUM_NAME.getSpecialFieldName()) && posInPojoSchema != -1) {
obj = mappedFields.get(posInPojoSchema).parseBoxedWrapper(reader, offset);
} else {
reader.skipField(offset, schema.getFieldType(i));
reader.skipField(offset, flatRecordSchema.getFieldType(i));
}
}
} else {
Expand All @@ -280,7 +280,7 @@ protected Object parseFlatRecord(FlatRecordOrdinalReader reader, int ordinal) {
if (posInPojoSchema != -1) {
mappedFields.get(posInPojoSchema).copy(obj, reader, offset);
} else {
reader.skipField(offset, schema.getFieldType(i));
reader.skipField(offset, flatRecordSchema.getFieldType(i));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ protected Object parseFlatRecord(FlatRecordOrdinalReader reader, int ordinal) {
FlatRecordOrdinalReader.Offset offset = reader.getOffsetAtDataStartOf(ordinal);
int size = reader.readSize(offset);
Set<Object> collection = new HashSet<>();
int elementOrdinal = 0;
int previousElementOrdinal = 0;
for (int i = 0; i < size; i++) {
elementOrdinal += reader.readSetElementOrdinalDelta(offset);
collection.add(elementMapper.parseFlatRecord(reader, elementOrdinal));
previousElementOrdinal = reader.readSetElementOrdinal(offset, previousElementOrdinal);
collection.add(elementMapper.parseFlatRecord(reader, previousElementOrdinal));
}
return collection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ public int readSize(int ordinal) {
}

public int readSize(Offset offset) {
int schemaId = VarInt.readVInt(record.data, offset.get());
offset.increment(VarInt.sizeOfVInt(schemaId));

HollowSchema schema = record.schemaIdMapper.getSchema(schemaId);
if (schema.getSchemaType() != HollowSchema.SchemaType.LIST &&
schema.getSchemaType() != HollowSchema.SchemaType.SET &&
schema.getSchemaType() != HollowSchema.SchemaType.MAP) {
throw new IllegalArgumentException(String.format("Schema %s is not a LIST, SET, or MAP type (found %s)", schema.getName(), schema.getSchemaType()));
}

int size = VarInt.readVInt(record.data, offset.get());
offset.increment(VarInt.sizeOfVInt(size));
return size;
Expand All @@ -91,18 +81,18 @@ public int readListElementOrdinal(Offset offset) {
return elementOrdinal;
}

public int readSetElementOrdinalDelta(Offset offset) {
public int readSetElementOrdinal(Offset offset, int previousElementOrdinal) {
int elementOrdinalDelta = VarInt.readVInt(record.data, offset.get());
offset.increment(VarInt.sizeOfVInt(elementOrdinalDelta));
return elementOrdinalDelta;
return previousElementOrdinal + elementOrdinalDelta;
}

public long readMapKeyOrdinalDeltaAndValueOrdinal(Offset offset) {
public long readMapKeyAndValueOrdinals(Offset offset, int previousKeyOrdinal) {
int keyOrdinalDelta = VarInt.readVInt(record.data, offset.get());
offset.increment(VarInt.sizeOfVInt(keyOrdinalDelta));
int valueOrdinal = VarInt.readVInt(record.data, offset.get());
offset.increment(VarInt.sizeOfVInt(valueOrdinal));
return (long) keyOrdinalDelta << 32 | valueOrdinal;
return (long) (previousKeyOrdinal + keyOrdinalDelta) << 32 | valueOrdinal;
}

public void readListElementsInto(int ordinal, int[] elements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public class HollowObjectMapperFlatRecordTraversalNodeParserTest {
private HollowObjectMapper mapper;
private FlatRecordWriter flatRecordWriter;
Expand Down

0 comments on commit 6f8c350

Please sign in to comment.