use of com.yahoo.document.datatypes.LongFieldValue in project vespa by vespa-engine.
the class DocumentCalculatorTestCase method setUp.
public void setUp() {
docMan = new DocumentTypeManager();
testDocType = new DocumentType("testdoc");
testDocType.addHeaderField("byteattr", DataType.BYTE);
testDocType.addHeaderField("intattr", DataType.INT);
testDocType.addHeaderField("longattr", DataType.LONG);
testDocType.addHeaderField("doubleattr", DataType.DOUBLE);
testDocType.addHeaderField("missingattr", DataType.INT);
docMan.registerDocumentType(testDocType);
doc = new Document(testDocType, new DocumentId("doc:testdoc:http://www.ntnu.no/"));
doc.setFieldValue(testDocType.getField("byteattr"), new ByteFieldValue((byte) 32));
doc.setFieldValue(testDocType.getField("intattr"), new IntegerFieldValue(468));
doc.setFieldValue(testDocType.getField("longattr"), new LongFieldValue((long) 327));
doc.setFieldValue(testDocType.getField("doubleattr"), new DoubleFieldValue(25.0));
}
use of com.yahoo.document.datatypes.LongFieldValue in project vespa by vespa-engine.
the class DocumentSerializationTestCase method testSerializationAllVersions.
@Test
public void testSerializationAllVersions() throws IOException {
DocumentType docInDocType = new DocumentType("docindoc");
docInDocType.addField(new Field("stringindocfield", DataType.STRING, false));
DocumentType docType = new DocumentType("serializetest");
docType.addField(new Field("floatfield", DataType.FLOAT, true));
docType.addField(new Field("stringfield", DataType.STRING, true));
docType.addField(new Field("longfield", DataType.LONG, true));
docType.addField(new Field("urifield", DataType.URI, true));
docType.addField(new Field("intfield", DataType.INT, false));
docType.addField(new Field("rawfield", DataType.RAW, false));
docType.addField(new Field("doublefield", DataType.DOUBLE, false));
docType.addField(new Field("bytefield", DataType.BYTE, false));
DataType arrayOfFloatDataType = new ArrayDataType(DataType.FLOAT);
docType.addField(new Field("arrayoffloatfield", arrayOfFloatDataType, false));
DataType arrayOfArrayOfFloatDataType = new ArrayDataType(arrayOfFloatDataType);
docType.addField(new Field("arrayofarrayoffloatfield", arrayOfArrayOfFloatDataType, false));
docType.addField(new Field("docfield", DataType.DOCUMENT, false));
DataType weightedSetDataType = DataType.getWeightedSet(DataType.STRING, false, false);
docType.addField(new Field("wsfield", weightedSetDataType, false));
DocumentTypeManager docMan = new DocumentTypeManager();
docMan.register(docInDocType);
docMan.register(docType);
String path = "src/test/serializeddocuments/";
{
Document doc = new Document(docType, "doc:serializetest:http://test.doc.id/");
doc.setFieldValue("intfield", 5);
doc.setFieldValue("floatfield", -9.23);
doc.setFieldValue("stringfield", "This is a string.");
doc.setFieldValue("longfield", new LongFieldValue(398420092938472983l));
doc.setFieldValue("doublefield", new DoubleFieldValue(98374532.398820));
doc.setFieldValue("bytefield", new ByteFieldValue(254));
byte[] rawData = "RAW DATA".getBytes();
assertEquals(8, rawData.length);
doc.setFieldValue(docType.getField("rawfield"), new Raw(ByteBuffer.wrap("RAW DATA".getBytes())));
Document docInDoc = new Document(docInDocType, "doc:serializetest:http://doc.in.doc/");
docInDoc.setFieldValue("stringindocfield", "Elvis is dead");
doc.setFieldValue(docType.getField("docfield"), docInDoc);
Array<FloatFieldValue> floatArray = new Array<>(arrayOfFloatDataType);
floatArray.add(new FloatFieldValue(1.0f));
floatArray.add(new FloatFieldValue(2.0f));
doc.setFieldValue("arrayoffloatfield", floatArray);
WeightedSet<StringFieldValue> weightedSet = new WeightedSet<>(weightedSetDataType);
weightedSet.put(new StringFieldValue("Weighted 0"), 50);
weightedSet.put(new StringFieldValue("Weighted 1"), 199);
doc.setFieldValue("wsfield", weightedSet);
CompressionConfig noncomp = new CompressionConfig();
CompressionConfig lz4comp = new CompressionConfig(CompressionType.LZ4);
{
doc.getDataType().getHeaderType().setCompressionConfig(noncomp);
doc.getDataType().getBodyType().setCompressionConfig(noncomp);
FileOutputStream fout = new FileOutputStream(path + "document-java-currentversion-uncompressed.dat", false);
doc.serialize(fout);
fout.close();
}
{
doc.getDataType().getHeaderType().setCompressionConfig(lz4comp);
doc.getDataType().getBodyType().setCompressionConfig(lz4comp);
FileOutputStream fout = new FileOutputStream(path + "document-java-currentversion-lz4-9.dat", false);
doc.serialize(fout);
doc.getDataType().getHeaderType().setCompressionConfig(noncomp);
doc.getDataType().getBodyType().setCompressionConfig(noncomp);
fout.close();
}
}
class TestDoc {
String testFile;
int version;
TestDoc(String testFile, int version) {
this.testFile = testFile;
this.version = version;
}
}
String cpppath = "src/tests/data/";
List<TestDoc> tests = new ArrayList<>();
tests.add(new TestDoc(path + "document-java-currentversion-uncompressed.dat", Document.SERIALIZED_VERSION));
tests.add(new TestDoc(path + "document-java-currentversion-lz4-9.dat", Document.SERIALIZED_VERSION));
tests.add(new TestDoc(path + "document-java-v8-uncompressed.dat", 8));
tests.add(new TestDoc(cpppath + "document-cpp-currentversion-uncompressed.dat", 7));
tests.add(new TestDoc(cpppath + "document-cpp-currentversion-lz4-9.dat", 7));
tests.add(new TestDoc(cpppath + "document-cpp-v8-uncompressed.dat", 7));
tests.add(new TestDoc(cpppath + "document-cpp-v7-uncompressed.dat", 7));
tests.add(new TestDoc(cpppath + "serializev6.dat", 6));
for (TestDoc test : tests) {
File f = new File(test.testFile);
FileInputStream fin = new FileInputStream(f);
byte[] buffer = new byte[(int) f.length()];
int pos = 0;
int remaining = buffer.length;
while (remaining > 0) {
int read = fin.read(buffer, pos, remaining);
assertFalse(read == -1);
pos += read;
remaining -= read;
}
System.err.println("Checking doc from file " + test.testFile);
Document doc = new Document(DocumentDeserializerFactory.create42(docMan, GrowableByteBuffer.wrap(buffer)));
System.err.println("Id: " + doc.getId());
assertEquals(new IntegerFieldValue(5), doc.getFieldValue("intfield"));
assertEquals(-9.23, ((FloatFieldValue) doc.getFieldValue("floatfield")).getFloat(), 1E-6);
assertEquals(new StringFieldValue("This is a string."), doc.getFieldValue("stringfield"));
assertEquals(new LongFieldValue(398420092938472983l), doc.getFieldValue("longfield"));
assertEquals(98374532.398820, ((DoubleFieldValue) doc.getFieldValue("doublefield")).getDouble(), 1E-6);
assertEquals(new ByteFieldValue((byte) 254), doc.getFieldValue("bytefield"));
ByteBuffer bbuffer = ((Raw) doc.getFieldValue("rawfield")).getByteBuffer();
if (!Arrays.equals("RAW DATA".getBytes(), bbuffer.array())) {
System.err.println("Expected 'RAW DATA' but got '" + new String(bbuffer.array()) + "'.");
assertTrue(false);
}
if (test.version > 6) {
Document docInDoc = (Document) doc.getFieldValue("docfield");
assertTrue(docInDoc != null);
assertEquals(new StringFieldValue("Elvis is dead"), docInDoc.getFieldValue("stringindocfield"));
}
Array array = (Array) doc.getFieldValue("arrayoffloatfield");
assertTrue(array != null);
assertEquals(1.0f, ((FloatFieldValue) array.get(0)).getFloat(), 1E-6);
assertEquals(2.0f, ((FloatFieldValue) array.get(1)).getFloat(), 1E-6);
WeightedSet wset = (WeightedSet) doc.getFieldValue("wsfield");
assertTrue(wset != null);
assertEquals(Integer.valueOf(50), wset.get(new StringFieldValue("Weighted 0")));
assertEquals(Integer.valueOf(199), wset.get(new StringFieldValue("Weighted 1")));
}
}
use of com.yahoo.document.datatypes.LongFieldValue in project vespa by vespa-engine.
the class HexDecodeExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
String input = String.valueOf(ctx.getValue());
if (input.isEmpty()) {
ctx.setValue(new LongFieldValue(Long.MIN_VALUE));
return;
}
BigInteger output;
try {
output = new BigInteger(input, 16);
} catch (NumberFormatException e) {
throw new NumberFormatException("Illegal hex value '" + input + "'.");
}
if (output.bitLength() > 64) {
throw new NumberFormatException("Hex value '" + input + "' is out of range.");
}
if (output.compareTo(BigInteger.ZERO) == 1 && output.bitLength() == 64) {
// flip to negative
output = output.subtract(ULONG_MAX);
}
ctx.setValue(new LongFieldValue(output.longValue()));
}
use of com.yahoo.document.datatypes.LongFieldValue in project vespa by vespa-engine.
the class OptimizePredicateTestCase method requireThatPredicateOptionsAreSet.
@Test
public void requireThatPredicateOptionsAreSet() {
final Predicate predicate = Mockito.mock(Predicate.class);
final PredicateFieldValue input = new PredicateFieldValue(predicate);
ExecutionContext ctx = new ExecutionContext().setValue(input).setVariable("arity", new IntegerFieldValue(10));
new OptimizePredicateExpression((predicate1, options) -> {
assertEquals(10, options.getArity());
assertEquals(0x8000000000000000L, options.getLowerBound());
assertEquals(0x7fffffffffffffffL, options.getUpperBound());
return predicate1;
}).execute(ctx);
ctx.setVariable("upper_bound", new LongFieldValue(1000));
ctx.setVariable("lower_bound", new LongFieldValue(0));
new OptimizePredicateExpression((value, options) -> {
assertEquals(10, options.getArity());
assertEquals(0, options.getLowerBound());
assertEquals(1000, options.getUpperBound());
return value;
}).execute(ctx);
}
use of com.yahoo.document.datatypes.LongFieldValue in project vespa by vespa-engine.
the class GuardTestCase method requireThatConstFieldsAreIncludedByDocument.
@Test
public void requireThatConstFieldsAreIncludedByDocument() throws ParseException {
DocumentType docType = new DocumentType("my_input");
docType.addField(new Field("my_lng", DataType.LONG));
docType.addField(new Field("my_str", DataType.STRING));
Document doc = new Document(docType, "doc:scheme:");
doc.setFieldValue("my_str", new StringFieldValue("foo"));
assertNotNull(doc = Expression.execute(Expression.fromString("guard { now | attribute my_lng }"), doc));
assertTrue(doc.getFieldValue("my_lng") instanceof LongFieldValue);
}
Aggregations