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

Support byte[] in @HollowPrimaryKey for ObjectInternPool in HollowHistoryUI #664

Merged
merged 1 commit into from
Mar 12, 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 @@ -43,7 +43,7 @@
*
*/
public class HollowDiff {
private final EnumSet<FieldType> SINGLE_FIELD_SUPPORTED_TYPES = EnumSet.of(FieldType.INT, FieldType.LONG, FieldType.DOUBLE, FieldType.STRING, FieldType.FLOAT, FieldType.BOOLEAN);
private final EnumSet<FieldType> SINGLE_FIELD_SUPPORTED_TYPES = EnumSet.of(FieldType.INT, FieldType.LONG, FieldType.DOUBLE, FieldType.STRING, FieldType.FLOAT, FieldType.BOOLEAN, FieldType.BYTES);

private final Logger log = Logger.getLogger(HollowDiff.class.getName());
private final HollowReadStateEngine fromStateEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public Object getObject(int ordinal, FieldType type) {
return getLong(pointer);
case STRING:
return getString(pointer);
case BYTES:
return getBytes(pointer);
default:
throw new IllegalArgumentException("Unknown type " + type);
}
Expand Down Expand Up @@ -82,13 +84,17 @@ public long getLong(long pointer) {
}

public String getString(long pointer) {
return new String(getBytes(pointer));
}

public byte[] getBytes(long pointer) {
ByteData byteData = ordinalMap.getByteData().getUnderlyingArray();
int length = VarInt.readVInt(byteData, pointer);
byte[] bytes = new byte[length];
for(int i=0;i<length;i++) {
bytes[i] = byteData.get(pointer+1+i);
}
return new String(bytes);
return bytes;
}

public int writeAndGetOrdinal(Object objectToIntern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public static Object[] parseKey(HollowReadStateEngine readStateEngine, PrimaryKe
key[i] = Float.parseFloat(fields[i]);
break;
case BYTES:
throw new IllegalArgumentException("Primary key contains a field of type BYTES");
key[i] = fields[i];
break;
}
}
return key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.netflix.hollow.tools.util;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import com.netflix.hollow.core.schema.HollowObjectSchema.FieldType;

Expand Down Expand Up @@ -162,6 +163,32 @@ public void testString() {
assertEquals(retrievedString2, "I can do this all day");
}

@Test
public void testBytes() {
byte[] bytesObj1 = "I am Groot".getBytes();
byte[] bytesObj2 = "I am Groot".getBytes();
byte[] bytesObj3 = "I can do this all day".getBytes();
byte[] bytesObj4 = "I can do this all day".getBytes();

int bytes1Ordinal = internPool.writeAndGetOrdinal(bytesObj1);
int bytes2Ordinal = internPool.writeAndGetOrdinal(bytesObj2);
internPool.prepareForRead();

byte[] retrievedString1 = (byte[]) internPool.getObject(bytes1Ordinal, FieldType.BYTES);

assertEquals(bytes1Ordinal, bytes2Ordinal);
assertArrayEquals(retrievedString1, "I am Groot".getBytes());

int bytes3Ordinal = internPool.writeAndGetOrdinal(bytesObj3);
int bytes4Ordinal = internPool.writeAndGetOrdinal(bytesObj4);
internPool.prepareForRead();

byte[] retrievedBytes2 = (byte[]) internPool.getObject(bytes3Ordinal, FieldType.BYTES);

assertEquals(bytes3Ordinal, bytes4Ordinal);
assertArrayEquals(retrievedBytes2, "I can do this all day".getBytes());
}

@Test
public void testBool() {
Boolean boolObj1 = true;
Expand Down