Search in sources :

Example 66 with Field

use of com.yahoo.document.Field in project vespa by vespa-engine.

the class VespaXmlUpdateReaderTestCase method requireThatMapKeyDeserializeExceptionIncludesFieldName.

@Test
public void requireThatMapKeyDeserializeExceptionIncludesFieldName() throws Exception {
    Field field = new Field("my_field", DataType.getMap(DataType.BYTE, DataType.STRING));
    assertThrows(field, "<assign field='my_field'><item><key>-129</key><value>foo</value></item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 87)");
    assertThrows(field, "<assign fieldpath='my_field'><item><key>-129</key><value>foo</value></item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 91)");
    assertThrows(field, "<add field='my_field'><item><key>-129</key><value>foo</value></item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 84)");
    assertThrows(field, "<add fieldpath='my_field'><item><key>-129</key><value>foo</value></item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 88)");
    assertThrows(field, "<remove field='my_field'><item><key>-129</key><value>foo</value></item></remove>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 87)");
    try {
        readUpdate(field, "<remove fieldpath='my_field{-129}' />");
        fail();
    } catch (NumberFormatException e) {
    }
}
Also used : Field(com.yahoo.document.Field) Test(org.junit.Test)

Example 67 with Field

use of com.yahoo.document.Field in project vespa by vespa-engine.

the class VespaXmlUpdateReaderTestCase method requireThatMapValueDeserializeExceptionIncludesFieldName.

@Test
public void requireThatMapValueDeserializeExceptionIncludesFieldName() throws Exception {
    Field field = new Field("my_field", DataType.getMap(DataType.STRING, DataType.BYTE));
    assertThrows(field, "<assign field='my_field'><item><key>foo</key><value>-129</value></item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 105)");
    assertThrows(field, "<assign fieldpath='my_field'><item><key>foo</key><value>-129</value></item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 109)");
    assertThrows(field, "<add field='my_field'><item><key>foo</key><value>-129</value></item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 102)");
    assertThrows(field, "<add fieldpath='my_field'><item><key>foo</key><value>-129</value></item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 106)");
    assertThrows(field, "<remove field='my_field'><item><key>foo</key><value>-129</value></item></remove>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 105)");
}
Also used : Field(com.yahoo.document.Field) Test(org.junit.Test)

Example 68 with Field

use of com.yahoo.document.Field in project vespa by vespa-engine.

the class VespaXmlUpdateReaderTestCase method requireThatFieldPathWhereClauseIsValidated.

@Test
@Ignore
public void requireThatFieldPathWhereClauseIsValidated() throws Exception {
    // tracked in ticket 6675091
    // problem caused by VespaXMLUpdateReader#read(FieldPathUpdate) not validating where clause
    assertThrows(new Field("my_field", DataType.getArray(DataType.BYTE)), "<remove fieldpath='my_field[$x]' where='my_field[$x] == -129' />", "Field 'my_field': Invalid byte \"-129\". (at line 1, column X)");
    assertThrows(new Field("my_field", DataType.getMap(DataType.STRING, DataType.BYTE)), "<remove fieldpath='my_field{$x}' where='my_field{$x} == -129' />", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 109)");
}
Also used : Field(com.yahoo.document.Field) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 69 with Field

use of com.yahoo.document.Field in project vespa by vespa-engine.

the class VespaXmlUpdateReaderTestCase method requireThatArrayItemDeserializeExceptionIncludesFieldName.

@Test
public void requireThatArrayItemDeserializeExceptionIncludesFieldName() throws Exception {
    Field field = new Field("my_field", DataType.getArray(DataType.BYTE));
    assertThrows(field, "<assign field='my_field'><item>-129</item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 83)");
    assertThrows(field, "<assign fieldpath='my_field'><item>-129</item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 87)");
    assertThrows(field, "<add field='my_field'><item>-129</item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 80)");
    assertThrows(field, "<add fieldpath='my_field'><item>-129</item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 84)");
    assertThrows(field, "<remove field='my_field'><item>-129</item></remove>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 83)");
}
Also used : Field(com.yahoo.document.Field) Test(org.junit.Test)

Example 70 with Field

use of com.yahoo.document.Field in project vespa by vespa-engine.

the class JsonWriterTestCase method testWritingOfTensorFieldValueWithoutTensor.

@Test
public void testWritingOfTensorFieldValueWithoutTensor() throws IOException {
    DocumentType documentTypeWithTensor = types.getDocumentType("testtensor");
    String docId = "id:unittest:testtensor::0";
    Document doc = new Document(documentTypeWithTensor, docId);
    Field tensorField = documentTypeWithTensor.getField("tensorfield");
    doc.setFieldValue(tensorField, new TensorFieldValue(((TensorDataType) tensorField.getDataType()).getTensorType()));
    assertEqualJson(asDocument(docId, "{ \"tensorfield\": {} }"), JsonWriter.toByteArray(doc));
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Field(com.yahoo.document.Field) TensorDataType(com.yahoo.document.TensorDataType) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

Field (com.yahoo.document.Field)115 Test (org.junit.Test)50 StructDataType (com.yahoo.document.StructDataType)46 DocumentType (com.yahoo.document.DocumentType)24 DataType (com.yahoo.document.DataType)17 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 ArrayDataType (com.yahoo.document.ArrayDataType)12 MapDataType (com.yahoo.document.MapDataType)12 TensorDataType (com.yahoo.document.TensorDataType)11 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)11 SDField (com.yahoo.searchdefinition.document.SDField)10 PositionDataType (com.yahoo.document.PositionDataType)9 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)9 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Struct (com.yahoo.document.datatypes.Struct)7 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)6 Document (com.yahoo.document.Document)5