@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(getName()); if (primaryKey != null) { builder.append(" @PrimaryKey("); if (primaryKey.numFields() > 0) { builder.append(primaryKey.getFieldPath(0)); for (int i = 1; i < primaryKey.numFields(); i++) { builder.append(", ").append(primaryKey.getFieldPath(i)); } } builder.append(")"); } builder.append(" {\n"); for(int i=0;i<numFields();i++) { builder.append("\t"); if(getFieldType(i) == FieldType.REFERENCE) { builder.append(getReferencedType(i)); } else { builder.append(getFieldType(i).toString().toLowerCase()); } builder.append(" ").append(getFieldName(i)).append(";\n"); } builder.append("}"); return builder.toString(); }
this.estimatedMaxStringDuplicates = estimatedMaxStringDuplicates; this.fieldPath = new FieldPath(readStateEngine, type, fieldPath); if (!this.fieldPath.getLastFieldType().equals(HollowObjectSchema.FieldType.STRING)) throw new IllegalArgumentException("Field path should lead to a string type");
@Override public void writeTo(OutputStream os) throws IOException { DataOutputStream dos = new DataOutputStream(os); if (primaryKey != null) dos.write(SchemaType.OBJECT.getTypeIdWithPrimaryKey()); else dos.write(SchemaType.OBJECT.getTypeId()); dos.writeUTF(getName()); if (primaryKey != null) { VarInt.writeVInt(dos, primaryKey.numFields()); for (int i = 0; i < primaryKey.numFields(); i++) { dos.writeUTF(primaryKey.getFieldPath(i)); } } dos.writeShort(size); for(int i=0;i<size;i++) { dos.writeUTF(fieldNames[i]); dos.writeUTF(fieldTypes[i].name()); if(fieldTypes[i] == FieldType.REFERENCE) dos.writeUTF(referencedTypes[i]); } }
HollowObjectTypeDataAccess objectTypeDataAccess = (HollowObjectTypeDataAccess) typeDataAccess; if (fieldTypes[fieldIndex].equals(FieldType.REFERENCE)) { int refOrdinal = objectTypeDataAccess.readOrdinal(ordinal, fieldPositions[fieldIndex]); if (refOrdinal >= 0) {
HollowObjectTypeDataAccess objectTypeDataAccess = (HollowObjectTypeDataAccess) typeDataAccess; if (fieldTypes[fieldIndex].equals(FieldType.REFERENCE)) {
for(int i=0;i<schema.numFields();i++) { String fieldName = schema.getFieldName(i); String fieldType = schema.getFieldType(i) == FieldType.REFERENCE ? schema.getReferencedType(i) : schema.getFieldType(i).toString(); Object fieldValue = null;
for(int i=0;i<fieldIndexes.length;i++) { int fieldIdx = fieldIndexes[i]; if(!schema.getFieldType(fieldIdx).isVariableLength()) { long bitOffset = fieldOffset(currentData, shardOrdinal, fieldIdx); int numBitsForField = currentData.bitsPerField[fieldIdx];
if (FieldType.REFERENCE.equals(ft)) { HollowObjectSchema refSchema = pk.getFieldSchema(dataset, i); params.add(refSchema.getName() + " " + fn);
public HollowDiffObjectCountingNode(HollowDiff diff, HollowTypeDiff topLevelTypeDiff, HollowDiffNodeIdentifier nodeId, HollowObjectTypeReadState fromState, HollowObjectTypeReadState toState) { super(diff, topLevelTypeDiff, nodeId); this.fromState = fromState; this.toState = toState; this.fromSchema = fromState == null ? emptySchema(toState.getSchema()) : fromState.getSchema(); this.toSchema = toState == null ? emptySchema(fromState.getSchema()) : toState.getSchema(); if(!fromSchema.getName().equals(toSchema.getName())) throw new IllegalArgumentException("Cannot diff between two schemas with different names: from '" + fromSchema.getName() + "' to '" + toSchema.getName() + "'"); this.unionSchema = fromSchema.findUnionSchema(toSchema); this.fieldNodes = new HollowDiffCountingNode[unionSchema.numFields()]; this.fromFieldMapping = createFieldMapping(unionSchema, fromSchema); this.toFieldMapping = createFieldMapping(unionSchema, toSchema); this.fieldRequiresMissingFieldTraversal = new boolean[unionSchema.numFields()]; this.fieldEqualOrdinalFilters = new DiffEqualOrdinalFilter[unionSchema.numFields()]; for(int i=0;i<unionSchema.numFields();i++) { int fromFieldIndex = fromSchema.getPosition(unionSchema.getFieldName(i)); int toFieldIndex = toSchema.getPosition(unionSchema.getFieldName(i)); if(unionSchema.getFieldType(i) == FieldType.REFERENCE) { HollowTypeReadState refFromState = fromFieldIndex == -1 ? null : fromSchema.getReferencedTypeState(fromFieldIndex); HollowTypeReadState refToState = toFieldIndex == -1 ? null : toSchema.getReferencedTypeState(toFieldIndex); fieldNodes[i] = getHollowDiffCountingNode(refFromState, refToState, unionSchema.getFieldName(i)); fieldEqualOrdinalFilters[i] = new DiffEqualOrdinalFilter(equalityMapping.getEqualOrdinalMap(unionSchema.getReferencedType(i))); if(refFromState == null || refToState == null || equalityMapping.requiresMissingFieldTraversal(unionSchema.getReferencedType(i))) fieldRequiresMissingFieldTraversal[i] = true; } else { HollowDiffNodeIdentifier childNodeId = new HollowDiffNodeIdentifier(nodeId, unionSchema.getFieldName(i), unionSchema.getFieldType(i).toString()); fieldNodes[i] = new HollowDiffFieldCountingNode(diff, topLevelTypeDiff, childNodeId, fromState, toState, unionSchema, i); } } }
public HollowObjectSchema findCommonSchema(HollowObjectSchema otherSchema) { if(!getName().equals(otherSchema.getName())) { throw new IllegalArgumentException("Cannot find common schema of two schemas with different names!"); } int commonFields = 0; for (String fieldName : fieldNames) { if(otherSchema.getPosition(fieldName) != -1) { commonFields++; } } PrimaryKey primaryKey = isNullableObjectEquals(this.primaryKey, otherSchema.getPrimaryKey()) ? this.primaryKey : null; HollowObjectSchema commonSchema = new HollowObjectSchema(getName(), commonFields, primaryKey); for (int i = 0; i < fieldNames.length; i++) { int otherFieldIndex = otherSchema.getPosition(fieldNames[i]); if (otherFieldIndex != -1) { if (fieldTypes[i] != otherSchema.getFieldType(otherFieldIndex) || !referencedTypesEqual(referencedTypes[i], otherSchema.getReferencedType(otherFieldIndex))) { String fieldType = fieldTypes[i] == FieldType.REFERENCE ? referencedTypes[i] : fieldTypes[i].toString().toLowerCase(); String otherFieldType = otherSchema.getFieldType(otherFieldIndex) == FieldType.REFERENCE ? otherSchema.getReferencedType(otherFieldIndex) : otherSchema.getFieldType(otherFieldIndex).toString().toLowerCase(); throw new IncompatibleSchemaException(getName(), fieldNames[i], fieldType, otherFieldType); } commonSchema.addField(fieldNames[i], fieldTypes[i], referencedTypes[i]); } } return commonSchema; }
public static String getJavaBoxedType(FieldType fieldType) { switch(fieldType) { case BOOLEAN: return "Boolean"; case BYTES: return "byte[]"; case DOUBLE: return "Double"; case FLOAT: return "Float"; case LONG: return "Long"; case INT: case REFERENCE: return "Integer"; case STRING: return "String"; } throw new IllegalArgumentException("Java boxed type is not known for FieldType." + fieldType.toString()); }
public static String getJavaScalarType(FieldType fieldType) { switch(fieldType) { case BOOLEAN: return "boolean"; case BYTES: return "byte[]"; case DOUBLE: return "double"; case FLOAT: return "float"; case LONG: return "long"; case INT: case REFERENCE: return "int"; case STRING: return "String"; } throw new IllegalArgumentException("Java scalar type is not known for FieldType." + fieldType.toString()); }
private static HollowObjectSchema readObjectSchemaFrom(DataInputStream is, String schemaName, boolean hasPrimaryKey) throws IOException { String[] keyFieldPaths = null; if (hasPrimaryKey) { int numFields = VarInt.readVInt(is); keyFieldPaths = new String[numFields]; for(int i=0;i<numFields;i++) { keyFieldPaths[i] = is.readUTF(); } } int numFields = is.readShort(); HollowObjectSchema schema = new HollowObjectSchema(schemaName, numFields, keyFieldPaths); for(int i=0;i<numFields;i++) { String fieldName = is.readUTF(); FieldType fieldType = FieldType.valueOf(is.readUTF()); String referencedType = fieldType == FieldType.REFERENCE ? is.readUTF() : null; schema.addField(fieldName, fieldType, referencedType); } return schema; }
public String toString() { return Arrays.toString(path) + " (" + type.toString() + ")"; } }
private void writeField(ByteDataBuffer buf, int fieldIndex) { if (isNonNull[fieldIndex]) { if (getSchema().getFieldType(fieldIndex).isVariableLength()) VarInt.writeVInt(buf, (int)fieldData[fieldIndex].length()); fieldData[fieldIndex].copyTo(buf); } else { writeNull(buf, schema.getFieldType(fieldIndex)); } }