@Override public 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"); } }
@Override public String toString() { return getName() + " List<" + getElementType() + ">;"; }
@Override public void writeTo(OutputStream os) throws IOException { DataOutputStream dos = new DataOutputStream(os); dos.write(SchemaType.LIST.getTypeId()); dos.writeUTF(getName()); dos.writeUTF(getElementType()); }
public HollowListTypeReadState(HollowReadStateEngine stateEngine, HollowListSchema schema, int numShards) { super(stateEngine, schema); this.sampler = new HollowListSampler(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!"); HollowListTypeReadStateShard shards[] = new HollowListTypeReadStateShard[numShards]; for(int i=0;i<shards.length;i++) shards[i] = new HollowListTypeReadStateShard(); this.shards = shards; }
private void appendListStringify(Writer writer, HollowDataAccess dataAccess, HollowListTypeDataAccess typeDataAccess, int ordinal, int indentation) throws IOException { HollowListSchema schema = typeDataAccess.getSchema(); if(showTypes) writer.append("(").append(schema.getName()).append(")"); if(showOrdinals) writer.append(" (ordinal ").append(Integer.toString(ordinal)).append(")"); indentation++; int size = typeDataAccess.size(ordinal); String elementType = schema.getElementType(); for(int i=0;i<size;i++) { writer.append(NEWLINE); int elementOrdinal = typeDataAccess.getElementOrdinal(ordinal, i); appendIndentation(writer, indentation); writer.append("e" + i + ": "); appendStringify(writer, dataAccess, elementType, elementOrdinal, indentation); } }
@Override protected void applyToChecksum(HollowChecksum checksum, HollowSchema withSchema) { if(!getSchema().equals(withSchema)) throw new IllegalArgumentException("HollowListTypeReadState 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 int copyListRecord(HollowListSchema engineSchema, int currentRecordPointer, int currentRecordOrdinal) { HollowListWriteRecord rec = engineSchema != null ? (HollowListWriteRecord)getWriteRecord(engineSchema) : null; int numElements = VarInt.readVInt(record.data, currentRecordPointer); currentRecordPointer += VarInt.sizeOfVInt(numElements); for(int i=0;i<numElements;i++) { int unmappedElementOrdinal = VarInt.readVInt(record.data, currentRecordPointer); currentRecordPointer += VarInt.sizeOfVInt(unmappedElementOrdinal); if(rec != null) { int mappedElementOrdinal = ordinalMapping.get(unmappedElementOrdinal); rec.addElement(mappedElementOrdinal); } } if(engineSchema != null) { int stateEngineOrdinal = stateEngine.add(engineSchema.getName(), rec); ordinalMapping.put(currentRecordOrdinal, stateEngineOrdinal); } return currentRecordPointer; }
private void addTestList(int... elementOrdinals) { HollowListWriteRecord rec = new HollowListWriteRecord(); for(int ordinal : elementOrdinals) rec.addElement(ordinal); writeStateEngine.add(listSchema.getName(), rec); }
private int addListRec(HollowWriteStateEngine stateEngine, TypeCRec[] typeCs) { HollowListWriteRecord listRec = new HollowListWriteRecord(); for(TypeCRec typeC : typeCs) { listRec.addElement(addCRec(stateEngine, typeC)); } int listOrdinal = stateEngine.add(listOfTypeCSchema.getName(), listRec); return listOrdinal; }
private int addListRec(HollowWriteStateEngine stateEngine, TypeCRec[] typeCs) { HollowListWriteRecord listRec = new HollowListWriteRecord(); for(TypeCRec typeC : typeCs) { listRec.addElement(addCRec(stateEngine, typeC)); } int listOrdinal = stateEngine.add(listOfTypeCSchema.getName(), listRec); return listOrdinal; }
@Override public int getElementOrdinal(int ordinal, int listIndex) { sampler().recordGet(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowListTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).getElementOrdinal(ordinal, listIndex); return removedRecords().getElementOrdinal(getMappedOrdinal(ordinal), listIndex); }
@Override public HollowOrdinalIterator ordinalIterator(int ordinal) { sampler().recordIterator(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowListTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).ordinalIterator(ordinal); return removedRecords().ordinalIterator(getMappedOrdinal(ordinal)); }
@Override public int size(int ordinal) { sampler().recordSize(); recordStackTrace(); if(!ordinalIsPresent(ordinal)) return ((HollowListTypeDataAccess)dataAccess.getTypeDataAccess(getSchema().getName(), ordinal)).size(ordinal); return removedRecords().size(getMappedOrdinal(ordinal)); }
@Test public void parsesListSchema() throws IOException { String listSchema = "ListOfTypeA List<TypeA>;\n"; HollowListSchema schema = (HollowListSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("ListOfTypeA", 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())); }