private HollowSchema getFilteredSchema(HollowSchema schema, HollowFilterConfig filterConfig) { if(filterConfig.doesIncludeType(schema.getName())) { if(schema.getSchemaType() == SchemaType.OBJECT) return getFilteredObjectSchema((HollowObjectSchema) schema, filterConfig); return schema; } return null; }
private String readTypeStateDelta(DataInputStream is, HollowBlobHeader header) throws IOException { HollowSchema schema = HollowSchema.readFrom(is); int numShards = readNumShards(is); HollowTypeReadState typeState = stateEngine.getTypeState(schema.getName()); if(typeState != null) { typeState.applyDelta(is, schema, stateEngine.getMemoryRecycler()); } else { discardDelta(is, schema, numShards); } return schema.getName(); }
public static HollowSchema readFrom(InputStream is) throws IOException { int schemaTypeId = is.read(); DataInputStream dis = new DataInputStream(is); String schemaName = dis.readUTF(); switch(SchemaType.fromTypeId(schemaTypeId)) { case OBJECT: return readObjectSchemaFrom(dis, schemaName, SchemaType.hasKey(schemaTypeId)); case LIST: return readListSchemaFrom(dis, schemaName); case SET: return readSetSchemaFrom(dis, schemaName, SchemaType.hasKey(schemaTypeId)); case MAP: return readMapSchemaFrom(dis, schemaName, SchemaType.hasKey(schemaTypeId)); } throw new IOException(); }
public String getTypeName() { return schema.getName(); }
private String schemaType(HollowSchema schema) { switch(schema.getSchemaType()) { case OBJECT: return "Object"; case LIST: return "List"; case SET: return "Set"; case MAP: return "Map"; default: throw new IllegalArgumentException(); } }
HollowSchema schema = HollowSchema.readFrom(in); encounteredTypes.add(schema.getName()); 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(schemasStream, header.getSchemas().size()); for(HollowSchema schema : header.getSchemas()) schema.writeTo(schemasStream); byte[] schemasData = schemasStream.toByteArray();
@Test public void isNullableObjectEquals() { Assert.assertTrue(HollowSchema.isNullableObjectEquals(null, null)); Assert.assertTrue(HollowSchema.isNullableObjectEquals("S1", "S1")); Assert.assertTrue(HollowSchema.isNullableObjectEquals(1, 1)); Assert.assertFalse(HollowSchema.isNullableObjectEquals(null, 1)); Assert.assertFalse(HollowSchema.isNullableObjectEquals(null, "S1")); Assert.assertFalse(HollowSchema.isNullableObjectEquals("S1", null)); Assert.assertFalse(HollowSchema.isNullableObjectEquals("S1", "")); Assert.assertFalse(HollowSchema.isNullableObjectEquals("S1", "S2")); Assert.assertFalse(HollowSchema.isNullableObjectEquals("S1", 1)); }
schemas.add(HollowSchema.readFrom(is)); header.setSchemas(schemas);
public void setNumShards(int numShards) { if(this.numShards == -1) { this.numShards = numShards; } else if(this.numShards != numShards) { throw new IllegalStateException("The number of shards for type " + schema.getName() + " is already fixed to " + this.numShards + ". Cannot reset to " + numShards + "."); } }
private PrimaryKey getPrimaryKey(HollowSchema schema) { if(schema.getSchemaType() == SchemaType.OBJECT) return ((HollowObjectSchema)schema).getPrimaryKey(); return null; }
schema.writeTo(dos);
private static Map<String, HollowWriteRecord> createWriteRecords(HollowWriteStateEngine stateEngine) { Map<String, HollowWriteRecord> hollowWriteRecords = new HashMap<>(); for (HollowSchema schema : stateEngine.getSchemas()) { switch (schema.getSchemaType()) { case LIST: hollowWriteRecords.put(schema.getName(), new HollowListWriteRecord()); break; case MAP: hollowWriteRecords.put(schema.getName(), new HollowMapWriteRecord()); break; case OBJECT: hollowWriteRecords.put(schema.getName(), new HollowObjectWriteRecord((HollowObjectSchema)schema)); break; case SET: hollowWriteRecords.put(schema.getName(), new HollowSetWriteRecord()); break; } } return hollowWriteRecords; }
private boolean schemaExists(String schemaName, Collection<HollowSchema> allSchemas) { for(HollowSchema schema : allSchemas) { if(schema.getName().equals(schemaName)) return true; } return false; }
public static boolean isCollectionType(String schemaName, HollowDataset dataset) { return dataset.getSchema(schemaName).getSchemaType() != HollowSchema.SchemaType.OBJECT; } }
private String readTypeStateSnapshot(DataInputStream is, HollowBlobHeader header, HollowFilterConfig filter) throws IOException { HollowSchema schema = HollowSchema.readFrom(is); if(!filter.doesIncludeType(schema.getName())) { HollowObjectTypeReadState.discardSnapshot(is, (HollowObjectSchema)schema, numShards); } else { if(!filter.doesIncludeType(schema.getName())) { HollowListTypeReadState.discardSnapshot(is, numShards); } else { if(!filter.doesIncludeType(schema.getName())) { HollowSetTypeReadState.discardSnapshot(is, numShards); } else { if(!filter.doesIncludeType(schema.getName())) { HollowMapTypeReadState.discardSnapshot(is, numShards); } else { return schema.getName();
@Test public void testTransient() throws IOException { HollowObjectMapper mapper = new HollowObjectMapper(writeStateEngine); mapper.initializeTypeState(TestTransientClass.class); mapper.add(new TestTransientClass(1, 2, 3)); roundTripSnapshot(); HollowSchema schema = readStateEngine.getSchema("TestTransientClass"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); schema.writeTo(baos); String schemeText = baos.toString(); Assert.assertTrue(schemeText.contains("notTransient")); Assert.assertFalse(schemeText.contains("transientKeyword")); Assert.assertFalse(schemeText.contains("annotatedTransient")); }
private Set<HollowSchema> getCommonSchemas(HollowReadStateEngine from, HollowReadStateEngine to) { Set<HollowSchema> schemas = new HashSet<HollowSchema>(); for(HollowSchema fromSchema : from.getSchemas()) { HollowSchema toSchema = to.getTypeState(fromSchema.getName()).getSchema(); if(toSchema != null) { if(fromSchema.getSchemaType() == SchemaType.OBJECT) { HollowObjectSchema commonSchema = ((HollowObjectSchema)fromSchema).findCommonSchema((HollowObjectSchema)toSchema); schemas.add(commonSchema); } else { schemas.add(toSchema); } } } return schemas; }
private Map<String, HollowSchema> mapSchemas(Collection<HollowSchema> schemas) { Map<String, HollowSchema> schemaMap = new HashMap<String, HollowSchema>(); for(HollowSchema schema : schemas) { schemaMap.put(schema.getName(), schema); } return schemaMap; }
public AbstractHollowDataAccessor(HollowReadStateEngine rStateEngine, String type, PrimaryKey primaryKey) { this.rStateEngine = rStateEngine; HollowSchema schema = rStateEngine.getTypeState(type).getSchema(); if (schema instanceof HollowObjectSchema) { this.type = type; if (primaryKey == null) { HollowObjectSchema oSchema = ((HollowObjectSchema) schema); this.primaryKey = oSchema.getPrimaryKey(); } else { this.primaryKey = primaryKey; } if (this.primaryKey == null) throw new RuntimeException(String.format("Unsupported DataType=%s with SchemaType=%s : %s", type, schema.getSchemaType(), "PrimaryKey is missing")); } else { throw new RuntimeException(String.format("Unsupported DataType=%s with SchemaType=%s : %s", type, schema.getSchemaType(), "Only supported type=" + SchemaType.OBJECT)); } }