public static FilteredHollowBlobWriterStreamAndFilter[] combine(OutputStream streams[], HollowFilterConfig configs[]) { if(streams.length != configs.length) throw new IllegalArgumentException("Must provide exactly the same number of streams as configs"); FilteredHollowBlobWriterStreamAndFilter streamAndFilters[] = new FilteredHollowBlobWriterStreamAndFilter[streams.length]; for(int i=0;i<streams.length;i++) streamAndFilters[i] = new FilteredHollowBlobWriterStreamAndFilter(new DataOutputStream(streams[i]), configs[i]); return streamAndFilters; }
public static DataOutputStream[] streamsOnly(FilteredHollowBlobWriterStreamAndFilter[] streamAndFilters) { DataOutputStream streams[] = new DataOutputStream[streamAndFilters.length]; for(int i=0;i<streams.length;i++) streams[i] = streamAndFilters[i].getStream(); return streams; }
FilteredHollowBlobWriterStreamAndFilter allStreamAndFilters[] = FilteredHollowBlobWriterStreamAndFilter.combine(out, configs); List<HollowSchema> filteredSchemaList = getFilteredSchemaList(unfilteredSchemaList, streamAndFilter.getConfig()); header.setSchemas(filteredSchemaList); headerWriter.writeHeader(header, streamAndFilter.getStream()); VarInt.writeVInt(streamAndFilter.getStream(), filteredSchemaList.size()); FilteredHollowBlobWriterStreamAndFilter[] streamsWithType = FilteredHollowBlobWriterStreamAndFilter.withType(schema.getName(), allStreamAndFilters); } else { for(int j=0;j<streamsWithType.length;j++) { schema.writeTo(streamsWithType[j].getStream()); VarInt.writeVInt(streamsWithType[j].getStream(), 1 + VarInt.sizeOfVInt(numShards)); VarInt.writeVInt(streamsWithType[j].getStream(), 0); /// forwards compatibility VarInt.writeVInt(streamsWithType[j].getStream(), numShards); HollowListTypeReadState.discardType(dis, numShards, delta); else copyListState(delta, dis, streamsOnly(streamsWithType), numShards); } else if(schema instanceof HollowSetSchema) { if(streamsWithType.length == 0) HollowSetTypeReadState.discardType(dis, numShards, delta); else copySetState(delta, dis, streamsOnly(streamsWithType), numShards); } else if(schema instanceof HollowMapSchema) { if(streamsWithType.length == 0) HollowMapTypeReadState.discardType(dis, numShards, delta); else copyMapState(delta, dis, streamsOnly(streamsWithType), numShards);
@SuppressWarnings("unchecked") private void copyFilteredObjectState(boolean delta, DataInputStream is, FilteredHollowBlobWriterStreamAndFilter[] streamAndFilters, HollowObjectSchema schema, int numShards) throws IOException { DataOutputStream[] os = streamsOnly(streamAndFilters); HollowObjectSchema[] filteredObjectSchemas = new HollowObjectSchema[os.length]; HollowObjectSchema filteredObjectSchema = getFilteredObjectSchema(schema, streamAndFilters[i].getConfig()); filteredObjectSchemas[i] = filteredObjectSchema; filteredObjectSchema.writeTo(streamAndFilters[i].getStream()); VarInt.writeVInt(streamAndFilters[i].getStream(), 1 + VarInt.sizeOfVInt(numShards)); VarInt.writeVInt(streamAndFilters[i].getStream(), 0); /// forwards compatibility VarInt.writeVInt(streamAndFilters[i].getStream(), numShards); long bitsPerRecord = writeBitsPerField(schema, bitsPerField, filteredObjectSchemas[i], streamAndFilters[i].getStream()); List<DataOutputStream> streamsWithFieldList = new ArrayList<DataOutputStream>(); for(int j=0;j<streamAndFilters.length;j++) { ObjectFilterConfig objectTypeConfig = streamAndFilters[j].getConfig().getObjectTypeConfig(schema.getName()); if(objectTypeConfig.includesField(schema.getFieldName(i))) streamsWithFieldList.add(streamAndFilters[j].getStream());
public static FilteredHollowBlobWriterStreamAndFilter[] withType(String typeName, FilteredHollowBlobWriterStreamAndFilter[] allStreamAndFilters) { int countConfigsWithType = 0; for(int i=0;i<allStreamAndFilters.length;i++) { if(allStreamAndFilters[i].getConfig().doesIncludeType(typeName)) countConfigsWithType++; } FilteredHollowBlobWriterStreamAndFilter[] streamAndFiltersWithType = new FilteredHollowBlobWriterStreamAndFilter[countConfigsWithType]; int withTypeCounter = 0; for(int i=0;i<allStreamAndFilters.length;i++) { if(allStreamAndFilters[i].getConfig().doesIncludeType(typeName)) streamAndFiltersWithType[withTypeCounter++] = allStreamAndFilters[i]; } return streamAndFiltersWithType; }