@Override public HollowRecord instantiateElement(int elementOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getElementType(), elementOrdinal); }
@Override public boolean equalsElement(int elementOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getElementType(), elementOrdinal, testObject); }
@Override public HollowRecord instantiateKey(int keyOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getKeyType(), keyOrdinal); }
@Override public boolean equalsElement(int elementOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getElementType(), elementOrdinal, testObject); }
@Override public HollowRecord instantiateValue(int valueOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getValueType(), valueOrdinal); }
@Override public boolean equalsKey(int keyOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getKeyType(), keyOrdinal, testObject); }
@Override public HollowRecord instantiateElement(int elementOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getElementType(), elementOrdinal); }
@Override public boolean equalsValue(int valueOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getValueType(), valueOrdinal, testObject); }
private HollowObject retrieveAddedRecord(HollowHistory history, long version, String type, int key) { HollowHistoricalState historicalState = history.getHistoricalState(version); Map<String, HollowHistoryTypeKeyIndex> typeKeyIndexes = history.getKeyIndex().getTypeKeyIndexes(); IntList queryResult = typeKeyIndexes.get(type).queryIndexedFields(String.valueOf(key)); int keyOrdinal = queryResult.get(0); int addedOrdinal = historicalState.getKeyOrdinalMapping().getTypeMapping(type).findAddedOrdinal(keyOrdinal); return (HollowObject) GenericHollowRecordHelper.instantiate(historicalState.getDataAccess(), type, addedOrdinal); }
private HollowObject retrieveRemovedRecord(HollowHistory history, long version, String type, int key) { HollowHistoricalState historicalState = history.getHistoricalState(version); IntList queryResult = history.getKeyIndex().getTypeKeyIndexes().get(type).queryIndexedFields(String.valueOf(key)); int keyOrdinal = queryResult.get(0); int removedOrdinal = historicalState.getKeyOrdinalMapping().getTypeMapping(type).findRemovedOrdinal(keyOrdinal); return (HollowObject) GenericHollowRecordHelper.instantiate(historicalState.getDataAccess(), type, removedOrdinal); }
public final HollowRecord getReferencedGenericRecord(String fieldName) { String referencedType = getSchema().getReferencedType(fieldName); if(referencedType == null) { try { HollowObjectSchema hollowObjectSchema = (HollowObjectSchema)getTypeDataAccess().getDataAccess().getMissingDataHandler().handleSchema(getSchema().getName()); referencedType = hollowObjectSchema.getReferencedType(fieldName); if(referencedType == null) return null; } catch(Exception e) { return null; } } int ordinal = getOrdinal(fieldName); if(ordinal == -1) return null; return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), referencedType, ordinal); }
@Test public void testCompletelyMissingMap() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowMap map = (GenericHollowMap) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingMap", 0); Assert.assertEquals(2, map.size()); Assert.assertTrue(map.containsKey(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertEquals(300, map.get(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 3)).getOrdinal()); Assert.assertFalse(map.containsKey(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Assert.assertNull(map.get(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 4))); Iterator<Map.Entry<HollowRecord, HollowRecord>> rec = map.entrySet().iterator(); Assert.assertTrue(rec.hasNext()); Map.Entry<HollowRecord, HollowRecord> next = rec.next(); Assert.assertEquals(2, next.getKey().getOrdinal()); Assert.assertEquals("MissingObject", next.getKey().getSchema().getName()); Assert.assertEquals(200, next.getValue().getOrdinal()); Assert.assertEquals("MissingObject", next.getValue().getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getKey().getOrdinal()); Assert.assertEquals("MissingObject", next.getKey().getSchema().getName()); Assert.assertEquals(300, next.getValue().getOrdinal()); Assert.assertEquals("MissingObject", next.getValue().getSchema().getName()); Assert.assertEquals(300, map.get(next.getKey()).getOrdinal()); Assert.assertEquals("MissingObject", map.get(next.getKey()).getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
private void assertA(HollowReadStateEngine stateEngine, int id, String val, boolean verifyEchoes) { HollowPrimaryKeyIndex idx = new HollowPrimaryKeyIndex(stateEngine, "TypeA", "id"); int ordinal = idx.getMatchingOrdinal(id); GenericHollowObject a = (GenericHollowObject) GenericHollowRecordHelper.instantiate(stateEngine, "TypeA", ordinal); GenericHollowList bList = (GenericHollowList)a.getReferencedGenericRecord("b"); GenericHollowObject b = (GenericHollowObject)bList.get(0); GenericHollowObject str = (GenericHollowObject)b.getReferencedGenericRecord("val"); Assert.assertEquals(val, str.getString("value")); if(verifyEchoes) { Assert.assertEquals(id, a.getInt("idEcho")); Assert.assertEquals(id, b.getInt("idEcho")); } }
@Test public void testCompletelyMissingList() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowList list = (GenericHollowList) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingList", 0); Assert.assertEquals(2, list.size()); Assert.assertTrue(list.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertFalse(list.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Iterator<HollowRecord> rec = list.iterator(); Assert.assertTrue(rec.hasNext()); HollowRecord next = rec.next(); Assert.assertEquals(2, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
@Test public void testCompletelyMissingSet() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowSet set = (GenericHollowSet) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingSet", 0); Assert.assertEquals(2, set.size()); Assert.assertTrue(set.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertFalse(set.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Iterator<HollowRecord> rec = set.iterator(); Assert.assertTrue(rec.hasNext()); HollowRecord next = rec.next(); Assert.assertEquals(2, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
private void assertObject(HollowReadStateEngine output, int aKey, int expectAOrigin, int expectBKey, int expectBOrigin, int expectCKey, int expectCOrigin) { HollowPrimaryKeyIndex idx = new HollowPrimaryKeyIndex(output, new PrimaryKey("TypeA", "key")); GenericHollowObject typeA = (GenericHollowObject)GenericHollowRecordHelper.instantiate(output, "TypeA", idx.getMatchingOrdinal(aKey)); Assert.assertEquals(aKey, typeA.getInt("key")); Assert.assertEquals(expectAOrigin, typeA.getInt("origin")); GenericHollowObject typeB = (GenericHollowObject)typeA.getReferencedGenericRecord("b"); Assert.assertEquals(expectBKey, typeB.getInt("key")); Assert.assertEquals(expectBOrigin, typeB.getInt("origin")); GenericHollowObject typeC = (GenericHollowObject)typeB.getReferencedGenericRecord("c"); Assert.assertEquals(expectCKey, typeC.getInt("key")); Assert.assertEquals(expectCOrigin, typeC.getInt("origin")); }
@Test public void testDefaultMissingObjectValue() throws IOException { addRecord(1, "one"); addRecord(2, "two"); addRecord(3, "three"); roundTripSnapshot(); GenericHollowObject obj = (GenericHollowObject) GenericHollowRecordHelper.instantiate(readStateEngine, "TestObject", 1); assertEquals(2, obj.getInt("f1")); assertEquals("two", obj.getString("f2")); assertEquals(Long.MIN_VALUE, obj.getLong("f3")); assertEquals(Integer.MIN_VALUE, obj.getInt("f4")); assertTrue(Float.isNaN(obj.getFloat("f5"))); assertTrue(Double.isNaN(obj.getDouble("f6"))); assertEquals(null, obj.getString("f7")); assertFalse(obj.isStringFieldEqual("f7", "not-null")); assertTrue(obj.isStringFieldEqual("f7", null)); assertEquals(null, obj.getBytes("f8")); assertTrue(obj.isNull("f9")); assertFalse(obj.getBoolean("f10")); }