use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class JsonReaderTestCase method setUp.
@Before
public void setUp() throws Exception {
parserFactory = new JsonFactory();
types = new DocumentTypeManager();
{
DocumentType x = new DocumentType("smoke");
x.addField(new Field("something", DataType.STRING));
x.addField(new Field("nalle", DataType.STRING));
x.addField(new Field("int1", DataType.INT));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("mirrors");
StructDataType woo = new StructDataType("woo");
woo.addField(new Field("sandra", DataType.STRING));
woo.addField(new Field("cloud", DataType.STRING));
x.addField(new Field("skuggsjaa", woo));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testarray");
DataType d = new ArrayDataType(DataType.STRING);
x.addField(new Field("actualarray", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testset");
DataType d = new WeightedSetDataType(DataType.STRING, true, true);
x.addField(new Field("actualset", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testmap");
DataType d = new MapDataType(DataType.STRING, DataType.STRING);
x.addField(new Field("actualmap", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testraw");
DataType d = DataType.RAW;
x.addField(new Field("actualraw", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testMapStringToArrayOfInt");
DataType value = new ArrayDataType(DataType.INT);
DataType d = new MapDataType(DataType.STRING, value);
x.addField(new Field("actualMapStringToArrayOfInt", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testsinglepos");
DataType d = PositionDataType.INSTANCE;
x.addField(new Field("singlepos", d));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testtensor");
x.addField(new Field("mappedtensorfield", new TensorDataType(new TensorType.Builder().mapped("x").mapped("y").build())));
x.addField(new Field("indexedtensorfield", new TensorDataType(new TensorType.Builder().indexed("x").indexed("y").build())));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testpredicate");
x.addField(new Field("boolean", DataType.PREDICATE));
types.registerDocumentType(x);
}
{
DocumentType x = new DocumentType("testint");
x.addField(new Field("integerfield", DataType.INT));
types.registerDocumentType(x);
}
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class JsonWriterTestCase method registerMapToStringToArrayDocumentType.
private void registerMapToStringToArrayDocumentType() {
DocumentType x = new DocumentType("testMapStringToArrayOfInt");
DataType value = new ArrayDataType(DataType.INT);
DataType d = new MapDataType(DataType.STRING, value);
x.addField(new Field("actualMapStringToArrayOfInt", d));
types.registerDocumentType(x);
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class JsonWriterTestCase method registerMultiPositionDocumentType.
private void registerMultiPositionDocumentType() {
DocumentType x = new DocumentType("testmultipos");
DataType d = new ArrayDataType(PositionDataType.INSTANCE);
x.addField(new Field("multipos", d));
types.registerDocumentType(x);
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class ToArrayTestCase method requireThatValueIsConverted.
@Test
public void requireThatValueIsConverted() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(new StringFieldValue("69")).execute(new ToArrayExpression());
FieldValue val = ctx.getValue();
assertEquals(Array.class, val.getClass());
Array arr = (Array) val;
ArrayDataType type = arr.getDataType();
assertEquals(DataType.STRING, type.getNestedType());
assertEquals(1, arr.size());
assertEquals(new StringFieldValue("69"), arr.get(0));
}
use of com.yahoo.document.ArrayDataType in project vespa by vespa-engine.
the class MapValueUpdate method checkCompatibility.
@Override
protected void checkCompatibility(DataType fieldType) {
if (fieldType instanceof ArrayDataType) {
if (!(value instanceof IntegerFieldValue)) {
throw new IllegalArgumentException("Expected integer, got " + value.getClass().getName() + ".");
}
update.checkCompatibility(((ArrayDataType) fieldType).getNestedType());
} else if (fieldType instanceof WeightedSetDataType) {
((WeightedSetDataType) fieldType).getNestedType().createFieldValue().assign(value);
update.checkCompatibility(DataType.INT);
} else if (fieldType instanceof StructuredDataType) {
if (!(value instanceof StringFieldValue)) {
throw new IllegalArgumentException("Expected string, got " + value.getClass().getName() + ".");
}
Field field = ((StructuredDataType) fieldType).getField(((StringFieldValue) value).getString());
if (field == null) {
throw new IllegalArgumentException("Field '" + value + "' not found.");
}
update.checkCompatibility(field.getDataType());
} else {
throw new UnsupportedOperationException("Field type " + fieldType.getName() + " not supported.");
}
}
Aggregations