private FieldPathEntry(Field fieldRef) { type = Type.STRUCT_FIELD; lookupIndex = 0; lookupKey = null; variableName = null; this.fieldRef = fieldRef; resultingDataType = fieldRef.getDataType(); }
public StructFieldChange(Field currentField, Field nextField) { super(currentField, nextField); this.currentType = (StructDataType)currentField.getDataType(); this.nextType = (StructDataType)nextField.getDataType(); }
private static void expectFieldIsOfTypeTensor(Field field) { if (!(field.getDataType() instanceof TensorDataType)) { throw new IllegalArgumentException("A modify update can only be applied to tensor fields. " + "Field '" + field.getName() + "' is of type '" + field.getDataType().getName() + "'"); } }
/** * Adds a value update to the list of value updates. * * @param valueUpdate the ValueUpdate to add * @return a reference to itself * @throws IllegalArgumentException if the data type of the value update is not equal to the data type of this field */ public FieldUpdate addValueUpdate(ValueUpdate valueUpdate) { valueUpdate.checkCompatibility(field.getDataType()); //will throw exception valueUpdates.add(valueUpdate); return this; }
private Map<String, DocumentReference> createFieldToDocumentReferenceMapping(SDDocumentType documentType) { return fieldStream(documentType) .filter(field -> field.getDataType() instanceof ReferenceDataType) .collect(toMap(Field::getName, this::createDocumentReference)); }
public String nextTypeName() { return nextField.getDataType().getName(); } }
@Override protected void register(DocumentTypeManager manager, List<DataType> seenTypes) { seenTypes.add(this); for (Field field : getFields()) { if (!seenTypes.contains(field.getDataType())) { //we haven't seen this one before, register it: field.getDataType().register(manager, seenTypes); } } super.register(manager, seenTypes); }
private static void expectTensorTypeIsNotMixed(Field field) { TensorType tensorType = ((TensorDataType)field.getDataType()).getTensorType(); long numMappedDimensions = tensorType.dimensions().stream().filter(dim -> dim.type().equals(TensorType.Dimension.Type.mapped)).count(); long numIndexedDimensions = tensorType.dimensions().stream().filter(dim -> dim.isIndexed()).count(); if (numMappedDimensions > 0 && numIndexedDimensions > 0) { throw new IllegalArgumentException("A modify update cannot be applied to tensor types with mixed dimensions. " + "Field '" + field.getName() + "' has mixed tensor type '" + tensorType + "'"); } }
private static void expectTensorTypeHasNoneIndexedUnboundDimensions(Field field) { TensorType tensorType = ((TensorDataType)field.getDataType()).getTensorType(); if (tensorType.dimensions().stream() .anyMatch(dim -> dim.type().equals(TensorType.Dimension.Type.indexedUnbound))) { throw new IllegalArgumentException("A modify update cannot be applied to tensor types with indexed unbound dimensions. " + "Field '" + field.getName() + "' has unsupported tensor type '" + tensorType + "'"); } }
private static void extractDataTypesFromFields(NewDocumentType dt, Collection<Field> fields) { for (Field f : fields) { DataType type = f.getDataType(); if (testAddType(dt, type)) { extractNestedTypes(dt, type); addType(dt, type); } } } private static void extractNestedTypes(NewDocumentType dt, DataType type) {
@SuppressWarnings("rawtypes") public static ValueUpdate createMapUpdate(TokenBuffer buffer, Field field) { buffer.next(); MapValueUpdate m = (MapValueUpdate) MapReader.createMapUpdate(buffer, field.getDataType(), null, null); buffer.next(); // must generate the field value in parallell with the actual return m; }
@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 }
public static void applyUpdate(Field field, ValueUpdate update, Document doc) { doc.setFieldValue(field, createFieldValue(field.getDataType().createFieldValue(), update)); }
private void disallowIndexingOfMaps(AbstractSearchCluster cluster, SearchDefinition def, Field field) { DataType fieldType = field.getDataType(); if ((fieldType instanceof MapDataType) && (((SDField) field).doesIndexing())) { throw new IllegalArgumentException("Field type '" + fieldType.getName() + "' cannot be indexed for search " + "clusters (field '" + field.getName() + "' in definition '" + def.getName() + "' for cluster '" + cluster.getClusterName() + "')."); } } }
private void deriveIndexFields(Field field, Search search) { IndexField toAdd = new IndexField(field.getName(), Index.convertType(field.getDataType()), field.getDataType()); com.yahoo.searchdefinition.Index definedIndex = search.getIndex(field.getName()); if (definedIndex != null) { toAdd.setIndexSettings(definedIndex); } fields.add(toAdd); addFieldToCollection(field.getName(), field.getName()); // implicit }
@Override public void tryOutputType(Expression exp, String fieldName, DataType valueType) { Field field = output.getDataType().getField(fieldName); if (field == null) { throw new VerificationException(exp, "Field '" + fieldName + "' not found."); } DataType fieldType = field.getDataType(); if (!fieldType.isAssignableFrom(valueType)) { throw new VerificationException(exp, "Can not assign " + valueType.getName() + " to field '" + fieldName + "' which is " + fieldType.getName() + "."); } }
@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()); } }
@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()); } }
private static SDDocumentType createSDDocumentType(StructDataType structType) { SDDocumentType docType = new SDDocumentType(structType.getName()); for (Field field : structType.getFields()) { docType.addField(new SDField(docType, field.getName(), field.getDataType())); } docType.setStruct(structType); return docType; }
@Override protected void doVerify(VerificationContext context) { DataType input = context.getValue(); if (!(input instanceof StructuredDataType)) { throw new VerificationException(this, "Expected structured input, got " + input.getName() + "."); } Field field = ((StructuredDataType)input).getField(fieldName); if (field == null) { throw new VerificationException(this, "Field '" + fieldName + "' not found in struct type '" + input.getName() + "'"); } context.setValue(field.getDataType()); }