Skip to content

Commit

Permalink
with optimization ish
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoramirez committed Oct 8, 2024
1 parent d9dd643 commit b5cde34
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
import com.netflix.hollow.core.write.HollowListWriteRecord;
import com.netflix.hollow.core.write.HollowTypeWriteState;
import com.netflix.hollow.core.write.HollowWriteRecord;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordOrdinalReader;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordWriter;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalListNode;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalNode;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -126,14 +125,15 @@ protected Object parseHollowRecord(HollowRecord record) {
}

@Override
protected Object parseFlatRecord(FlatRecordTraversalNode node) {
List<Object> collection = new ArrayList<>();

for (FlatRecordTraversalNode elementNode : (FlatRecordTraversalListNode) node) {
Object element = elementMapper.parseFlatRecord(elementNode);
protected Object parseFlatRecord(FlatRecordOrdinalReader reader, int ordinal) {
FlatRecordOrdinalReader.Offset offset = reader.getOffsetAtDataStartOf(ordinal);
int size = reader.readSize(offset);
List<Object> collection = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
int elementOrdinal = reader.readListElementOrdinal(offset);
Object element = elementMapper.parseFlatRecord(reader, elementOrdinal);
collection.add(element);
}

return collection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import com.netflix.hollow.core.write.HollowTypeWriteState;
import com.netflix.hollow.core.write.HollowWriteRecord;
import com.netflix.hollow.core.write.HollowWriteStateEngine;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordOrdinalReader;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordWriter;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalMapNode;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalNode;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -140,13 +139,18 @@ protected Object parseHollowRecord(HollowRecord record) {
}

@Override
protected Object parseFlatRecord(FlatRecordTraversalNode node) {
FlatRecordTraversalMapNode mapNode = (FlatRecordTraversalMapNode) node;
Map<Object, Object> collection = new HashMap<>();

for (Map.Entry<FlatRecordTraversalNode, FlatRecordTraversalNode> entry : mapNode.entrySet()) {
Object key = keyMapper.parseFlatRecord(entry.getKey());
Object value = valueMapper.parseFlatRecord(entry.getValue());
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;
for (int i = 0; i < size; i++) {
long keyOrdinalDeltaAndValueOrdinal = reader.readMapKeyOrdinalDeltaAndValueOrdinal(offset);
keyOrdinal += (int) (keyOrdinalDeltaAndValueOrdinal >>> 32);
int valueOrdinal = (int) keyOrdinalDeltaAndValueOrdinal;

Object key = keyMapper.parseFlatRecord(reader, keyOrdinal);
Object value = valueMapper.parseFlatRecord(reader, valueOrdinal);
collection.put(key, value);
}
return collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.netflix.hollow.core.schema.HollowSchema;
import com.netflix.hollow.core.write.HollowWriteStateEngine;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecord;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordOrdinalReader;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordReader;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordWriter;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalNode;
Expand Down Expand Up @@ -100,13 +101,20 @@ public <T> T readFlat(FlatRecordTraversalNode node) {
if (typeMapper == null) {
throw new IllegalArgumentException("No type mapper found for schema " + schemaName);
}
Object obj = typeMapper.parseFlatRecord(node);
Object obj = typeMapper.parseFlatRecord(node.getReader(), node.getOrdinal());
return (T) obj;
}

public <T> T readFlat(FlatRecord record) {
FlatRecordTraversalNode node = new FlatRecordTraversalObjectNode(record);
return readFlat(node);
FlatRecordOrdinalReader reader = new FlatRecordOrdinalReader(record);
int ordinal = reader.getOrdinalCount() - 1;
HollowSchema schema = reader.readSchema(ordinal);
HollowTypeMapper typeMapper = typeMappers.get(schema.getName());
if (typeMapper == null) {
throw new IllegalArgumentException("No type mapper found for schema " + schema.getName());
}
Object obj = typeMapper.parseFlatRecord(reader, ordinal);
return (T) obj;
}

/**
Expand Down
Loading

0 comments on commit b5cde34

Please sign in to comment.