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; } }
public HollowDiffMapCountingNode(HollowDiff diff, HollowTypeDiff topLevelTypeDiff, HollowDiffNodeIdentifier nodeId, HollowMapTypeReadState fromState, HollowMapTypeReadState toState) { super(diff, topLevelTypeDiff, nodeId); this.fromState = fromState; this.toState = toState; HollowTypeReadState keyFromState = fromState == null ? null : fromState.getSchema().getKeyTypeState(); HollowTypeReadState keyToState = toState == null ? null : toState.getSchema().getKeyTypeState(); this.keyNode = getHollowDiffCountingNode(keyFromState, keyToState, "key"); HollowTypeReadState valueFromState = fromState == null ? null : fromState.getSchema().getValueTypeState(); HollowTypeReadState valueToState = toState == null ? null : toState.getSchema().getValueTypeState(); this.valueNode = getHollowDiffCountingNode(valueFromState, valueToState, "value"); String keyType = fromState != null ? fromState.getSchema().getKeyType() : toState.getSchema().getKeyType(); String valueType = fromState != null ? fromState.getSchema().getValueType() : toState.getSchema().getValueType(); this.keyFilter = new DiffEqualOrdinalFilter(equalityMapping.getEqualOrdinalMap(keyType)); this.valueFilter = new DiffEqualOrdinalFilter(equalityMapping.getEqualOrdinalMap(valueType)); this.keyRequiresTraversalForMissingFields = equalityMapping.requiresMissingFieldTraversal(keyType); this.valueRequiresTraversalForMissingFields = equalityMapping.requiresMissingFieldTraversal(valueType); }
@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()); }
public HollowMapJavaGenerator(String packageName, String apiClassname, HollowMapSchema schema, HollowDataset dataset, Set<String> parameterizedTypes, boolean parameterizeClassNames, CodeGeneratorConfig config) { super(packageName, apiClassname, schema, dataset, config); this.schema = schema; this.keyClassName = hollowImplClassname(schema.getKeyType()); this.valueClassName = hollowImplClassname(schema.getValueType()); this.parameterizeKey = parameterizeClassNames || parameterizedTypes.contains(schema.getKeyType()); this.parameterizeValue = parameterizeClassNames || parameterizedTypes.contains(schema.getValueType()); }
@Override public String toString() { StringBuilder builder = new StringBuilder(getName()); builder.append(" Map<").append(getKeyType()).append(",").append(getValueType()).append(">"); if(hashKey != null) { builder.append(" @HashKey("); if(hashKey.numFields() > 0) { builder.append(hashKey.getFieldPath(0)); for(int i=1;i<hashKey.numFields();i++) { builder.append(", ").append(hashKey.getFieldPath(i)); } } builder.append(")"); } builder.append(";"); return builder.toString(); }
private static HollowMapSchema readMapSchemaFrom(DataInputStream is, String schemaName, boolean hasHashKey) throws IOException { String keyType = is.readUTF(); String valueType = is.readUTF(); String hashKeyFields[] = null; if(hasHashKey) { int numFields = VarInt.readVInt(is); hashKeyFields = new String[numFields]; for(int i=0;i<numFields;i++) { hashKeyFields[i] = is.readUTF(); } } return new HollowMapSchema(schemaName, keyType, valueType, hashKeyFields); }
@Override protected String getTypeName() { return schema.getName(); }
void wireTypeStatesToSchemas() { for(HollowTypeReadState state : typeStates.values()) { switch(state.getSchema().getSchemaType()) { case OBJECT: HollowObjectSchema objSchema = (HollowObjectSchema)state.getSchema(); for(int i=0;i<objSchema.numFields();i++) { if(objSchema.getReferencedType(i) != null) objSchema.setReferencedTypeState(i, typeStates.get(objSchema.getReferencedType(i))); } break; case LIST: HollowListSchema listSchema = (HollowListSchema)state.getSchema(); listSchema.setElementTypeState(typeStates.get(listSchema.getElementType())); break; case SET: HollowSetSchema setSchema = (HollowSetSchema)state.getSchema(); setSchema.setElementTypeState(typeStates.get(setSchema.getElementType())); ((HollowSetTypeReadState)state).buildKeyDeriver(); break; case MAP: HollowMapSchema mapSchema = (HollowMapSchema)state.getSchema(); mapSchema.setKeyTypeState(typeStates.get(mapSchema.getKeyType())); mapSchema.setValueTypeState(typeStates.get(mapSchema.getValueType())); ((HollowMapTypeReadState)state).buildKeyDeriver(); break; } } }
private boolean isDefinedHashCode(HollowSchema schema) { if(schema instanceof HollowSetSchema) return typeNamesWithDefinedHashCodes.contains(((HollowSetSchema)schema).getElementType()); if(schema instanceof HollowMapSchema) return typeNamesWithDefinedHashCodes.contains(((HollowMapSchema)schema).getKeyType()); return false; }
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()); }
@Test public void testEqualsWithKeys() { HollowMapSchema s1 = new HollowMapSchema("Test", "TypeA", "TypeB", "f1"); HollowMapSchema s2 = new HollowMapSchema("Test", "TypeA", "TypeB", "f1"); Assert.assertEquals(s1.getHashKey(), s2.getHashKey()); Assert.assertEquals(new PrimaryKey("TypeA", "f1"), s2.getHashKey()); HollowMapSchema s1 = new HollowMapSchema("Test", "TypeA", "TypeB", "f1", "f2"); HollowMapSchema s2 = new HollowMapSchema("Test", "TypeA", "TypeB", "f1", "f2"); Assert.assertEquals(s1.getHashKey(), s2.getHashKey()); Assert.assertEquals(new PrimaryKey("TypeA", "f1", "f2"), s2.getHashKey()); HollowMapSchema s1 = new HollowMapSchema("Test", "TypeA", "TypeB"); HollowMapSchema s2 = new HollowMapSchema("Test", "TypeA", "TypeB", "f1"); Assert.assertNotEquals(s1.getHashKey(), s2.getHashKey()); HollowMapSchema s1 = new HollowMapSchema("Test", "TypeA", "TypeB", "f1"); HollowMapSchema s2 = new HollowMapSchema("Test", "TypeA", "TypeB", "f1", "f2"); Assert.assertNotEquals(s1.getHashKey(), s2.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); }
public SchemaDisplayField(String fieldPath, HollowMapSchema parentSchema, int fieldNumber) { this.fieldPath = fieldPath; this.fieldName = fieldNumber == 0 ? "key" : "value"; this.fieldType = FieldType.REFERENCE; this.isSearchable = false; this.referencedType = fieldNumber == 0 ? new SchemaDisplay(parentSchema.getKeyTypeState().getSchema(), fieldPath) : new SchemaDisplay(parentSchema.getValueTypeState().getSchema(), fieldPath); }
private void appendGetByHashKeyMethod(StringBuilder classBuilder) { if(schema.getHashKey() != null) { String valueReturnType = parameterizeValue ? "V" : valueClassName; classBuilder.append(" public " + valueReturnType + " get("); classBuilder.append(getKeyFieldType(schema.getHashKey().getFieldPath(0))).append(" k0"); for(int i=1;i<schema.getHashKey().numFields();i++) classBuilder.append(", ").append(getKeyFieldType(schema.getHashKey().getFieldPath(i))).append(" k").append(i); classBuilder.append(") {\n"); classBuilder.append(" return findValue(k0"); for(int i=1;i<schema.getHashKey().numFields();i++) classBuilder.append(", k").append(i); classBuilder.append(");\n"); classBuilder.append(" }\n\n"); } }
@Override public boolean equalsValue(int valueOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getValueType(), valueOrdinal, testObject); }
public DiffEqualityMapMapper(DiffEqualityMapping mapping, HollowMapTypeReadState fromState, HollowMapTypeReadState toState, boolean oneToOne) { super(fromState, toState, oneToOne); HollowMapSchema schema = fromState.getSchema(); this.keyEqualOrdinalMap = mapping.getEqualOrdinalMap(schema.getKeyType()); this.valueEqualOrdinalMap = mapping.getEqualOrdinalMap(schema.getValueType()); this.requiresTraversalForMissingFields = mapping.requiresMissingFieldTraversal(schema.getKeyType()) || mapping.requiresMissingFieldTraversal(schema.getValueType()); }
private int addStructuredMap(JsonParser parser, String mapTypeName, HollowMapWriteRecord mapRec) throws IOException { JsonToken token = parser.nextToken(); mapRec.reset(); HollowMapSchema schema = (HollowMapSchema) hollowSchemas.get(mapTypeName); while(token != JsonToken.END_ARRAY) { if(token == JsonToken.START_OBJECT) { int keyOrdinal = -1, valueOrdinal = -1; while(token != JsonToken.END_OBJECT) { if(token == JsonToken.START_OBJECT || token == JsonToken.START_ARRAY) { if("key".equals(parser.getCurrentName())) keyOrdinal = parseSubType(parser, token, schema.getKeyType()); else if("value".equals(parser.getCurrentName())) valueOrdinal = parseSubType(parser, token, schema.getValueType()); } token = parser.nextToken(); } mapRec.addEntry(keyOrdinal, valueOrdinal); } token = parser.nextToken(); } return stateEngine.add(schema.getName(), mapRec); }
private static HollowMapSchema parseMapSchema(String typeName, StreamTokenizer tokenizer) throws IOException { int tok = tokenizer.nextToken(); if(tokenizer.ttype != '<') throw new IOException("Invalid Syntax: Expected '<' after 'Map' for type " + typeName); tok = tokenizer.nextToken(); if(tok != StreamTokenizer.TT_WORD) { log.warning("Invalid Syntax: Expected element type declaration: " + typeName); } String keyType = tokenizer.sval; tok = tokenizer.nextToken(); if(tokenizer.ttype != ',') throw new IOException("Invalid Syntax: Expected ',' after key type declaration: " + typeName); tok = tokenizer.nextToken(); if(tok != StreamTokenizer.TT_WORD) { log.warning("Invalid Syntax: Expected value type declaration: " + typeName); } String valueType = tokenizer.sval; tok = tokenizer.nextToken(); if(tokenizer.ttype != '>') throw new IOException("Invalid Syntax: Expected '>' after value type declaration: " + typeName); tok = tokenizer.nextToken(); String hashKeyPaths[] = parseHashKey(tokenizer); if(tokenizer.ttype != ';') throw new IOException("Invalid Syntax: Expected semicolon after Map schema declaration: " + typeName); return new HollowMapSchema(typeName, keyType, valueType, hashKeyPaths); }
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 boolean equalsKey(int keyOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getKeyType(), keyOrdinal, testObject); }