@Override public void writeTo(OutputStream os) throws IOException { DataOutputStream dos = new DataOutputStream(os); if(getHashKey() != null) dos.write(SchemaType.SET.getTypeIdWithPrimaryKey()); else dos.write(SchemaType.SET.getTypeId()); dos.writeUTF(getName()); dos.writeUTF(getElementType()); if(getHashKey() != null) { VarInt.writeVInt(dos, getHashKey().numFields()); for(int i=0;i<getHashKey().numFields();i++) { dos.writeUTF(getHashKey().getFieldPath(i)); } } }
public void buildKeyDeriver() { if(getSchema().getHashKey() != null) this.keyDeriver = new HollowPrimaryKeyValueDeriver(getSchema().getHashKey(), getStateEngine()); for(int i=0;i<shards.length;i++) shards[i].setKeyDeriver(keyDeriver); }
void buildKeyMatcher() { PrimaryKey hashKey = getSchema().getHashKey(); if(hashKey != null) this.keyMatcher = new HistoricalPrimaryKeyMatcher(getDataAccess(), hashKey); }
@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()); }
Assert.assertEquals(s1.getHashKey(), s2.getHashKey()); Assert.assertEquals(new PrimaryKey("TypeA", "f1"), s2.getHashKey()); Assert.assertEquals(s1.getHashKey(), s2.getHashKey()); Assert.assertEquals(new PrimaryKey("TypeA", "f1", "f2"), s2.getHashKey()); Assert.assertNotEquals(s1.getHashKey(), s2.getHashKey()); Assert.assertNotEquals(s1.getHashKey(), s2.getHashKey());
@Override public boolean contains(HollowSet<T> set, int ordinal, Object o) { if(getSchema().getHashKey() != null) { for(int i=0;i<ordinals.length;i++) { if(ordinals[i] != -1 && set.equalsElement(ordinals[i], o)) return true; } } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(o); int bucket = HashCodes.hashInt(hashCode) & hashMask; while(ordinals[bucket] != -1) { if(set.equalsElement(ordinals[bucket], o)) return true; bucket ++; bucket &= hashMask; } } return false; }
public static HollowSchema withoutKeys(HollowSchema schema) { switch(schema.getSchemaType()) { case SET: HollowSetSchema setSchema = (HollowSetSchema)schema; if(setSchema.getHashKey() != null) setSchema = new HollowSetSchema(setSchema.getName(), setSchema.getElementType()); return setSchema; case MAP: HollowMapSchema mapSchema = (HollowMapSchema)schema; if(mapSchema.getHashKey() != null) mapSchema = new HollowMapSchema(mapSchema.getName(), mapSchema.getKeyType(), mapSchema.getValueType()); return mapSchema; default: return schema; } }
@Override public boolean contains(HollowSet<T> set, int ordinal, Object o) { HollowOrdinalIterator iter; if(getSchema().getHashKey() != null) { iter = dataAccess.ordinalIterator(ordinal); } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(o); iter = dataAccess.potentialMatchOrdinalIterator(ordinal, hashCode); } int potentialOrdinal = iter.next(); while(potentialOrdinal != HollowOrdinalIterator.NO_MORE_ORDINALS) { if(set.equalsElement(potentialOrdinal, o)) return true; potentialOrdinal = iter.next(); } return false; }
if(getSchema().getHashKey() != null) primaryKeyHasher = new HollowWriteStateEnginePrimaryKeyHasher(getSchema().getHashKey(), getStateEngine());
@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())); }
@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())); }
if(getSchema().getHashKey() != null) primaryKeyHasher = new HollowWriteStateEnginePrimaryKeyHasher(getSchema().getHashKey(), getStateEngine());