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(); } }
private PrimaryKey getPrimaryKey(HollowSchema schema) { if(schema.getSchemaType() == SchemaType.OBJECT) return ((HollowObjectSchema)schema).getPrimaryKey(); return null; }
public static boolean isCollectionType(String schemaName, HollowDataset dataset) { return dataset.getSchema(schemaName).getSchemaType() != HollowSchema.SchemaType.OBJECT; } }
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)); } }
private int copyRecord(HollowSchema recordSchema, HollowSchema engineSchema, int currentRecordPointer, int currentRecordOrdinal) { switch(recordSchema.getSchemaType()) { case OBJECT: return copyObjectRecord((HollowObjectSchema)recordSchema, (HollowObjectSchema)engineSchema, currentRecordPointer, currentRecordOrdinal); case LIST: return copyListRecord((HollowListSchema)engineSchema, currentRecordPointer, currentRecordOrdinal); case SET: return copySetRecord((HollowSetSchema)engineSchema, currentRecordPointer, currentRecordOrdinal); case MAP: return copyMapRecord((HollowMapSchema)engineSchema, currentRecordPointer, currentRecordOrdinal); default: throw new IllegalStateException("Unknown schema type: " + recordSchema.getSchemaType()); } }
private void initializePrimaryKeys() { List<PrimaryKey> keys = new ArrayList<PrimaryKey>(); for (HollowSchema schema : output.getSchemas()) { if (schema.getSchemaType() == SchemaType.OBJECT) { PrimaryKey pk = ((HollowObjectSchema) schema).getPrimaryKey(); if (pk != null) keys.add(pk); } } this.primaryKeys = sortPrimaryKeys(keys); }
private boolean shouldPreserveHashPositions(HollowSchema schema) { switch(schema.getSchemaType()) { case MAP: return from.getTypesWithDefinedHashCodes().contains(((HollowMapSchema)schema).getKeyType()); case SET: return from.getTypesWithDefinedHashCodes().contains(((HollowSetSchema)schema).getElementType()); default: return false; } }
private boolean shouldPreserveHashPositions(HollowSchema schema) { switch(schema.getSchemaType()) { case MAP: return readEngine.getTypesWithDefinedHashCodes().contains(((HollowMapSchema)schema).getKeyType()); case SET: return readEngine.getTypesWithDefinedHashCodes().contains(((HollowSetSchema)schema).getElementType()); default: return false; } }
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; }
List<Field> createFields(HollowEffigy effigy) { switch(effigy.dataAccess.getSchema().getSchemaType()) { case OBJECT: return createObjectFields(effigy); case LIST: case SET: return createCollectionFields(effigy); case MAP: return createMapFields(effigy); } throw new IllegalArgumentException(); }
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 List<PrimaryKey> extractPrimaryKeys(HollowDataset dataset) { List<PrimaryKey> keys = new ArrayList<PrimaryKey>(); for (HollowSchema schema : dataset.getSchemas()) { if (schema.getSchemaType() == SchemaType.OBJECT) { PrimaryKey pk = ((HollowObjectSchema) schema).getPrimaryKey(); if (pk != null) keys.add(pk); } } return keys; }
protected HollowDiffCountingNode getHollowDiffCountingNode(HollowTypeReadState refFromState, HollowTypeReadState refToState, String viaFieldName) { if(refFromState == null && refToState == null) return HollowDiffMissingCountingNode.INSTANCE; HollowSchema elementSchema = refFromState == null ? refToState.getSchema() : refFromState.getSchema(); HollowDiffNodeIdentifier childNodeId = new HollowDiffNodeIdentifier(this.nodeId, viaFieldName, elementSchema.getName()); if(topLevelTypeDiff.isShortcutType(elementSchema.getName())) return new HollowDiffShortcutTypeCountingNode(diff, topLevelTypeDiff, childNodeId); switch(elementSchema.getSchemaType()) { case OBJECT: return new HollowDiffObjectCountingNode(diff, topLevelTypeDiff, childNodeId, (HollowObjectTypeReadState)refFromState, (HollowObjectTypeReadState)refToState); case LIST: case SET: return new HollowDiffCollectionCountingNode(diff, topLevelTypeDiff, childNodeId, (HollowCollectionTypeReadState)refFromState, (HollowCollectionTypeReadState)refToState); case MAP: return new HollowDiffMapCountingNode(diff, topLevelTypeDiff, childNodeId, (HollowMapTypeReadState)refFromState, (HollowMapTypeReadState)refToState); } throw new IllegalArgumentException("I don't know how to create a HollowDiffCountingNode for a " + elementSchema.getSchemaType()); }
private static void traverseReferencesOutsideClosure(HollowReadStateEngine stateEngine, String referencerType, String referencedType, Map<String, BitSet> matches, TransitiveSetTraverserAction action) { HollowTypeReadState referencerTypeState = stateEngine.getTypeState(referencerType); switch(referencerTypeState.getSchema().getSchemaType()) { case OBJECT: traverseReferencesOutsideClosure(stateEngine, (HollowObjectTypeReadState)referencerTypeState, referencedType, matches, action); break; case LIST: case SET: traverseReferencesOutsideClosure(stateEngine, (HollowCollectionTypeReadState)referencerTypeState, referencedType, matches, action); break; case MAP: traverseReferencesOutsideClosure(stateEngine, (HollowMapTypeReadState)referencerTypeState, referencedType, matches, action); break; } }
private static void addTransitiveMatches(HollowReadStateEngine stateEngine, String type, Map<String, BitSet> matches) { HollowTypeReadState typeState = stateEngine.getTypeState(type); switch(typeState.getSchema().getSchemaType()) { case OBJECT: addTransitiveMatches(stateEngine, (HollowObjectTypeReadState)typeState, matches); break; case LIST: case SET: addTransitiveMatches(stateEngine, (HollowCollectionTypeReadState)typeState, matches); break; case MAP: addTransitiveMatches(stateEngine, (HollowMapTypeReadState)typeState, matches); break; } }
private void traverse(HollowTypeReadState typeState, int ordinal) { switch(typeState.getSchema().getSchemaType()) { case OBJECT: traverseObject((HollowObjectTypeReadState)typeState, ordinal); break; case LIST: traverseList((HollowListTypeReadState)typeState, ordinal); break; case SET: traverseSet((HollowSetTypeReadState)typeState, ordinal); break; case MAP: traverseMap((HollowMapTypeReadState)typeState, ordinal); break; } }
public static List<EffigyFieldPair> pair(HollowEffigy from, HollowEffigy to, Map<String, PrimaryKey> matchHints) { if(from == null || to == null) return new HollowEffigyNullPartnerPairer(from, to).pair(); if(from.getDataAccess() == null) return new HollowEffigyObjectPairer(from, to).pair(); HollowSchema schema = from.getDataAccess().getSchema(); switch(schema.getSchemaType()) { case OBJECT: return new HollowEffigyObjectPairer(from, to).pair(); case MAP: String keyType = ((HollowMapSchema)schema).getKeyType(); return new HollowEffigyMapPairer(from, to, matchHints.get(keyType)).pair(); case LIST: case SET: String elementType = ((HollowCollectionSchema)schema).getElementType(); return new HollowEffigyCollectionPairer(from, to, matchHints.get(elementType)).pair(); } throw new IllegalArgumentException("I don't know how to pair fields for type " + schema.getName() + "(" + schema.getSchemaType() + ")"); } }
private boolean isSearchable(HollowObjectSchema schema, int fieldNumber) { if(schema.getFieldType(fieldNumber) == FieldType.REFERENCE) { if(schema.getReferencedTypeState(fieldNumber).getSchema().getSchemaType() != SchemaType.OBJECT) return false; HollowObjectSchema refObjSchema = (HollowObjectSchema)schema.getReferencedTypeState(fieldNumber).getSchema(); if(refObjSchema.numFields() != 1) return false; return isSearchable(refObjSchema, 0); } return true; }
@Override public FieldType[] getPrimaryKeyFieldTypes(int identifier) { HollowSchema schema = getSchema(identifier); if (schema.getSchemaType() == SchemaType.OBJECT) { PrimaryKey primaryKey = ((HollowObjectSchema) schema).getPrimaryKey(); if (primaryKey != null) { FieldType fieldTypes[] = new FieldType[primaryKey.numFields()]; for (int i = 0; i < fieldTypes.length; i++) { fieldTypes[i] = primaryKey.getFieldType(dataset, i); } return fieldTypes; } } return null; }
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; } }