@Override protected String getTypeName() { return schema.getName(); }
private void appendTypeAPIAccessor(StringBuilder classBuilder) { String typeAPIClassname = typeAPIClassname(schema.getName()); classBuilder.append(" public " + typeAPIClassname + " typeApi() {\n"); classBuilder.append(" return (").append(typeAPIClassname).append(") delegate.getTypeAPI();\n"); classBuilder.append(" }\n\n"); } }
public HollowSetTypeReadState(HollowReadStateEngine stateEngine, HollowSetSchema schema, int numShards) { super(stateEngine, schema); this.sampler = new HollowSetSampler(schema.getName(), DisabledSamplingDirector.INSTANCE); this.shardNumberMask = numShards - 1; this.shardOrdinalShift = 31 - Integer.numberOfLeadingZeros(numShards); if(numShards < 1 || 1 << shardOrdinalShift != numShards) throw new IllegalArgumentException("Number of shards must be a power of 2!"); HollowSetTypeReadStateShard shards[] = new HollowSetTypeReadStateShard[numShards]; for(int i=0;i<shards.length;i++) shards[i] = new HollowSetTypeReadStateShard(); this.shards = shards; }
@Override public boolean equals(Object other) { if(!(other instanceof HollowSetSchema)) return false; HollowSetSchema otherSchema = (HollowSetSchema)other; if(!getName().equals(otherSchema.getName())) return false; if(!getElementType().equals(otherSchema.getElementType())) return false; return isNullableObjectEquals(hashKey, otherSchema.getHashKey()); }
@Override public String toString() { StringBuilder builder = new StringBuilder(getName()); builder.append(" Set<").append(getElementType()).append(">"); if(hashKey != null) { builder.append(" @HashKey("); if(hashKey.numFields() > 0) { builder.append(hashKey.getFieldPath(0)); for(int i=1;i<hashKey.numFields();i++) { builder.append(", ").append(hashKey.getFieldPath(i)); } } builder.append(")"); } builder.append(";"); return builder.toString(); }
@Override protected void applyToChecksum(HollowChecksum checksum, HollowSchema withSchema) { if(!getSchema().equals(withSchema)) throw new IllegalArgumentException("HollowSetTypeReadState cannot calculate checksum with unequal schemas: " + getSchema().getName()); BitSet populatedOrdinals = getListener(PopulatedOrdinalListener.class).getPopulatedOrdinals(); for(int i=0;i<shards.length;i++) shards[i].applyToChecksum(checksum, populatedOrdinals, i, shards.length); }
private void addTestSet(int... elementOrdinals) { HollowSetWriteRecord rec = new HollowSetWriteRecord(); for(int ordinal : elementOrdinals) rec.addElement(ordinal); writeStateEngine.add(setSchema.getName(), rec); }
@Override public int relativeBucketValue(int ordinal, int bucketIndex) { recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowSetTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).relativeBucketValue(ordinal, bucketIndex); return removedRecords().relativeBucketValue(getMappedOrdinal(ordinal), bucketIndex); }
private int addSetRec(HollowWriteStateEngine stateEngine, TypeDRec[] typeDs) { HollowSetWriteRecord setRec = new HollowSetWriteRecord(); for(TypeDRec typeD : typeDs) { setRec.addElement(addDRec(stateEngine, typeD)); } int setOrdinal = stateEngine.add(setOfTypeDSchema.getName(), setRec); return setOrdinal; }
private int addSetRec(HollowWriteStateEngine stateEngine, TypeDRec[] typeDs) { HollowSetWriteRecord setRec = new HollowSetWriteRecord(); for(TypeDRec typeD : typeDs) { setRec.addElement(addDRec(stateEngine, typeD)); } int setOrdinal = stateEngine.add(setOfTypeDSchema.getName(), setRec); return setOrdinal; }
@Override public int size(int ordinal) { sampler().recordSize(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowSetTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).size(ordinal); return removedRecords().size(getMappedOrdinal(ordinal)); }
@Override public boolean contains(int ordinal, int value, int hashCode) { sampler().recordGet(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowSetTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).contains(ordinal, value, hashCode); return removedRecords().contains(getMappedOrdinal(ordinal), value, hashCode); }
@Override public HollowOrdinalIterator potentialMatchOrdinalIterator(int ordinal, int hashCode) { sampler().recordIterator(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowSetTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).potentialMatchOrdinalIterator(ordinal, hashCode); return removedRecords().potentialMatchOrdinalIterator(getMappedOrdinal(ordinal), hashCode); }
@Override public boolean contains(int ordinal, int value) { sampler().recordGet(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowSetTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).contains(ordinal, value); return removedRecords().contains(getMappedOrdinal(ordinal), value); }
@Override public HollowOrdinalIterator ordinalIterator(int ordinal) { sampler().recordIterator(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowSetTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).ordinalIterator(ordinal); return removedRecords().ordinalIterator(getMappedOrdinal(ordinal)); }
@Test public void parsesSetSchema() throws IOException { String listSchema = "SetOfTypeA Set<TypeA>;\n"; HollowSetSchema schema = (HollowSetSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("SetOfTypeA", schema.getName()); Assert.assertEquals("TypeA", schema.getElementType()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void testMultipleIgnoredTypes() throws Exception { readFilter = new HollowFilterConfig(true); readFilter.addType(listSchema.getName()); readFilter.addType(setSchema.getName()); readFilter.addType(mapSchema.getName()); runThroughTheMotions(); Assert.assertNull(readStateEngine.getTypeState(listSchema.getName())); Assert.assertNull(readStateEngine.getTypeState(setSchema.getName())); Assert.assertNull(readStateEngine.getTypeState(mapSchema.getName())); }
@Test public void parsesSetSchemaWithKey() throws IOException { String listSchema = "SetOfTypeA Set<TypeA> @HashKey(id.value);\n"; HollowSetSchema schema = (HollowSetSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("SetOfTypeA", schema.getName()); Assert.assertEquals("TypeA", schema.getElementType()); Assert.assertEquals(new PrimaryKey("TypeA", "id.value"), schema.getHashKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void parsesSetSchemaWithMultiFieldKey() throws IOException { String listSchema = "SetOfTypeA Set<TypeA> @HashKey(id.value, region.country.id, key);\n"; HollowSetSchema schema = (HollowSetSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("SetOfTypeA", schema.getName()); Assert.assertEquals("TypeA", schema.getElementType()); Assert.assertEquals(new PrimaryKey("TypeA", "id.value", "region.country.id", "key"), schema.getHashKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }