@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 HollowMapTypeReadState(HollowReadStateEngine stateEngine, HollowMapSchema schema, int numShards) { super(stateEngine, schema); this.sampler = new HollowMapSampler(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!"); HollowMapTypeReadStateShard shards[] = new HollowMapTypeReadStateShard[numShards]; for(int i=0; i<shards.length; i++) shards[i] = new HollowMapTypeReadStateShard(); this.shards = shards; }
@Override public boolean equals(Object other) { if(!(other instanceof HollowMapSchema)) return false; HollowMapSchema otherSchema = (HollowMapSchema)other; if(!getName().equals(otherSchema.getName())) return false; if(!getKeyType().equals(otherSchema.getKeyType())) return false; if(!getValueType().equals(otherSchema.getValueType())) return false; return isNullableObjectEquals(hashKey, otherSchema.getHashKey()); }
@Override protected void applyToChecksum(HollowChecksum checksum, HollowSchema withSchema) { if(!getSchema().equals(withSchema)) throw new IllegalArgumentException("HollowMapTypeReadState 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 String getKeyFieldType(String fieldPath) { try { HollowObjectSchema keySchema = (HollowObjectSchema)dataset.getSchema(schema.getKeyType()); String fieldPathElements[] = fieldPath.split("\\."); int idx = 0; while(idx < fieldPathElements.length-1) { keySchema = (HollowObjectSchema)dataset.getSchema(keySchema.getReferencedType(fieldPathElements[idx])); idx++; } FieldType fieldType = keySchema.getFieldType(keySchema.getPosition(fieldPathElements[idx])); return HollowCodeGenerationUtils.getJavaBoxedType(fieldType); } catch(Throwable th) { } throw new IllegalArgumentException("Field path '" + fieldPath + "' specified incorrectly for type: " + schema.getName()); }
private void addTestMap(int... keyAndValueOrdinals) { HollowMapWriteRecord rec = new HollowMapWriteRecord(); for(int i=0;i<keyAndValueOrdinals.length; i+= 2) rec.addEntry(keyAndValueOrdinals[i], keyAndValueOrdinals[i+1]); writeStateEngine.add(mapSchema.getName(), rec); }
@Override public HollowMapEntryOrdinalIterator ordinalIterator(int ordinal) { sampler().recordIterator(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowMapTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).ordinalIterator(ordinal); return removedRecords().ordinalIterator(getMappedOrdinal(ordinal)); }
@Override public int get(int ordinal, int keyOrdinal) { sampler().recordGet(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowMapTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).get(ordinal, keyOrdinal); return removedRecords().get(getMappedOrdinal(ordinal), keyOrdinal); }
@Override public HollowMapEntryOrdinalIterator potentialMatchOrdinalIterator(int ordinal, int hashCode) { sampler().recordIterator(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowMapTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).potentialMatchOrdinalIterator(ordinal, hashCode); return removedRecords().potentialMatchOrdinalIterator(getMappedOrdinal(ordinal), hashCode); }
@Override public int get(int ordinal, int keyOrdinal, int hashCode) { sampler().recordGet(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowMapTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).get(ordinal, keyOrdinal, hashCode); return removedRecords().get(getMappedOrdinal(ordinal), keyOrdinal, hashCode); }
@Override public int size(int ordinal) { sampler().recordSize(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowMapTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).size(ordinal); return removedRecords().size(getMappedOrdinal(ordinal)); }
@Override public long relativeBucket(int ordinal, int bucketIndex) { sampler().recordBucketRetrieval(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowMapTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).relativeBucket(ordinal, bucketIndex); return removedRecords().relativeBucket(getMappedOrdinal(ordinal), bucketIndex); }
private int addMapRec(HollowWriteStateEngine stateEngine, MapEntry[] mapEntries) { HollowMapWriteRecord mapRec = new HollowMapWriteRecord(); for(MapEntry entry : mapEntries) { int cOrdinal = addCRec(stateEngine, entry.key); int dOrdinal = addDRec(stateEngine, entry.value); mapRec.addEntry(cOrdinal, dOrdinal); } int mapOrdinal = stateEngine.add(mapOfTypeCToTypeDSchema.getName(), mapRec); return mapOrdinal; }
private int addMapRec(HollowWriteStateEngine stateEngine, MapEntry[] mapEntries) { HollowMapWriteRecord mapRec = new HollowMapWriteRecord(); for(MapEntry entry : mapEntries) { int cOrdinal = addCRec(stateEngine, entry.key); int dOrdinal = addDRec(stateEngine, entry.value); mapRec.addEntry(cOrdinal, dOrdinal); } int mapOrdinal = stateEngine.add(mapOfTypeCToTypeDSchema.getName(), mapRec); return mapOrdinal; }
@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 parsesMapSchema() throws IOException { String listSchema = "MapOfStringToTypeA Map<String, TypeA>;\n"; HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("MapOfStringToTypeA", schema.getName()); Assert.assertEquals("String", schema.getKeyType()); Assert.assertEquals("TypeA", schema.getValueType()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void parsesMapSchemaWithMultiFieldPrimaryKey() throws IOException { String listSchema = "MapOfStringToTypeA Map<String, TypeA> @HashKey(id.value, region.country.id, key);\n"; HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("MapOfStringToTypeA", schema.getName()); Assert.assertEquals("String", schema.getKeyType()); Assert.assertEquals("TypeA", schema.getValueType()); Assert.assertEquals(new PrimaryKey("String", "id.value", "region.country.id", "key"), schema.getHashKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void parsesMapSchemaWithPrimaryKey() throws IOException { String listSchema = "MapOfStringToTypeA Map<String, TypeA> @HashKey(value);\n"; HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("MapOfStringToTypeA", schema.getName()); Assert.assertEquals("String", schema.getKeyType()); Assert.assertEquals("TypeA", schema.getValueType()); Assert.assertEquals(new PrimaryKey("String", "value"), schema.getHashKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }