use of com.yahoo.document.Field in project vespa by vespa-engine.
the class SDDocumentType method createSDDocumentType.
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;
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class SDDocumentType method getField.
/**
* Override getField, as it may need to ask inherited types that isn't registered in document type.
* @param name Name of field to get.
* @return The field found.
*/
public Field getField(String name) {
if (name.contains(".")) {
String superFieldName = name.substring(0, name.indexOf("."));
String subFieldName = name.substring(name.indexOf(".") + 1);
Field f = docType.getField(superFieldName);
if (f != null) {
if (f instanceof SDField) {
SDField superField = (SDField) f;
return superField.getStructField(subFieldName);
} else {
throw new IllegalArgumentException("Field " + f.getName() + " is not SDField");
}
}
}
Field f = docType.getField(name);
if (f == null) {
for (SDDocumentType parent : inheritedTypes.values()) {
f = parent.getField(name);
if (f != null)
return f;
}
}
return f;
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class TypedTransformProvider method requiresTransform.
@Override
protected final boolean requiresTransform(Expression exp) {
if (exp instanceof OutputExpression) {
String fieldName = ((OutputExpression) exp).getFieldName();
if (exp instanceof AttributeExpression) {
Attribute attribute = search.getAttribute(fieldName);
if (attribute == null)
throw new IllegalArgumentException("Attribute '" + fieldName + "' not found.");
fieldType = attribute.getDataType();
} else if (exp instanceof IndexExpression) {
Field field = search.getConcreteField(fieldName);
if (field == null)
throw new IllegalArgumentException("Index field '" + fieldName + "' not found.");
fieldType = field.getDataType();
} else if (exp instanceof SummaryExpression) {
Field field = search.getSummaryField(fieldName);
if (field == null)
throw new IllegalArgumentException("Summary field '" + fieldName + "' not found.");
fieldType = field.getDataType();
} else {
throw new UnsupportedOperationException();
}
}
return requiresTransform(exp, fieldType);
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class AddExtraFieldsToDocument method addSummaryField.
private void addSummaryField(Search search, SDDocumentType document, SummaryField field, boolean validate) {
Field docField = document.getField(field.getName());
if (docField == null) {
ImmutableSDField existingField = search.getField(field.getName());
if (existingField == null) {
SDField newField = new SDField(document, field.getName(), field.getDataType(), field.isHeader(), true);
newField.setIsExtraField(true);
document.addField(newField);
} else if (!existingField.isImportedField()) {
document.addField(existingField.asField());
}
} else if (!docField.getDataType().equals(field.getDataType())) {
if (validate)
throw newProcessException(search, field, "Summary field has conflicting type.");
}
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class IndexSchemaTestCase method requireThatArrayOfStructIsFlattened.
@Test
public void requireThatArrayOfStructIsFlattened() {
StructDataType type = new StructDataType("my_struct");
type.addField(new Field("my_byte", DataType.BYTE));
type.addField(new Field("my_double", DataType.DOUBLE));
type.addField(new Field("my_float", DataType.FLOAT));
type.addField(new Field("my_int", DataType.INT));
type.addField(new Field("my_long", DataType.LONG));
type.addField(new Field("my_raw", DataType.RAW));
type.addField(new Field("my_string", DataType.STRING));
type.addField(new Field("my_uri", DataType.URI));
assertFlat(new Field("foo", DataType.getArray(type)), new Field("foo.my_byte", DataType.getArray(DataType.BYTE)), new Field("foo.my_double", DataType.getArray(DataType.DOUBLE)), new Field("foo.my_float", DataType.getArray(DataType.FLOAT)), new Field("foo.my_int", DataType.getArray(DataType.INT)), new Field("foo.my_long", DataType.getArray(DataType.LONG)), new Field("foo.my_raw", DataType.getArray(DataType.RAW)), new Field("foo.my_string", DataType.getArray(DataType.STRING)), new Field("foo.my_uri", DataType.getArray(DataType.URI)));
}
Aggregations