/** * Data type of the header fields of this and all inherited document types * @return merged {@link StructDataType} */ public StructDataType allHeader() { StructDataType ret = new StructDataType(header.getName()); for (Field f : header.getFields()) { ret.addField(f); } for (NewDocumentType inherited : getInherited()) { for (Field f : ((StructDataType) inherited.getHeader()).getFields()) { ret.addField(f); } } return ret; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof StructDataType)) return false; if (!super.equals(o)) return false; StructDataType that = (StructDataType) o; if (superType != null ? !superType.equals(that.superType) : that.superType != null) return false; return true; }
public com.yahoo.compress.CompressionType getCompressionType() { if (getDataType().getCompressionConfig() == null) { return com.yahoo.compress.CompressionType.NONE; } return getDataType().getCompressionConfig().type; }
public void inherit(StructDataType type) { if (superType != null) { throw new IllegalArgumentException("Already inherits type " + superType + ", multiple inheritance not currently supported."); } for (Field f : type.getFields()) { if (hasField(f)) { throw new IllegalArgumentException(f + " already present in " + type + ", " + this + " cannot inherit from it"); } } superType = type; }
private static StructDataType handleStruct(NewDocumentType dt, SDDocumentType type) { StructDataType s = new StructDataType(type.getName()); for (Field f : type.getDocumentType().contentStruct().getFieldsThisTypeOnly()) { specialHandleAnnotationReference(dt, f); s.addField(f); } for (StructDataType inherited : type.getDocumentType().contentStruct().getInheritedTypes()) { s.inherit(inherited); } extractNestedTypes(dt, s); addType(dt, s); return s; }
@Override public int getFieldCount() { return getFields().size(); }
private static boolean structTypeContainsLastFieldNameComponent(StructDataType structType, StringTokenizer fieldNames) { return structType.getField(fieldNames.nextToken()) != null && !fieldNames.hasMoreTokens(); } }
@Override @SuppressWarnings("deprecation") protected void register(DocumentTypeManager manager, List<DataType> seenTypes) { seenTypes.add(this); for (DocumentType type : getInheritedTypes()) { if (!seenTypes.contains(type)) { type.register(manager, seenTypes); } } // Get parent fields into fields specified in this type StructDataType header = headerType.clone(); StructDataType body = bodyType.clone(); header.clearFields(); body.clearFields(); for (Field field : fieldSet()) { (field.isHeader() ? header : body).addField(field); } headerType.assign(header); bodyType.assign(body); if (!seenTypes.contains(headerType)) { headerType.register(manager, seenTypes); } if (!seenTypes.contains(bodyType)) { bodyType.register(manager, seenTypes); } manager.registerSingleType(this); }
doc. name(dt.getName()). headerstruct(dt.contentStruct().getId()). bodystruct(dt.getBodyType().getId()); for (DocumentType inherited : dt.getInheritedTypes()) { doc.inherits(new Datatype.Documenttype.Inherits.Builder().name(inherited.getName())); Datatype.Structtype.Builder structBuilder = new Datatype.Structtype.Builder(); builder.structtype(structBuilder); structBuilder.name(structType.getName()); if (structType.getCompressionConfig().type.getCode() != 0) { structBuilder. compresstype(Datatype.Structtype.Compresstype.Enum.valueOf(structType.getCompressionConfig().type.toString())). compresslevel(structType.getCompressionConfig().compressionLevel). compressthreshold((int)structType.getCompressionConfig().threshold). compressminsize((int)structType.getCompressionConfig().minsize); for (com.yahoo.document.Field field : structType.getFieldsThisTypeOnly()) { Datatype.Structtype.Field.Builder fieldBuilder = new Datatype.Structtype.Field.Builder(); structBuilder.field(fieldBuilder); fieldBuilder.detailedtype(((TensorDataType)field.getDataType()).getTensorType().toString()); for (StructDataType inherited : structType.getInheritedTypes()) { structBuilder.inherits(new Datatype.Structtype.Inherits.Builder().name(inherited.getName()));
private static void registerStructType(DocumentmanagerConfig config, DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Structtype struct) { StructDataType type = new StructDataType(id, struct.name()); if (config.enablecompression()) { CompressionConfig comp = makeCompressionConfig(struct); type.setCompressionConfig(comp); } for (Object j : struct.field()) { DocumentmanagerConfig.Datatype.Structtype.Field field = (DocumentmanagerConfig.Datatype.Structtype.Field) j; DataType fieldType = (field.datatype() == id) ? manager.getDataTypeAndReturnTemporary(field.datatype(), field.detailedtype()) : manager.getDataType(field.datatype(), field.detailedtype()); if (field.id().size() == 1) { type.addField(new Field(field.name(), field.id().get(0).id(), fieldType, true)); } else { type.addField(new Field(field.name(), fieldType, true)); } } manager.register(type); }
private void buildConfig(StructDataType type, DocumenttypesConfig.Documenttype.Datatype.Builder dataTypeBuilder, DocumenttypesConfig.Documenttype.Builder documentBuilder, Set<Integer> built) { dataTypeBuilder.type(DocumenttypesConfig.Documenttype.Datatype.Type.Enum.STRUCT); DocumenttypesConfig.Documenttype.Datatype.Sstruct.Builder structBuilder = new DocumenttypesConfig.Documenttype.Datatype.Sstruct.Builder(); dataTypeBuilder.sstruct(structBuilder); structBuilder.name(type.getName()); if (type.getCompressionConfig().type.getCode() != 0) { structBuilder.compression(new DocumenttypesConfig.Documenttype.Datatype.Sstruct.Compression.Builder(). type(DocumenttypesConfig.Documenttype.Datatype.Sstruct.Compression.Type.Enum.valueOf(type.getCompressionConfig().type.toString())). level(type.getCompressionConfig().compressionLevel). threshold((int) type.getCompressionConfig().threshold). minsize((int) type.getCompressionConfig().minsize)); } for (com.yahoo.document.Field field : type.getFields()) { DocumenttypesConfig.Documenttype.Datatype.Sstruct.Field.Builder builder = new DocumenttypesConfig.Documenttype.Datatype.Sstruct.Field.Builder(); builder.name(field.getName()). id(field.getId()). id_v6(field.getIdV6()). datatype(field.getDataType().getId()); if (field.getDataType() instanceof TensorDataType) { builder.detailedtype(((TensorDataType) field.getDataType()).getTensorType().toString()); } structBuilder.field(builder); buildConfig(field.getDataType(), documentBuilder, built); } }
private static String toString(StructDataType dataType) { StringBuilder builder = new StringBuilder(); builder.append(dataType.getName()).append(":{"); boolean first = true; for (Field field : dataType.getFields()) { if (!first) { builder.append(","); } if (field.getDataType() instanceof StructDataType) { builder.append(toString((StructDataType) field.getDataType())); } else { builder.append(field.getName() + ":" + field.getDataType().getName()); } first = false; } builder.append("}"); return builder.toString(); } }
private static boolean changedType(StructDataType currentType, StructDataType nextType) { for (Field currentField : currentType.getFields()) { Field nextField = nextType.getField(currentField.getName()); if (nextField != null) { if (areStructFields(currentField, nextField)) { if (changedType((StructDataType) currentField.getDataType(), (StructDataType) nextField.getDataType())) { return true; } } else { if (!currentField.getDataType().equals(nextField.getDataType())) { return true; } } } } return false; }
private static StructDataType newInstance() { StructDataType ret = new StructDataType(STRUCT_NAME); ret.addField(new Field(FIELD_X, DataType.INT)); ret.addField(new Field(FIELD_Y, DataType.INT)); return ret; } }
StructDataType s = new StructDataType("annotation."+annotation.getName()); if (anyParentsHavePayLoad(sa, sdoc)) { annotation.setDataType(s); StructDataType s = (StructDataType)dt.getDataType(e.getValue()); if (s != null) { e.getKey().inherit(s);
private static StructDataType handleStruct(NewDocumentType dt, StructDataType s) { for (Field f : s.getFieldsThisTypeOnly()) { specialHandleAnnotationReference(dt, f); } extractNestedTypes(dt, s); addType(dt, s); return s; } private static boolean anyParentsHavePayLoad(SDAnnotationType sa, SDDocumentType sdoc) {
/** * Adds an field that can be used with this document type. * * @param field the field to add */ @SuppressWarnings("deprecation") public void addField(Field field) { if (isRegistered()) { throw new IllegalStateException("You cannot add fields to a document type that is already registered."); } StructDataType struct = (field.isHeader() ? headerType : bodyType); struct.addField(field); }
private void visit(SDDocumentType docOrStruct) { int id; if (docOrStruct.isStruct()) { id = new StructDataType(docOrStruct.getName()).getId(); } else { id = new DocumentType(docOrStruct.getName()).getId(); } if (seenTypes.contains(id)) { return; } else { seenTypes.add((new StructDataType(docOrStruct.getName()).getId())); } for (Field field : docOrStruct.fieldSet()) { if (!seenTypes.contains(field.getDataType().getId())) { //we haven't seen this before, do it visit(field.getDataType()); } } processingOrder.add(docOrStruct); }
/** * Creates a new document type and registers it with the document type manager. * This will be created as version 0 of this document type. * Implicitly registers this with the document type manager. * The document type id will be generated as a hash from the document type name. * * @param name The name of the new document type */ public DocumentType(String name) { this(name, new StructDataType(name + ".header"), new StructDataType(name + ".body")); }