public SummaryField(Field field, SummaryTransform transform) { this(field.getName(), field.getDataType(), transform); }
/** * This method will add a field to a view. All fields must come from the same document type. Not enforced here. * @param field The field to add. * @return Itself for chaining purposes. */ public FieldView add(Field field) { if (fields.containsKey(field.getName())) { if ( ! fields.get(field.getName()).equals(field)) { throw new IllegalArgumentException( "View '" + name + "' already contains a field with name '" + field.getName() + "' and definition : " + fields.get(field.getName()).toString() + ". Your is : " + field.toString()); } } else { fields.put(field.getName(), field); } return this; }
public void addField(Field field) { if (fields.containsKey(field.getName())) { throw new IllegalArgumentException("Struct " + getName() + " already contains field with name " + field.getName()); } if (fieldIds.containsKey(field.getId(Document.SERIALIZED_VERSION))) { throw new IllegalArgumentException("Struct " + getName() + " already contains field with id " + field.getId(Document.SERIALIZED_VERSION)); } if (fieldIdsV6.containsKey(field.getId(6))) { throw new IllegalArgumentException("Struct " + getName() + " already contains a field with deprecated document serialization id " + field.getId(6)); } fields.put(field.getName(), field); fieldIds.put(field.getId(Document.SERIALIZED_VERSION), field); fieldIdsV6.put(field.getId(6), field); }
@SuppressWarnings("deprecation") private static void specialHandleAnnotationReference(NewDocumentType docType, Field field) { DataType fieldType = specialHandleAnnotationReferenceRecurse(docType, field.getName(), field.getDataType()); if (fieldType == null) { return; } field.setDataType(fieldType); // XXX deprecated }
@Override public String toString() { return "'" + field.getName() + "' " + valueUpdates; }
private FieldPathEntry(Field fieldRef) { type = Type.STRUCT_FIELD; lookupIndex = 0; lookupKey = null; variableName = null; this.fieldRef = fieldRef; resultingDataType = fieldRef.getDataType(); }
@SuppressWarnings("deprecation") static List<Field> flattenField(Field field) { DataType fieldType = field.getDataType(); if (fieldType.getPrimitiveType() != null){ return Collections.singletonList(field); } if (fieldType instanceof ArrayDataType) { boolean header = field.isHeader(); List<Field> ret = new LinkedList<>(); Field innerField = new Field(field.getName(), ((ArrayDataType)fieldType).getNestedType(), header); for (Field flatField : flattenField(innerField)) { ret.add(new Field(flatField.getName(), DataType.getArray(flatField.getDataType()), header)); } return ret; } if (fieldType instanceof StructuredDataType) { List<Field> ret = new LinkedList<>(); String fieldName = field.getName(); for (Field childField : ((StructuredDataType)fieldType).getFields()) { for (Field flatField : flattenField(childField)) { ret.add(new Field(fieldName + "." + flatField.getName(), flatField)); } } return ret; } throw new UnsupportedOperationException(fieldType.getName()); }
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); } }
@Override protected void doSetFieldValue(Field field, FieldValue value) { if (field == null) { throw new IllegalArgumentException("Invalid null field pointer"); } Field myField = getDataType().getField(field.getId()); if (myField==null) { throw new IllegalArgumentException("No such field in "+getDataType()+" : "+field.getName()); } if (!myField .getDataType().isValueCompatible(value)) { throw new IllegalArgumentException( "Incompatible data types. Got " + value.getDataType() + ", expected " + myField.getDataType()); } if (myField.getId() != field.getId()) { throw new IllegalArgumentException( "Inconsistent field: " + field); } int index = values.getIndexOfKey(field.getId()); if (index == -1) { values.put(field.getId(), value); invalidateOrder(); } else { values.setValue(index, value); } }
Datatype.Structtype.Field.Builder fieldBuilder = new Datatype.Structtype.Field.Builder(); structBuilder.field(fieldBuilder); fieldBuilder.name(field.getName()); if (field.hasForcedId()) { fieldBuilder.id(new Datatype.Structtype.Field.Id.Builder().id(field.getId())); fieldBuilder.datatype(field.getDataType().getId()); if (field.getDataType() instanceof TensorDataType) fieldBuilder.detailedtype(((TensorDataType)field.getDataType()).getTensorType().toString());
@Override public void write(FieldUpdate update) { putInt(null, update.getField().getId(Document.SERIALIZED_VERSION)); putInt(null, update.getValueUpdates().size()); for (ValueUpdate vupd : update.getValueUpdates()) { putInt(null, vupd.getValueUpdateClassID().id); vupd.serialize(this, update.getField().getDataType()); } }
@SuppressWarnings("deprecation") private void replaceTemporaryTypesInStruct(StructDataType structDataType, List<DataType> seenStructs) { seenStructs.add(structDataType); for (Field field : structDataType.getFieldsThisTypeOnly()) { DataType fieldType = field.getDataType(); if (fieldType instanceof TemporaryDataType) { field.setDataType(getDataType(fieldType.getCode(), ((TemporaryDataType)fieldType).getDetailedType())); } else { if (!seenStructs.contains(fieldType)) { replaceTemporaryTypes(fieldType, seenStructs); } } } }
private boolean verifyInheritance(NewDocumentType inherited) { for (Field f : getFields()) { Field inhF = inherited.getField(f.getName()); if (inhF != null && !inhF.equals(f)) { throw new IllegalArgumentException("Inherited document '" + inherited.toString() + "' already contains field '" + inhF.getName() + "'. Can not override with '" + f.getName() + "'."); } } for (Field f : inherited.getAllFields()) { for (NewDocumentType side : inherits.values()) { Field sideF = side.getField(f.getName()); if (sideF != null && !sideF.equals(f)) { throw new IllegalArgumentException("Inherited document '" + side.toString() + "' already contains field '" + sideF.getName() + "'. Document '" + inherited.toString() + "' also defines field '" + f.getName() + "'.Multiple inheritance must be disjunctive."); } } } return true; } public void inherit(NewDocumentType inherited) {
/** * The field id must be unique within a document type, and also * within a (unknown at this time) hierarchy of document types. * In addition it should be as resilient to doctype content changes * and inheritance hierarchy changes as possible. * All of this is enforced for names, so id's should follow names. * Therefore we hash on name. */ protected int calculateIdV7(DocumentType owner) { String combined = getName() + dataType.getId(); int newId = BobHash.hash(combined); // Using a portfriendly hash if (newId < 0) newId = -newId; // Highest bit is reserved to tell 7-bit id's from 31-bit ones validateId(newId, owner, Document.SERIALIZED_VERSION); return newId; }
@Override public int hashCode() { return getId(); }
@Override public boolean equals(Object other) { if ( ! (other instanceof SDField)) return false; return super.equals(other); }
@Override public boolean contains(FieldSet o) { if (o instanceof BodyFields || o instanceof DocIdOnly || o instanceof NoFields) { return true; } if (o instanceof Field) { return !((Field) o).isHeader(); } if (o instanceof FieldCollection) { FieldCollection c = (FieldCollection)o; for (Field f : c) { if (f.isHeader()) { return false; } } return true; } else { return false; } }